launchpad.net/~rogpeppe/juju-core/500-errgo-fix@v0.0.0-20140213181702-000000002356/environs/interface.go (about) 1 // Copyright 2011, 2012, 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package environs 5 6 import ( 7 "io" 8 "os" 9 10 "launchpad.net/juju-core/constraints" 11 "launchpad.net/juju-core/environs/config" 12 "launchpad.net/juju-core/environs/storage" 13 "launchpad.net/juju-core/instance" 14 "launchpad.net/juju-core/state" 15 "launchpad.net/juju-core/state/api" 16 ) 17 18 // A EnvironProvider represents a computing and storage provider. 19 type EnvironProvider interface { 20 // Prepare prepares an environment for use. Any additional 21 // configuration attributes in the returned environment should 22 // be saved to be used later. If the environment is already 23 // prepared, this call is equivalent to Open. 24 Prepare(cfg *config.Config) (Environ, error) 25 26 // Open opens the environment and returns it. 27 // The configuration must have come from a previously 28 // prepared environment. 29 Open(cfg *config.Config) (Environ, error) 30 31 // Validate ensures that config is a valid configuration for this 32 // provider, applying changes to it if necessary, and returns the 33 // validated configuration. 34 // If old is not nil, it holds the previous environment configuration 35 // for consideration when validating changes. 36 Validate(cfg, old *config.Config) (valid *config.Config, err error) 37 38 // Boilerplate returns a default configuration for the environment in yaml format. 39 // The text should be a key followed by some number of attributes: 40 // `environName: 41 // type: environTypeName 42 // attr1: val1 43 // ` 44 // The text is used as a template (see the template package) with one extra template 45 // function available, rand, which expands to a random hexadecimal string when invoked. 46 BoilerplateConfig() string 47 48 // SecretAttrs filters the supplied configuration returning only values 49 // which are considered sensitive. All of the values of these secret 50 // attributes need to be strings. 51 SecretAttrs(cfg *config.Config) (map[string]string, error) 52 53 // PublicAddress returns this machine's public host name. 54 PublicAddress() (string, error) 55 56 // PrivateAddress returns this machine's private host name. 57 PrivateAddress() (string, error) 58 } 59 60 // EnvironStorage implements storage access for an environment 61 type EnvironStorage interface { 62 // Storage returns storage specific to the environment. 63 Storage() storage.Storage 64 } 65 66 // BootstrapStorager is an interface through which an Environ may be 67 // instructed to use a special "bootstrap storage". Bootstrap storage 68 // is one that may be used before the bootstrap machine agent has been 69 // provisioned. 70 // 71 // This is useful for environments where the storage is managed by the 72 // machine agent once bootstrapped. 73 type BootstrapStorager interface { 74 // EnableBootstrapStorage enables bootstrap storage, returning an 75 // error if enablement failed. If nil is returned, then calling 76 // this again will have no effect and will return nil. 77 EnableBootstrapStorage(BootstrapContext) error 78 } 79 80 // ConfigGetter implements access to an environments configuration. 81 type ConfigGetter interface { 82 // Config returns the configuration data with which the Environ was created. 83 // Note that this is not necessarily current; the canonical location 84 // for the configuration data is stored in the state. 85 Config() *config.Config 86 } 87 88 // Prechecker is an optional interface that an Environ may implement, 89 // in order to support pre-flight checking of instance/container creation. 90 // 91 // Prechecker's methods are best effort, and not guaranteed to eliminate 92 // all invalid parameters. If a precheck method returns nil, it is not 93 // guaranteed that the constraints are valid; if a non-nil error is 94 // returned, then the constraints are definitely invalid. 95 type Prechecker interface { 96 // PrecheckInstance performs a preflight check on the specified 97 // series and constraints, ensuring that they are possibly valid for 98 // creating an instance in this environment. 99 PrecheckInstance(series string, cons constraints.Value) error 100 101 // PrecheckContainer performs a preflight check on the container type, 102 // ensuring that the environment is possibly capable of creating a 103 // container of the specified type and series. 104 // 105 // The container type must be a valid ContainerType as specified 106 // in the instance package, and != instance.NONE. 107 PrecheckContainer(series string, kind instance.ContainerType) error 108 } 109 110 // An Environ represents a juju environment as specified 111 // in the environments.yaml file. 112 // 113 // Due to the limitations of some providers (for example ec2), the 114 // results of the Environ methods may not be fully sequentially 115 // consistent. In particular, while a provider may retry when it 116 // gets an error for an operation, it will not retry when 117 // an operation succeeds, even if that success is not 118 // consistent with a previous operation. 119 // 120 // Even though Juju takes care not to share an Environ between concurrent 121 // workers, it does allow concurrent method calls into the provider 122 // implementation. The typical provider implementation needs locking to 123 // avoid undefined behaviour when the configuration changes. 124 type Environ interface { 125 // Name returns the Environ's name. 126 Name() string 127 128 // Bootstrap initializes the state for the environment, possibly 129 // starting one or more instances. If the configuration's 130 // AdminSecret is non-empty, the administrator password on the 131 // newly bootstrapped state will be set to a hash of it (see 132 // utils.PasswordHash), When first connecting to the 133 // environment via the juju package, the password hash will be 134 // automatically replaced by the real password. 135 // 136 // The supplied constraints are used to choose the initial instance 137 // specification, and will be stored in the new environment's state. 138 // 139 // Bootstrap is responsible for selecting the appropriate tools, 140 // and setting the agent-version configuration attribute prior to 141 // bootstrapping the environment. 142 Bootstrap(ctx BootstrapContext, cons constraints.Value) error 143 144 // StateInfo returns information on the state initialized 145 // by Bootstrap. 146 StateInfo() (*state.Info, *api.Info, error) 147 148 // InstanceBroker defines methods for starting and stopping 149 // instances. 150 InstanceBroker 151 152 // ConfigGetter allows the retrieval of the configuration data. 153 ConfigGetter 154 155 // SetConfig updates the Environ's configuration. 156 // 157 // Calls to SetConfig do not affect the configuration of 158 // values previously obtained from Storage. 159 SetConfig(cfg *config.Config) error 160 161 // Instances returns a slice of instances corresponding to the 162 // given instance ids. If no instances were found, but there 163 // was no other error, it will return ErrNoInstances. If 164 // some but not all the instances were found, the returned slice 165 // will have some nil slots, and an ErrPartialInstances error 166 // will be returned. 167 Instances(ids []instance.Id) ([]instance.Instance, error) 168 169 EnvironStorage 170 171 // Destroy shuts down all known machines and destroys the 172 // rest of the environment. Note that on some providers, 173 // very recently started instances may not be destroyed 174 // because they are not yet visible. 175 // 176 // When Destroy has been called, any Environ referring to the 177 // same remote environment may become invalid 178 Destroy() error 179 180 // OpenPorts opens the given ports for the whole environment. 181 // Must only be used if the environment was setup with the 182 // FwGlobal firewall mode. 183 OpenPorts(ports []instance.Port) error 184 185 // ClosePorts closes the given ports for the whole environment. 186 // Must only be used if the environment was setup with the 187 // FwGlobal firewall mode. 188 ClosePorts(ports []instance.Port) error 189 190 // Ports returns the ports opened for the whole environment. 191 // Must only be used if the environment was setup with the 192 // FwGlobal firewall mode. 193 Ports() ([]instance.Port, error) 194 195 // Provider returns the EnvironProvider that created this Environ. 196 Provider() EnvironProvider 197 } 198 199 // BootstrapContext is an interface that is passed to 200 // Environ.Bootstrap, providing a means of obtaining 201 // information about and manipulating the context in which 202 // it is being invoked. 203 type BootstrapContext interface { 204 Stdin() io.Reader 205 Stdout() io.Writer 206 Stderr() io.Writer 207 208 // InterruptNotify starts watching for interrupt signals 209 // on behalf of the caller, sending them to the supplied 210 // channel. 211 InterruptNotify(sig chan<- os.Signal) 212 213 // StopInterruptNotify undoes the effects of a previous 214 // call to InterruptNotify with the same channel. After 215 // StopInterruptNotify returns, no more signals will be 216 // delivered to the channel. 217 StopInterruptNotify(chan<- os.Signal) 218 }