github.com/Pankov404/juju@v0.0.0-20150703034450-be266991dceb/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  
    54  // StartInstanceResult holds the result of an
    55  // InstanceBroker.StartInstance method call.
    56  type StartInstanceResult struct {
    57  	// Instance is an interface representing a cloud instance.
    58  	Instance instance.Instance
    59  
    60  	// HardwareCharacteristics represents the hardware characteristics
    61  	// of the newly created instance.
    62  	Hardware *instance.HardwareCharacteristics
    63  
    64  	// NetworkInfo contains information about how to configure network
    65  	// interfaces on the instance. Depending on the provider, this
    66  	// might be the same StartInstanceParams.NetworkInfo or may be
    67  	// modified as needed.
    68  	NetworkInfo []network.InterfaceInfo
    69  
    70  	// Volumes contains a list of volumes created, each one having the
    71  	// same Name as one of the VolumeParams in StartInstanceParams.Volumes.
    72  	// VolumeAttachment information is reported separately.
    73  	Volumes []storage.Volume
    74  
    75  	// VolumeAttachments contains a attachment-specific information about
    76  	// volumes that were attached to the started instance.
    77  	VolumeAttachments []storage.VolumeAttachment
    78  }
    79  
    80  // TODO(wallyworld) - we want this in the environs/instance package but import loops
    81  // stop that from being possible right now.
    82  type InstanceBroker interface {
    83  	// StartInstance asks for a new instance to be created, associated with
    84  	// the provided config in machineConfig. The given config describes the juju
    85  	// state for the new instance to connect to. The config MachineNonce, which must be
    86  	// unique within an environment, is used by juju to protect against the
    87  	// consequences of multiple instances being started with the same machine
    88  	// id.
    89  	StartInstance(args StartInstanceParams) (*StartInstanceResult, error)
    90  
    91  	// StopInstances shuts down the instances with the specified IDs.
    92  	// Unknown instance IDs are ignored, to enable idempotency.
    93  	StopInstances(...instance.Id) error
    94  
    95  	// AllInstances returns all instances currently known to the broker.
    96  	AllInstances() ([]instance.Instance, error)
    97  
    98  	// MaintainInstance is used to run actions on jujud startup for existing
    99  	// instances. It is currently only used to ensure that LXC hosts have the
   100  	// correct network configuration.
   101  	MaintainInstance(args StartInstanceParams) error
   102  }