Left: | ||
Right: |
OLD | NEW |
---|---|
1 // Copyright 2011, 2012, 2013 Canonical Ltd. | 1 // Copyright 2011, 2012, 2013 Canonical Ltd. |
2 // Licensed under the AGPLv3, see LICENCE file for details. | 2 // Licensed under the AGPLv3, see LICENCE file for details. |
3 | 3 |
4 package environs | 4 package environs |
5 | 5 |
6 import ( | 6 import ( |
7 "fmt" | 7 "fmt" |
8 "io/ioutil" | |
8 "launchpad.net/juju-core/environs/config" | 9 "launchpad.net/juju-core/environs/config" |
10 "launchpad.net/juju-core/errors" | |
9 ) | 11 ) |
10 | 12 |
11 // Open creates a new Environ using the environment configuration with the | 13 // Open creates a new Environ using the environment configuration with the |
12 // given name. If name is empty, the default environment will be used. | 14 // given name. If name is empty, the default environment will be used. |
13 func (envs *Environs) Open(name string) (Environ, error) { | 15 func (envs *Environs) Open(name string) (Environ, error) { |
14 if name == "" { | 16 if name == "" { |
15 name = envs.Default | 17 name = envs.Default |
16 if name == "" { | 18 if name == "" { |
17 return nil, fmt.Errorf("no default environment found") | 19 return nil, fmt.Errorf("no default environment found") |
18 } | 20 } |
(...skipping 30 matching lines...) Expand all Loading... | |
49 } | 51 } |
50 | 52 |
51 // New returns a new environment based on the provided configuration. | 53 // New returns a new environment based on the provided configuration. |
52 func New(config *config.Config) (Environ, error) { | 54 func New(config *config.Config) (Environ, error) { |
53 p, err := Provider(config.Type()) | 55 p, err := Provider(config.Type()) |
54 if err != nil { | 56 if err != nil { |
55 return nil, err | 57 return nil, err |
56 } | 58 } |
57 return p.Open(config) | 59 return p.Open(config) |
58 } | 60 } |
61 | |
62 // Checks if an environment has a bootstrap-verify that is written by | |
dimitern
2013/06/28 16:34:08
// CheckEnvironment checks ...
Danilo
2013/06/29 03:03:11
Fixed.
| |
63 // juju-core commands (as compared to one being written by Python juju). | |
64 // | |
65 // If there is no bootstrap-verify file in the storage, it is still | |
66 // considered to be a Juju-core environment since early versions have | |
67 // not written it out. | |
68 // | |
69 // Returns InvalidEnvironmentError on failure, nil otherwise. | |
70 func CheckEnvironment(environ Environ) error { | |
71 storage := environ.Storage() | |
72 reader, err := storage.Get(verificationFilename) | |
73 if errors.IsNotFoundError(err) { | |
74 // When verification file does not exist, this is a juju-core | |
75 // environment. | |
76 return nil | |
77 } else if err == nil { | |
78 content, err := ioutil.ReadAll(reader) | |
79 if err == nil && string(content) == verificationContent { | |
80 // Content matches what juju-core puts in the | |
81 // verificationFilename. | |
82 return nil | |
83 } | |
84 } | |
85 return InvalidEnvironmentError | |
fwereade
2013/06/28 15:51:19
I'd prefer to distinguish between "couldn't read f
Danilo
2013/06/29 03:03:11
Done it mostly like this (though I very much disli
| |
86 } | |
OLD | NEW |