mirror of https://github.com/docker/docs.git
Adds region defaults
Signed-off-by: Simon Thulbourn <simon+github@thulbourn.com>
This commit is contained in:
parent
9178f518e8
commit
8482c7201f
|
@ -21,7 +21,6 @@ import (
|
|||
const (
|
||||
driverName = "amazonec2"
|
||||
defaultRegion = "us-east-1"
|
||||
defaultAMI = "ami-4ae27e22"
|
||||
defaultInstanceType = "t2.micro"
|
||||
defaultRootSize = 16
|
||||
ipRange = "0.0.0.0/0"
|
||||
|
@ -96,7 +95,6 @@ func GetCreateFlags() []cli.Flag {
|
|||
cli.StringFlag{
|
||||
Name: "amazonec2-ami",
|
||||
Usage: "AWS machine image",
|
||||
Value: defaultAMI,
|
||||
EnvVar: "AWS_AMI",
|
||||
},
|
||||
cli.StringFlag{
|
||||
|
@ -150,11 +148,21 @@ func NewDriver(machineName string, storePath string, caCert string, privateKey s
|
|||
}
|
||||
|
||||
func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
|
||||
region, err := validateAwsRegion(flags.String("amazonec2-region"))
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
image := flags.String("amazonec2-ami")
|
||||
if len(image) == 0 {
|
||||
image = regionDetails[region].AmiId
|
||||
}
|
||||
|
||||
d.AccessKey = flags.String("amazonec2-access-key")
|
||||
d.SecretKey = flags.String("amazonec2-secret-key")
|
||||
d.SessionToken = flags.String("amazonec2-session-token")
|
||||
d.AMI = flags.String("amazonec2-ami")
|
||||
d.Region = flags.String("amazonec2-region")
|
||||
d.Region = region
|
||||
d.AMI = image
|
||||
d.InstanceType = flags.String("amazonec2-instance-type")
|
||||
d.VpcId = flags.String("amazonec2-vpc-id")
|
||||
d.SubnetId = flags.String("amazonec2-subnet-id")
|
||||
|
|
|
@ -92,3 +92,36 @@ func TestConfigureSecurityGroupPermissionsDockerAndSsh(t *testing.T) {
|
|||
t.Fatalf("expected 0 permissions; received %d", len(perms))
|
||||
}
|
||||
}
|
||||
|
||||
func TestAwsRegionList(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidateAwsRegionValid(t *testing.T) {
|
||||
regions := []string{"eu-west-1", "eu-central-1"}
|
||||
|
||||
for _, v := range regions {
|
||||
r, err := validateAwsRegion(v)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if v != r {
|
||||
t.Fatal("Wrong region returned")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateAwsRegionInvalid(t *testing.T) {
|
||||
regions := []string{"eu-west-2", "eu-central-2"}
|
||||
|
||||
for _, v := range regions {
|
||||
r, err := validateAwsRegion(v)
|
||||
if err == nil {
|
||||
t.Fatal("No error returned")
|
||||
}
|
||||
|
||||
if v == r {
|
||||
t.Fatal("Wrong region returned")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
package amazonec2
|
||||
|
||||
import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
var (
|
||||
errInvalidRegion = errors.New("invalid region specified")
|
||||
errNoVpcs = errors.New("No VPCs found in region")
|
||||
errMachineFailure = errors.New("Machine failed to start")
|
||||
errNoIP = errors.New("No IP Address associated with the instance")
|
||||
errComplete = errors.New("Complete")
|
||||
)
|
||||
|
||||
type region struct {
|
||||
AmiId string
|
||||
}
|
||||
|
||||
var regionDetails map[string]*region = map[string]*region{
|
||||
"ap-northeast-1": {"ami-44f1e245"},
|
||||
"ap-southeast-1": {"ami-f95875ab"},
|
||||
"ap-southeast-2": {"ami-890b62b3"},
|
||||
"cn-north-1": {"ami-fe7ae8c7"},
|
||||
"eu-west-1": {"ami-823686f5"},
|
||||
"eu-central-1": {"ami-ac1524b1"},
|
||||
"sa-east-1": {"ami-c770c1da"},
|
||||
"us-east-1": {"ami-4ae27e22"},
|
||||
"us-west-1": {"ami-d1180894"},
|
||||
"us-west-2": {"ami-898dd9b9"},
|
||||
"us-gov-west-1": {"ami-cf5630ec"},
|
||||
}
|
||||
|
||||
func awsRegionsList() []string {
|
||||
var list []string
|
||||
|
||||
for k := range regionDetails {
|
||||
list = append(list, k)
|
||||
}
|
||||
|
||||
return list
|
||||
}
|
||||
|
||||
func validateAwsRegion(region string) (string, error) {
|
||||
for _, v := range awsRegionsList() {
|
||||
if v == region {
|
||||
return region, nil
|
||||
}
|
||||
}
|
||||
|
||||
return "", errInvalidRegion
|
||||
}
|
Loading…
Reference in New Issue