mirror of https://github.com/docker/docs.git
allow vpc-id, zone and subnet-id options for ec2
Signed-off-by: Evan Hazlett <ejhazlett@gmail.com>
This commit is contained in:
parent
3d1582c69f
commit
e49e368cc3
|
@ -44,6 +44,7 @@ type Driver struct {
|
||||||
ReservationId string
|
ReservationId string
|
||||||
RootSize int64
|
RootSize int64
|
||||||
VpcId string
|
VpcId string
|
||||||
|
SubnetId string
|
||||||
Zone string
|
Zone string
|
||||||
storePath string
|
storePath string
|
||||||
keyPath string
|
keyPath string
|
||||||
|
@ -100,6 +101,11 @@ func GetCreateFlags() []cli.Flag {
|
||||||
Value: "a",
|
Value: "a",
|
||||||
EnvVar: "AMAZONEC2_ZONE",
|
EnvVar: "AMAZONEC2_ZONE",
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "amazonec2-subnet-id",
|
||||||
|
Usage: "AWS VPC subnet id",
|
||||||
|
Value: "",
|
||||||
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "amazonec2-instance-type",
|
Name: "amazonec2-instance-type",
|
||||||
Usage: "AWS instance type",
|
Usage: "AWS instance type",
|
||||||
|
@ -125,6 +131,7 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
|
||||||
d.Region = flags.String("amazonec2-region")
|
d.Region = flags.String("amazonec2-region")
|
||||||
d.InstanceType = flags.String("amazonec2-instance-type")
|
d.InstanceType = flags.String("amazonec2-instance-type")
|
||||||
d.VpcId = flags.String("amazonec2-vpc-id")
|
d.VpcId = flags.String("amazonec2-vpc-id")
|
||||||
|
d.SubnetId = flags.String("amazonec2-subnet-id")
|
||||||
zone := flags.String("amazonec2-zone")
|
zone := flags.String("amazonec2-zone")
|
||||||
d.Zone = zone[:]
|
d.Zone = zone[:]
|
||||||
d.RootSize = int64(flags.Int("amazonec2-root-size"))
|
d.RootSize = int64(flags.Int("amazonec2-root-size"))
|
||||||
|
@ -137,12 +144,8 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
|
||||||
return fmt.Errorf("amazonec2 driver requires the --amazonec2-secret-key option")
|
return fmt.Errorf("amazonec2 driver requires the --amazonec2-secret-key option")
|
||||||
}
|
}
|
||||||
|
|
||||||
if d.VpcId == "" {
|
if d.SubnetId == "" && d.VpcId == "" {
|
||||||
return fmt.Errorf("amazonec2 driver requires the --amazonec2-vpc-id option")
|
return fmt.Errorf("amazonec2 driver requires either the --amazonec2-subnet-id or --amazonec2-vpc-id option")
|
||||||
}
|
|
||||||
|
|
||||||
if d.Zone == "" {
|
|
||||||
return fmt.Errorf("amazonec2 driver requires the --amazonec2-zone option")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -172,25 +175,29 @@ func (d *Driver) Create() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the subnet id
|
// get the subnet id
|
||||||
subnets, err := d.getClient().GetSubnets()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
subnetId := ""
|
|
||||||
regionZone := d.Region + d.Zone
|
regionZone := d.Region + d.Zone
|
||||||
for _, s := range subnets {
|
subnetId := d.SubnetId
|
||||||
if s.AvailabilityZone == regionZone {
|
|
||||||
subnetId = s.SubnetId
|
if d.SubnetId == "" {
|
||||||
break
|
subnets, err := d.getClient().GetSubnets()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, s := range subnets {
|
||||||
|
if s.AvailabilityZone == regionZone {
|
||||||
|
subnetId = s.SubnetId
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if subnetId == "" {
|
if subnetId == "" {
|
||||||
return fmt.Errorf("unable to find a subnet in the zone: %s", regionZone)
|
return fmt.Errorf("unable to find a subnet in the zone: %s", regionZone)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("launching instance in %s", regionZone)
|
log.Debugf("launching instance in subnet %s", subnetId)
|
||||||
instance, err := d.getClient().RunInstance(d.AMI, d.InstanceType, d.Zone, 1, 1, group.GroupId, d.KeyName, subnetId, bdm)
|
instance, err := d.getClient().RunInstance(d.AMI, d.InstanceType, d.Zone, 1, 1, group.GroupId, d.KeyName, subnetId, bdm)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue