-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbroker.go
138 lines (113 loc) · 5.33 KB
/
broker.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// Copyright 2013 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package environs
import (
"github.com/juju/juju/cloudconfig/instancecfg"
"github.com/juju/juju/constraints"
"github.com/juju/juju/environs/config"
"github.com/juju/juju/environs/imagemetadata"
"github.com/juju/juju/instance"
"github.com/juju/juju/network"
"github.com/juju/juju/status"
"github.com/juju/juju/storage"
"github.com/juju/juju/tools"
)
// StatusCallbackFunc represents a function that can be called to report a status.
type StatusCallbackFunc func(settableStatus status.Status, info string, data map[string]interface{}) error
// StartInstanceParams holds parameters for the
// InstanceBroker.StartInstance method.
type StartInstanceParams struct {
// ControllerUUID is the uuid of the controller.
ControllerUUID string
// Constraints is a set of constraints on
// the kind of instance to create.
Constraints constraints.Value
// Tools is a list of tools that may be used
// to start a Juju agent on the machine.
Tools tools.List
// InstanceConfig describes the machine's configuration.
InstanceConfig *instancecfg.InstanceConfig
// Placement, if non-empty, contains an environment-specific
// placement directive that may be used to decide how the
// instance should be started.
Placement string
// DistributionGroup, if non-nil, is a function
// that returns a slice of instance.Ids that belong
// to the same distribution group as the machine
// being provisioned. The InstanceBroker may use
// this information to distribute instances for
// high availability.
DistributionGroup func() ([]instance.Id, error)
// Volumes is a set of parameters for volumes that should be created.
//
// StartInstance need not check the value of the Attachment field,
// as it is guaranteed that any volumes in this list are designated
// for attachment to the instance being started.
Volumes []storage.VolumeParams
// NetworkInfo is an optional list of network interface details,
// necessary to configure on the instance.
NetworkInfo []network.InterfaceInfo
// SubnetsToZones is an optional map of provider-specific subnet
// id to a list of availability zone names the subnet is available
// in. It is only populated when valid positive spaces constraints
// are present.
SubnetsToZones map[network.Id][]string
// EndpointBindings holds the mapping between service endpoint names to
// provider-specific space IDs. It is populated when provisioning a machine
// to host a unit of a service with endpoint bindings.
EndpointBindings map[string]network.Id
// ImageMetadata is a collection of image metadata
// that may be used to start this instance.
ImageMetadata []*imagemetadata.ImageMetadata
// CleanupCallback is a callback to be used to clean up any residual
// status-reporting output from StatusCallback.
CleanupCallback func(info string) error
// StatusCallback is a callback to be used by the instance to report
// changes in status. Its signature is consistent with other
// status-related functions to allow them to be used as callbacks.
StatusCallback StatusCallbackFunc
}
// StartInstanceResult holds the result of an
// InstanceBroker.StartInstance method call.
type StartInstanceResult struct {
// Instance is an interface representing a cloud instance.
Instance instance.Instance
// Config holds the environment config to be used for any further
// operations, if the instance is for a controller.
Config *config.Config
// HardwareCharacteristics represents the hardware characteristics
// of the newly created instance.
Hardware *instance.HardwareCharacteristics
// NetworkInfo contains information about how to configure network
// interfaces on the instance. Depending on the provider, this
// might be the same StartInstanceParams.NetworkInfo or may be
// modified as needed.
NetworkInfo []network.InterfaceInfo
// Volumes contains a list of volumes created, each one having the
// same Name as one of the VolumeParams in StartInstanceParams.Volumes.
// VolumeAttachment information is reported separately.
Volumes []storage.Volume
// VolumeAttachments contains a attachment-specific information about
// volumes that were attached to the started instance.
VolumeAttachments []storage.VolumeAttachment
}
// TODO(wallyworld) - we want this in the environs/instance package but import loops
// stop that from being possible right now.
type InstanceBroker interface {
// StartInstance asks for a new instance to be created, associated with
// the provided config in machineConfig. The given config describes the juju
// state for the new instance to connect to. The config MachineNonce, which must be
// unique within an environment, is used by juju to protect against the
// consequences of multiple instances being started with the same machine
// id.
StartInstance(args StartInstanceParams) (*StartInstanceResult, error)
// StopInstances shuts down the instances with the specified IDs.
// Unknown instance IDs are ignored, to enable idempotency.
StopInstances(...instance.Id) error
// AllInstances returns all instances currently known to the broker.
AllInstances() ([]instance.Instance, error)
// MaintainInstance is used to run actions on jujud startup for existing
// instances. It is currently only used to ensure that LXC hosts have the
// correct network configuration.
MaintainInstance(args StartInstanceParams) error
}