Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1452)

Unified Diff: environs/ec2/ec2.go

Issue 6408049: environs: turn environment configuration into a concrete type
Patch Set: environs: turn environment configuration into a concrete type Created 12 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « environs/ec2/config_test.go ('k') | environs/ec2/export_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: environs/ec2/ec2.go
=== modified file 'environs/ec2/ec2.go'
--- environs/ec2/ec2.go 2012-07-17 23:20:39 +0000
+++ environs/ec2/ec2.go 2012-07-18 02:32:42 +0000
@@ -6,6 +6,7 @@
"launchpad.net/goamz/ec2"
"launchpad.net/goamz/s3"
"launchpad.net/juju-core/environs"
+ "launchpad.net/juju-core/environs/config"
"launchpad.net/juju-core/log"
"launchpad.net/juju-core/state"
"launchpad.net/juju-core/version"
@@ -97,18 +98,24 @@
return "", fmt.Errorf("timed out trying to get DNS address for %v", inst.Id())
}
-func (cfg *providerConfig) Open() (environs.Environ, error) {
- log.Printf("environs/ec2: opening environment %q", cfg.name)
- if aws.Regions[cfg.region].EC2Endpoint == "" {
- return nil, fmt.Errorf("no ec2 endpoint found for region %q, opening %q", cfg.region, cfg.name)
- }
+func (p environProvider) Open(cfg *config.Config) (environs.Environ, error) {
+ log.Printf("environs/ec2: opening environment %q", cfg.Name())
e := new(environ)
- e.SetConfig(cfg)
+ err := e.SetConfig(cfg)
+ if err != nil {
+ return nil, err
+ }
return e, nil
}
-func (e *environ) SetConfig(cfg environs.EnvironConfig) {
- config := cfg.(*providerConfig)
+func (e *environ) SetConfig(cfg *config.Config) error {
+ config, err := newConfig(cfg)
+ if err != nil {
+ return err
+ }
+ if aws.Regions[config.region].EC2Endpoint == "" {
+ return fmt.Errorf("environment %q references unknown EC2 region %q", config.name, config.region)
+ }
e.configMutex.Lock()
defer e.configMutex.Unlock()
// TODO(dfc) bug #1018207, renaming an environment once it is in use should be forbidden
@@ -129,6 +136,7 @@
} else {
e.publicStorageUnlocked = nil
}
+ return nil
}
func (e *environ) config() *providerConfig {
@@ -258,7 +266,7 @@
providerType: "ec2",
toolsURL: toolsURL,
machineId: machineId,
- authorizedKeys: e.config().authorizedKeys,
+ authorizedKeys: e.config().AuthorizedKeys(),
}
cloudcfg, err := newCloudInit(cfg)
if err != nil {
@@ -272,8 +280,8 @@
// instance will be started.
func (e *environ) startInstance(machineId int, info *state.Info, master bool) (environs.Instance, error) {
spec, err := findInstanceSpec(&instanceConstraint{
- series: environs.CurrentSeries,
- arch: environs.CurrentArch,
+ series: config.CurrentSeries,
+ arch: config.CurrentArch,
region: e.config().region,
})
if err != nil {
« no previous file with comments | « environs/ec2/config_test.go ('k') | environs/ec2/export_test.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b