github.com/cloud-green/juju@v0.0.0-20151002100041-a00291338d3d/environs/broker.go (about) 1 // Copyright 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/cloudconfig/instancecfg" 8 "github.com/juju/juju/constraints" 9 "github.com/juju/juju/instance" 10 "github.com/juju/juju/network" 11 "github.com/juju/juju/storage" 12 "github.com/juju/juju/tools" 13 ) 14 15 // StartInstanceParams holds parameters for the 16 // InstanceBroker.StartInstance method. 17 type StartInstanceParams struct { 18 // Constraints is a set of constraints on 19 // the kind of instance to create. 20 Constraints constraints.Value 21 22 // Tools is a list of tools that may be used 23 // to start a Juju agent on the machine. 24 Tools tools.List 25 26 // InstanceConfig describes the machine's configuration. 27 InstanceConfig *instancecfg.InstanceConfig 28 29 // Placement, if non-empty, contains an environment-specific 30 // placement directive that may be used to decide how the 31 // instance should be started. 32 Placement string 33 34 // DistributionGroup, if non-nil, is a function 35 // that returns a slice of instance.Ids that belong 36 // to the same distribution group as the machine 37 // being provisioned. The InstanceBroker may use 38 // this information to distribute instances for 39 // high availability. 40 DistributionGroup func() ([]instance.Id, error) 41 42 // Volumes is a set of parameters for volumes that should be created. 43 // 44 // StartInstance need not check the value of the Attachment field, 45 // as it is guaranteed that any volumes in this list are designated 46 // for attachment to the instance being started. 47 Volumes []storage.VolumeParams 48 49 // NetworkInfo is an optional list of network interface details, 50 // necessary to configure on the instance. 51 NetworkInfo []network.InterfaceInfo 52 53 // SubnetsToZones is an optional map of provider-specific subnet 54 // id to a list of availability zone names the subnet is available 55 // in. It is only populated when valid positive spaces constraints 56 // are present. 57 SubnetsToZones map[network.Id][]string 58 } 59 60 // StartInstanceResult holds the result of an 61 // InstanceBroker.StartInstance method call. 62 type StartInstanceResult struct { 63 // Instance is an interface representing a cloud instance. 64 Instance instance.Instance 65 66 // HardwareCharacteristics represents the hardware characteristics 67 // of the newly created instance. 68 Hardware *instance.HardwareCharacteristics 69 70 // NetworkInfo contains information about how to configure network 71 // interfaces on the instance. Depending on the provider, this 72 // might be the same StartInstanceParams.NetworkInfo or may be 73 // modified as needed. 74 NetworkInfo []network.InterfaceInfo 75 76 // Volumes contains a list of volumes created, each one having the 77 // same Name as one of the VolumeParams in StartInstanceParams.Volumes. 78 // VolumeAttachment information is reported separately. 79 Volumes []storage.Volume 80 81 // VolumeAttachments contains a attachment-specific information about 82 // volumes that were attached to the started instance. 83 VolumeAttachments []storage.VolumeAttachment 84 } 85 86 // TODO(wallyworld) - we want this in the environs/instance package but import loops 87 // stop that from being possible right now. 88 type InstanceBroker interface { 89 // StartInstance asks for a new instance to be created, associated with 90 // the provided config in machineConfig. The given config describes the juju 91 // state for the new instance to connect to. The config MachineNonce, which must be 92 // unique within an environment, is used by juju to protect against the 93 // consequences of multiple instances being started with the same machine 94 // id. 95 StartInstance(args StartInstanceParams) (*StartInstanceResult, error) 96 97 // StopInstances shuts down the instances with the specified IDs. 98 // Unknown instance IDs are ignored, to enable idempotency. 99 StopInstances(...instance.Id) error 100 101 // AllInstances returns all instances currently known to the broker. 102 AllInstances() ([]instance.Instance, error) 103 104 // MaintainInstance is used to run actions on jujud startup for existing 105 // instances. It is currently only used to ensure that LXC hosts have the 106 // correct network configuration. 107 MaintainInstance(args StartInstanceParams) error 108 }