LEFT | RIGHT |
1 package environs | 1 package environs |
2 | 2 |
3 import ( | 3 import ( |
4 "errors" | 4 "errors" |
5 "io" | 5 "io" |
6 "launchpad.net/juju/go/schema" | 6 "launchpad.net/juju/go/schema" |
7 "launchpad.net/juju/go/state" | 7 "launchpad.net/juju/go/state" |
8 ) | 8 ) |
9 | 9 |
10 // A EnvironProvider represents a computing and storage provider. | 10 // A EnvironProvider represents a computing and storage provider. |
11 type EnvironProvider interface { | 11 type EnvironProvider interface { |
12 // ConfigChecker is used to check sections of the environments.yaml | 12 // ConfigChecker is used to check sections of the environments.yaml |
13 // file that specify this provider. The value passed to the Checker is | 13 // file that specify this provider. The value passed to the Checker is |
14 // that returned from the yaml parse, of type schema.MapType. | 14 // that returned from the yaml parse, of type schema.MapType. |
15 ConfigChecker() schema.Checker | 15 ConfigChecker() schema.Checker |
16 | 16 |
17 » // NewEnviron creates a new Environ with | 17 » // Open opens an environment with config, which must |
18 » // the given attributes returned by the ConfigChecker. | 18 » // have been processed and validated by the schema |
19 » // The name is that given in environments.yaml. | 19 » // checker returned by ConfigChecker. |
20 » Open(name string, attributes interface{}) (Environ, error) | 20 » Open(name string, config interface{}) (Environ, error) |
21 } | 21 } |
22 | 22 |
23 var ErrNoDNSName = errors.New("DNS name not allocated") | 23 var ErrNoDNSName = errors.New("DNS name not allocated") |
24 | 24 |
25 // Instance represents the provider-specific notion of a machine. | 25 // Instance represents the provider-specific notion of a machine. |
26 type Instance interface { | 26 type Instance interface { |
27 // Id returns a provider-generated identifier for the Instance. | 27 // Id returns a provider-generated identifier for the Instance. |
28 Id() string | 28 Id() string |
29 | 29 |
30 // DNSName returns the DNS name for the instance. | 30 // DNSName returns the DNS name for the instance. |
31 // If the name is not yet allocated, it will return | 31 // If the name is not yet allocated, it will return |
32 // an ErrNoDNSName error. | 32 // an ErrNoDNSName error. |
33 DNSName() (string, error) | 33 DNSName() (string, error) |
34 | 34 |
35 // WaitDNSName returns the DNS name for the instance, | 35 // WaitDNSName returns the DNS name for the instance, |
36 // waiting until it is allocated if necessary. | 36 // waiting until it is allocated if necessary. |
37 WaitDNSName() (string, error) | 37 WaitDNSName() (string, error) |
38 } | 38 } |
39 | 39 |
40 var ErrNoInstances = errors.New("no instances found") | 40 var ErrNoInstances = errors.New("no instances found") |
41 var ErrPartialInstances = errors.New("only some instances were found") | 41 var ErrPartialInstances = errors.New("only some instances were found") |
42 | 42 |
| 43 // NotFoundError records an error when something has not been found. |
43 type NotFoundError struct { | 44 type NotFoundError struct { |
44 » // error gives the underlying error. | 45 » // error is the underlying error. |
45 error | 46 error |
46 } | 47 } |
47 | 48 |
48 // StorageReader gives a way to read data stored within | 49 // A StorageReader can retrieve and list files from a storage provider. |
49 // an environment. When a method is called on a | |
50 // non-existent file, the concrete type of the returned error | |
51 // should be *NotFoundError. | |
52 type StorageReader interface { | 50 type StorageReader interface { |
53 » // Get opens the given storage file | 51 » // Get opens the given storage file and returns a ReadCloser |
54 » // and returns a ReadCloser that can be used to read its | 52 » // that can be used to read its contents. It is the caller's |
55 » // contents. It is the caller's responsibility to close it | 53 » // responsibility to close it after use. If the name does not |
56 » // after use. | 54 » // exist, it should return a *NotFoundError. |
57 Get(name string) (io.ReadCloser, error) | 55 Get(name string) (io.ReadCloser, error) |
58 | 56 |
59 » // List lists all files in the storage with the given prefix. | 57 » // List lists all names in the storage with the given prefix, in |
| 58 » // alphabetical order. The names in the storage are considered |
| 59 » // to be in a flat namespace, so the prefix may include slashes |
| 60 » // and the names returned are the full names for the matching |
| 61 » // entries. |
60 List(prefix string) ([]string, error) | 62 List(prefix string) ([]string, error) |
61 | 63 |
62 // TODO: URL returns a URL that can be used to access the given | 64 // TODO: URL returns a URL that can be used to access the given |
63 // storage file. | 65 // storage file. |
64 // URL(name string) (string, error) | 66 // URL(name string) (string, error) |
65 } | 67 } |
66 | 68 |
67 // StorageWriter gives a way to change data stored | 69 // A StorageWriter adds and removes files in a storage provider. |
68 // within an environment. | |
69 type StorageWriter interface { | 70 type StorageWriter interface { |
70 // Put reads from r and writes to the given storage file. | 71 // Put reads from r and writes to the given storage file. |
71 // The length must give the total length of the file. | 72 // The length must give the total length of the file. |
72 Put(name string, r io.Reader, length int64) error | 73 Put(name string, r io.Reader, length int64) error |
73 | 74 |
74 // Remove removes the given file from the environment's | 75 // Remove removes the given file from the environment's |
75 // storage. It should not return an error if the file does | 76 // storage. It should not return an error if the file does |
76 // not exist. | 77 // not exist. |
77 Remove(name string) error | 78 Remove(name string) error |
78 } | 79 } |
79 | 80 |
80 // StorageReadWriter represents storage that can be both | 81 // Storage represents storage that can be both |
81 // read and written. | 82 // read and written. |
82 type StorageReadWriter interface { | 83 type Storage interface { |
83 StorageReader | 84 StorageReader |
84 StorageWriter | 85 StorageWriter |
85 } | 86 } |
86 | 87 |
87 // An Environ represents a juju environment as specified | 88 // An Environ represents a juju environment as specified |
88 // in the environments.yaml file. | 89 // in the environments.yaml file. |
89 //· | 90 //· |
90 // Due to the limitations of some providers (for example ec2), the | 91 // Due to the limitations of some providers (for example ec2), the |
91 // results of the Environ methods may not be fully sequentially | 92 // results of the Environ methods may not be fully sequentially |
92 // consistent. In particular, while a provider may retry when it | 93 // consistent. In particular, while a provider may retry when it |
(...skipping 25 matching lines...) Expand all Loading... |
118 | 119 |
119 // Instances returns a slice of instances corresponding to the | 120 // Instances returns a slice of instances corresponding to the |
120 // given instance ids. If no instances were found, but there | 121 // given instance ids. If no instances were found, but there |
121 // was no other error, it will return ErrNoInstances. If | 122 // was no other error, it will return ErrNoInstances. If |
122 // some but not all the instances were found, the returned slice | 123 // some but not all the instances were found, the returned slice |
123 // will have some nil slots, and an ErrPartialInstances error | 124 // will have some nil slots, and an ErrPartialInstances error |
124 // will be returned. | 125 // will be returned. |
125 Instances(ids []string) ([]Instance, error) | 126 Instances(ids []string) ([]Instance, error) |
126 | 127 |
127 // Storage returns storage specific to the environment. | 128 // Storage returns storage specific to the environment. |
128 » Storage() StorageReadWriter | 129 » Storage() Storage |
129 | 130 |
130 // PublicStorage returns storage shared between environments. | 131 // PublicStorage returns storage shared between environments. |
131 PublicStorage() StorageReader | 132 PublicStorage() StorageReader |
132 | 133 |
133 // Destroy shuts down all known machines and destroys the | 134 // Destroy shuts down all known machines and destroys the |
134 // rest of the environment. A list of instances known to | 135 // rest of the environment. A list of instances known to |
135 // be part of the environment can be given with insts. | 136 // be part of the environment can be given with insts. |
136 // This is because recently started machines might not | 137 // This is because recently started machines might not |
137 // yet be visible in the environment, so this method | 138 // yet be visible in the environment, so this method |
138 // can wait until they are. | 139 // can wait until they are. |
139 Destroy(insts []Instance) error | 140 Destroy(insts []Instance) error |
140 } | 141 } |
LEFT | RIGHT |