github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/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 "github.com/juju/juju/cloud" 8 "github.com/juju/juju/constraints" 9 "github.com/juju/juju/environs/config" 10 "github.com/juju/juju/instance" 11 "github.com/juju/juju/network" 12 "github.com/juju/juju/state" 13 ) 14 15 // A EnvironProvider represents a computing and storage provider. 16 type EnvironProvider interface { 17 // RestrictedConfigAttributes are provider specific attributes stored in 18 // the config that really cannot or should not be changed across 19 // environments running inside a single juju server. 20 RestrictedConfigAttributes() []string 21 22 // PrepareForCreateEnvironment prepares an environment for creation. Any 23 // additional configuration attributes are added to the config passed in 24 // and returned. This allows providers to add additional required config 25 // for new environments that may be created in an existing juju server. 26 // Note that this is not called in a client context, so environment variables, 27 // local files, etc are not available. 28 PrepareForCreateEnvironment(cfg *config.Config) (*config.Config, error) 29 30 // PrepareForBootstrap prepares an environment for use. 31 PrepareForBootstrap(ctx BootstrapContext, cfg *config.Config) (Environ, error) 32 33 // BootstrapConfig produces the configuration for the initial controller 34 // model, based on the provided arguments. BootstrapConfig is expected 35 // to produce a deterministic output. Any unique values should be based 36 // on the "uuid" attribute of the base configuration. 37 BootstrapConfig(BootstrapConfigParams) (*config.Config, error) 38 39 // Open opens the environment and returns it. 40 // The configuration must have come from a previously 41 // prepared environment. 42 Open(cfg *config.Config) (Environ, error) 43 44 // Validate ensures that config is a valid configuration for this 45 // provider, applying changes to it if necessary, and returns the 46 // validated configuration. 47 // If old is not nil, it holds the previous environment configuration 48 // for consideration when validating changes. 49 Validate(cfg, old *config.Config) (valid *config.Config, err error) 50 51 // SecretAttrs filters the supplied configuration returning only values 52 // which are considered sensitive. All of the values of these secret 53 // attributes need to be strings. 54 SecretAttrs(cfg *config.Config) (map[string]string, error) 55 56 ProviderCredentials 57 } 58 59 // BootstrapConfigParams contains the parameters for EnvironProvider.BootstrapConfig. 60 type BootstrapConfigParams struct { 61 // Config is the base configuration for the provider. This should 62 // be updated with the region, endpoint and credentials. 63 Config *config.Config 64 65 // Credentials is the set of credentials to use to bootstrap. 66 // 67 // TODO(axw) rename field to Credential. 68 Credentials cloud.Credential 69 70 // CloudRegion is the name of the region of the cloud to create 71 // the Juju controller in. This will be empty for clouds without 72 // regions. 73 CloudRegion string 74 75 // CloudEndpoint is the location of the primary API endpoint to 76 // use when communicating with the cloud. 77 CloudEndpoint string 78 79 // CloudStorageEndpoint is the location of the API endpoint to use 80 // when communicating with the cloud's storage service. This will 81 // be empty for clouds that have no cloud-specific API endpoint. 82 CloudStorageEndpoint string 83 } 84 85 // ProviderCredentials is an interface that an EnvironProvider implements 86 // in order to validate and automatically detect credentials for clouds 87 // supported by the provider. 88 // 89 // TODO(axw) replace CredentialSchemas with an updated environschema. 90 // The GUI also needs to be able to handle multiple credential types, 91 // and dependencies in config attributes. 92 type ProviderCredentials interface { 93 // CredentialSchemas returns credential schemas, keyed on 94 // authentication type. These may be used to validate existing 95 // credentials, or to generate new ones (e.g. to create an 96 // interactive form.) 97 CredentialSchemas() map[cloud.AuthType]cloud.CredentialSchema 98 99 // DetectCredentials automatically detects one or more credentials 100 // from the environment. This may involve, for example, inspecting 101 // environment variables, or reading configuration files in 102 // well-defined locations. 103 // 104 // If no credentials can be detected, DetectCredentials should 105 // return an error satisfying errors.IsNotFound. 106 DetectCredentials() (*cloud.CloudCredential, error) 107 } 108 109 // CloudRegionDetector is an interface that an EnvironProvider implements 110 // in order to automatically detect cloud regions from the environment. 111 type CloudRegionDetector interface { 112 // DetectRetions automatically detects one or more regions 113 // from the environment. This may involve, for example, inspecting 114 // environment variables, or returning special hard-coded regions 115 // (e.g. "localhost" for lxd). The first item in the list will be 116 // considered the default region for bootstrapping if the user 117 // does not specify one. 118 // 119 // If no regions can be detected, DetectRegions should return 120 // an error satisfying errors.IsNotFound. 121 DetectRegions() ([]cloud.Region, error) 122 } 123 124 // ModelConfigUpgrader is an interface that an EnvironProvider may 125 // implement in order to modify environment configuration on agent upgrade. 126 type ModelConfigUpgrader interface { 127 // UpgradeConfig upgrades an old environment configuration by adding, 128 // updating or removing attributes. UpgradeConfig must be idempotent, 129 // as it may be called multiple times in the event of a partial upgrade. 130 // 131 // NOTE(axw) this is currently only called when upgrading to 1.25. 132 // We should update the upgrade machinery to call this for every 133 // version upgrade, so the upgrades package is not tightly coupled 134 // to provider upgrades. 135 UpgradeConfig(cfg *config.Config) (*config.Config, error) 136 } 137 138 // ConfigGetter implements access to an environment's configuration. 139 type ConfigGetter interface { 140 // Config returns the configuration data with which the Environ was created. 141 // Note that this is not necessarily current; the canonical location 142 // for the configuration data is stored in the state. 143 Config() *config.Config 144 } 145 146 // An Environ represents a Juju environment. 147 // 148 // Due to the limitations of some providers (for example ec2), the 149 // results of the Environ methods may not be fully sequentially 150 // consistent. In particular, while a provider may retry when it 151 // gets an error for an operation, it will not retry when 152 // an operation succeeds, even if that success is not 153 // consistent with a previous operation. 154 // 155 // Even though Juju takes care not to share an Environ between concurrent 156 // workers, it does allow concurrent method calls into the provider 157 // implementation. The typical provider implementation needs locking to 158 // avoid undefined behaviour when the configuration changes. 159 type Environ interface { 160 // Bootstrap creates a new instance with the series and architecture 161 // of its choice, constrained to those of the available tools, and 162 // returns the instance's architecture, series, and a function that 163 // must be called to finalize the bootstrap process by transferring 164 // the tools and installing the initial Juju controller. 165 // 166 // It is possible to direct Bootstrap to use a specific architecture 167 // (or fail if it cannot start an instance of that architecture) by 168 // using an architecture constraint; this will have the effect of 169 // limiting the available tools to just those matching the specified 170 // architecture. 171 Bootstrap(ctx BootstrapContext, params BootstrapParams) (*BootstrapResult, error) 172 173 // InstanceBroker defines methods for starting and stopping 174 // instances. 175 InstanceBroker 176 177 // ConfigGetter allows the retrieval of the configuration data. 178 ConfigGetter 179 180 // EnvironCapability allows access to this environment's capabilities. 181 state.EnvironCapability 182 183 // ConstraintsValidator returns a Validator instance which 184 // is used to validate and merge constraints. 185 ConstraintsValidator() (constraints.Validator, error) 186 187 // SetConfig updates the Environ's configuration. 188 // 189 // Calls to SetConfig do not affect the configuration of 190 // values previously obtained from Storage. 191 SetConfig(cfg *config.Config) error 192 193 // Instances returns a slice of instances corresponding to the 194 // given instance ids. If no instances were found, but there 195 // was no other error, it will return ErrNoInstances. If 196 // some but not all the instances were found, the returned slice 197 // will have some nil slots, and an ErrPartialInstances error 198 // will be returned. 199 Instances(ids []instance.Id) ([]instance.Instance, error) 200 201 // ControllerInstances returns the IDs of instances corresponding 202 // to Juju controllers. If there are no controller instances, 203 // ErrNoInstances is returned. If it can be determined that the 204 // environment has not been bootstrapped, then ErrNotBootstrapped 205 // should be returned instead. 206 ControllerInstances() ([]instance.Id, error) 207 208 // Destroy shuts down all known machines and destroys the 209 // rest of the environment. Note that on some providers, 210 // very recently started instances may not be destroyed 211 // because they are not yet visible. 212 // 213 // If the Environ represents the controller model, then this 214 // method should also destroy any resources relating to hosted 215 // models. This ensures that "kill-controller" can clean up 216 // hosted models when the Juju controller process is unavailable. 217 // 218 // When Destroy has been called, any Environ referring to the 219 // same remote environment may become invalid. 220 Destroy() error 221 222 Firewaller 223 224 // Provider returns the EnvironProvider that created this Environ. 225 Provider() EnvironProvider 226 227 state.Prechecker 228 } 229 230 // Firewaller exposes methods for managing network ports. 231 type Firewaller interface { 232 // OpenPorts opens the given port ranges for the whole environment. 233 // Must only be used if the environment was setup with the 234 // FwGlobal firewall mode. 235 OpenPorts(ports []network.PortRange) error 236 237 // ClosePorts closes the given port ranges for the whole environment. 238 // Must only be used if the environment was setup with the 239 // FwGlobal firewall mode. 240 ClosePorts(ports []network.PortRange) error 241 242 // Ports returns the port ranges opened for the whole environment. 243 // Must only be used if the environment was setup with the 244 // FwGlobal firewall mode. 245 Ports() ([]network.PortRange, error) 246 } 247 248 // InstanceTagger is an interface that can be used for tagging instances. 249 type InstanceTagger interface { 250 // TagInstance tags the given instance with the specified tags. 251 // 252 // The specified tags will replace any existing ones with the 253 // same names, but other existing tags will be left alone. 254 TagInstance(id instance.Id, tags map[string]string) error 255 } 256 257 // MigrationConfigUpdater is an optional interface that a provider 258 // can implement that will be called when the model is being imported 259 // into a new controller as part of model migration. If the provider stores 260 // information specific to the controller, this information can be extracted 261 // from the controller config. 262 // 263 // The return value is a map containing changes that are necessary to be 264 // applied to the model's config for the new controller. 265 type MigrationConfigUpdater interface { 266 MigrationConfigUpdate(controllerConfig *config.Config) map[string]interface{} 267 }