OLD | NEW |
(Empty) | |
| 1 package ec2 |
| 2 |
| 3 import ( |
| 4 "fmt" |
| 5 "launchpad.net/goamz/aws" |
| 6 "launchpad.net/juju/go/juju" |
| 7 "launchpad.net/juju/go/schema" |
| 8 ) |
| 9 |
| 10 func init() { |
| 11 juju.RegisterProvider("ec2", provider{}) |
| 12 } |
| 13 |
| 14 var regions = map[string]aws.Region{ |
| 15 "ap-northeast-1": aws.APNortheast, |
| 16 "ap-southeast-1": aws.APSoutheast, |
| 17 "eu-west-1": aws.EUWest, |
| 18 "us-east-1": aws.USEast, |
| 19 "us-west-1": aws.USWest, |
| 20 } |
| 21 |
| 22 type providerConfig struct { |
| 23 controlBucket string |
| 24 adminSecret string |
| 25 accessKey string |
| 26 secretKey string |
| 27 region aws.Region |
| 28 defaultInstanceType string |
| 29 defaultAMI string |
| 30 ec2URI string |
| 31 s3URI string |
| 32 placement string |
| 33 defaultSeries string |
| 34 } |
| 35 |
| 36 func maybeString(x interface{}) string { |
| 37 if x == nil { |
| 38 return "" |
| 39 } |
| 40 return x.(string) |
| 41 } |
| 42 |
| 43 type provider struct{} |
| 44 |
| 45 func (provider) ConfigChecker() schema.Checker { |
| 46 return combineCheckers( |
| 47 schema.FieldMap( |
| 48 schema.Fields{ |
| 49 "access-key": schema.String(), |
| 50 "admin-secret": schema.String(), |
| 51 "control-bucket": schema.String(), |
| 52 "default-ami": schema.String(), |
| 53 "default-instance-type": schema.String(), |
| 54 "default-series": schema.String(), |
| 55 "ec2-uri": schema.String(), |
| 56 "placement": oneOf("unassigned", "lo
cal"), |
| 57 "region": schema.String(), |
| 58 "s3-uri": schema.String(), |
| 59 "secret-key": schema.String(), |
| 60 }, []string{ |
| 61 "access-key", |
| 62 "default-ami", |
| 63 "default-instance-type", |
| 64 "default-series", |
| 65 "ec2-uri", |
| 66 "placement", |
| 67 "region", |
| 68 "s3-uri", |
| 69 "secret-key", |
| 70 }, |
| 71 ), |
| 72 checkerFunc(func(v interface{}, path []string) (newv interface{}
, err error) { |
| 73 m := v.(schema.MapType) |
| 74 var c providerConfig |
| 75 c.controlBucket = maybeString(m["control-bucket"]) |
| 76 c.adminSecret = maybeString(m["admin-secret"]) |
| 77 c.accessKey = maybeString(m["access-key"]) |
| 78 c.secretKey = maybeString(m["secret-key"]) |
| 79 regionName := maybeString(m["region"]) |
| 80 if regionName == "" { |
| 81 regionName = "us-east-1" |
| 82 } |
| 83 if r, ok := regions[regionName]; ok { |
| 84 c.region = r |
| 85 } else { |
| 86 return nil, fmt.Errorf("invalid region name %q",
regionName) |
| 87 } |
| 88 c.defaultInstanceType = maybeString(m["default-instance-
type"]) |
| 89 if c.defaultInstanceType == "" { |
| 90 c.defaultInstanceType = "m1.small" |
| 91 } |
| 92 c.defaultAMI = maybeString(m["default-ami"]) |
| 93 c.ec2URI = maybeString(m["ec2-uri"]) |
| 94 c.s3URI = maybeString(m["s3-uri"]) |
| 95 c.placement = maybeString(m["placement"]) |
| 96 c.defaultSeries = maybeString(m["default-series"]) |
| 97 // TODO more checking here? |
| 98 return &c, nil |
| 99 }), |
| 100 ) |
| 101 } |
OLD | NEW |