blob: 6b80115a5313eadb2f93cf8366e2b19230adbe2c [file] [log] [blame]
David K. Bainbridge528b3182017-01-23 08:51:59 -08001// Copyright 2016 Canonical Ltd.
2// Licensed under the LGPLv3, see LICENCE file for details.
3
4package gomaasapi
5
6import "github.com/juju/utils/set"
7
8const (
9 // Capability constants.
10 NetworksManagement = "networks-management"
11 StaticIPAddresses = "static-ipaddresses"
12 IPv6DeploymentUbuntu = "ipv6-deployment-ubuntu"
13 DevicesManagement = "devices-management"
14 StorageDeploymentUbuntu = "storage-deployment-ubuntu"
15 NetworkDeploymentUbuntu = "network-deployment-ubuntu"
16)
17
18// Controller represents an API connection to a MAAS Controller. Since the API
19// is restful, there is no long held connection to the API server, but instead
20// HTTP calls are made and JSON response structures parsed.
21type Controller interface {
22
23 // Capabilities returns a set of capabilities as defined by the string
24 // constants.
25 Capabilities() set.Strings
26
27 BootResources() ([]BootResource, error)
28
29 // Fabrics returns the list of Fabrics defined in the MAAS controller.
30 Fabrics() ([]Fabric, error)
31
32 // Spaces returns the list of Spaces defined in the MAAS controller.
33 Spaces() ([]Space, error)
34
35 // Zones lists all the zones known to the MAAS controller.
36 Zones() ([]Zone, error)
37
38 // Machines returns a list of machines that match the params.
39 Machines(MachinesArgs) ([]Machine, error)
40
41 // AllocateMachine will attempt to allocate a machine to the user.
42 // If successful, the allocated machine is returned.
43 AllocateMachine(AllocateMachineArgs) (Machine, ConstraintMatches, error)
44
45 // ReleaseMachines will stop the specified machines, and release them
46 // from the user making them available to be allocated again.
47 ReleaseMachines(ReleaseMachinesArgs) error
48
49 // Devices returns a list of devices that match the params.
50 Devices(DevicesArgs) ([]Device, error)
51
52 // CreateDevice creates and returns a new Device.
53 CreateDevice(CreateDeviceArgs) (Device, error)
54
55 // Files returns all the files that match the specified prefix.
56 Files(prefix string) ([]File, error)
57
58 // Return a single file by its filename.
59 GetFile(filename string) (File, error)
60
61 // AddFile adds or replaces the content of the specified filename.
62 // If or when the MAAS api is able to return metadata about a single
63 // file without sending the content of the file, we can return a File
64 // instance here too.
65 AddFile(AddFileArgs) error
66}
67
68// File represents a file stored in the MAAS controller.
69type File interface {
70 // Filename is the name of the file. No path, just the filename.
71 Filename() string
72
73 // AnonymousURL is a URL that can be used to retrieve the conents of the
74 // file without credentials.
75 AnonymousURL() string
76
77 // Delete removes the file from the MAAS controller.
78 Delete() error
79
80 // ReadAll returns the content of the file.
81 ReadAll() ([]byte, error)
82}
83
84// Fabric represents a set of interconnected VLANs that are capable of mutual
85// communication. A fabric can be thought of as a logical grouping in which
86// VLANs can be considered unique.
87//
88// For example, a distributed network may have a fabric in London containing
89// VLAN 100, while a separate fabric in San Francisco may contain a VLAN 100,
90// whose attached subnets are completely different and unrelated.
91type Fabric interface {
92 ID() int
93 Name() string
94 ClassType() string
95
96 VLANs() []VLAN
97}
98
99// VLAN represents an instance of a Virtual LAN. VLANs are a common way to
100// create logically separate networks using the same physical infrastructure.
101//
102// Managed switches can assign VLANs to each port in either a “tagged” or an
103// “untagged” manner. A VLAN is said to be “untagged” on a particular port when
104// it is the default VLAN for that port, and requires no special configuration
105// in order to access.
106//
107// “Tagged” VLANs (traditionally used by network administrators in order to
108// aggregate multiple networks over inter-switch “trunk” lines) can also be used
109// with nodes in MAAS. That is, if a switch port is configured such that
110// “tagged” VLAN frames can be sent and received by a MAAS node, that MAAS node
111// can be configured to automatically bring up VLAN interfaces, so that the
112// deployed node can make use of them.
113//
114// A “Default VLAN” is created for every Fabric, to which every new VLAN-aware
115// object in the fabric will be associated to by default (unless otherwise
116// specified).
117type VLAN interface {
118 ID() int
119 Name() string
120 Fabric() string
121
122 // VID is the VLAN ID. eth0.10 -> VID = 10.
123 VID() int
124 // MTU (maximum transmission unit) is the largest size packet or frame,
125 // specified in octets (eight-bit bytes), that can be sent.
126 MTU() int
127 DHCP() bool
128
129 PrimaryRack() string
130 SecondaryRack() string
131}
132
133// Zone represents a physical zone that a Machine is in. The meaning of a
134// physical zone is up to you: it could identify e.g. a server rack, a network,
135// or a data centre. Users can then allocate nodes from specific physical zones,
136// to suit their redundancy or performance requirements.
137type Zone interface {
138 Name() string
139 Description() string
140}
141
142// BootResource is the bomb... find something to say here.
143type BootResource interface {
144 ID() int
145 Name() string
146 Type() string
147 Architecture() string
148 SubArchitectures() set.Strings
149 KernelFlavor() string
150}
151
152// Device represents some form of device in MAAS.
153type Device interface {
154 // TODO: add domain
155 SystemID() string
156 Hostname() string
157 FQDN() string
158 IPAddresses() []string
159 Zone() Zone
160
161 // Parent returns the SystemID of the Parent. Most often this will be a
162 // Machine.
163 Parent() string
164
165 // Owner is the username of the user that created the device.
166 Owner() string
167
168 // InterfaceSet returns all the interfaces for the Device.
169 InterfaceSet() []Interface
170
171 // CreateInterface will create a physical interface for this machine.
172 CreateInterface(CreateInterfaceArgs) (Interface, error)
173
174 // Delete will remove this Device.
175 Delete() error
176}
177
178// Machine represents a physical machine.
179type Machine interface {
180 OwnerDataHolder
181
182 SystemID() string
183 Hostname() string
184 FQDN() string
185 Tags() []string
186
187 OperatingSystem() string
188 DistroSeries() string
189 Architecture() string
190 Memory() int
191 CPUCount() int
192
193 IPAddresses() []string
194 PowerState() string
195
196 // Devices returns a list of devices that match the params and have
197 // this Machine as the parent.
198 Devices(DevicesArgs) ([]Device, error)
199
200 // Consider bundling the status values into a single struct.
201 // but need to check for consistent representation if exposed on other
202 // entities.
203
204 StatusName() string
205 StatusMessage() string
206
207 // BootInterface returns the interface that was used to boot the Machine.
208 BootInterface() Interface
209 // InterfaceSet returns all the interfaces for the Machine.
210 InterfaceSet() []Interface
211 // Interface returns the interface for the machine that matches the id
212 // specified. If there is no match, nil is returned.
213 Interface(id int) Interface
214
215 // PhysicalBlockDevices returns all the physical block devices on the machine.
216 PhysicalBlockDevices() []BlockDevice
217 // PhysicalBlockDevice returns the physical block device for the machine
218 // that matches the id specified. If there is no match, nil is returned.
219 PhysicalBlockDevice(id int) BlockDevice
220
221 // BlockDevices returns all the physical and virtual block devices on the machine.
222 BlockDevices() []BlockDevice
223
224 Zone() Zone
225
226 // Start the machine and install the operating system specified in the args.
227 Start(StartArgs) error
228
229 // CreateDevice creates a new Device with this Machine as the parent.
230 // The device will have one interface that is linked to the specified subnet.
231 CreateDevice(CreateMachineDeviceArgs) (Device, error)
232}
233
234// Space is a name for a collection of Subnets.
235type Space interface {
236 ID() int
237 Name() string
238 Subnets() []Subnet
239}
240
241// Subnet refers to an IP range on a VLAN.
242type Subnet interface {
243 ID() int
244 Name() string
245 Space() string
246 VLAN() VLAN
247
248 Gateway() string
249 CIDR() string
250 // dns_mode
251
252 // DNSServers is a list of ip addresses of the DNS servers for the subnet.
253 // This list may be empty.
254 DNSServers() []string
255}
256
257// Interface represents a physical or virtual network interface on a Machine.
258type Interface interface {
259 ID() int
260 Name() string
261 // The parents of an interface are the names of interfaces that must exist
262 // for this interface to exist. For example a parent of "eth0.100" would be
263 // "eth0". Parents may be empty.
264 Parents() []string
265 // The children interfaces are the names of those that are dependent on this
266 // interface existing. Children may be empty.
267 Children() []string
268 Type() string
269 Enabled() bool
270 Tags() []string
271
272 VLAN() VLAN
273 Links() []Link
274
275 MACAddress() string
276 EffectiveMTU() int
277
278 // Params is a JSON field, and defaults to an empty string, but is almost
279 // always a JSON object in practice. Gleefully ignoring it until we need it.
280
281 // Update the name, mac address or VLAN.
282 Update(UpdateInterfaceArgs) error
283
284 // Delete this interface.
285 Delete() error
286
287 // LinkSubnet will attempt to make this interface available on the specified
288 // Subnet.
289 LinkSubnet(LinkSubnetArgs) error
290
291 // UnlinkSubnet will remove the Link to the subnet, and release the IP
292 // address associated if there is one.
293 UnlinkSubnet(Subnet) error
294}
295
296// Link represents a network link between an Interface and a Subnet.
297type Link interface {
298 ID() int
299 Mode() string
300 Subnet() Subnet
301 // IPAddress returns the address if one has been assigned.
302 // If unavailble, the address will be empty.
303 IPAddress() string
304}
305
306// FileSystem represents a formatted filesystem mounted at a location.
307type FileSystem interface {
308 // Type is the format type, e.g. "ext4".
309 Type() string
310
311 MountPoint() string
312 Label() string
313 UUID() string
314}
315
316// Partition represents a partition of a block device. It may be mounted
317// as a filesystem.
318type Partition interface {
319 ID() int
320 Path() string
321 // FileSystem may be nil if not mounted.
322 FileSystem() FileSystem
323 UUID() string
324 // UsedFor is a human readable string.
325 UsedFor() string
326 // Size is the number of bytes in the partition.
327 Size() uint64
328}
329
330// BlockDevice represents an entire block device on the machine.
331type BlockDevice interface {
332 ID() int
333 Name() string
334 Model() string
335 Path() string
336 UsedFor() string
337 Tags() []string
338
339 BlockSize() uint64
340 UsedSize() uint64
341 Size() uint64
342
343 Partitions() []Partition
344
345 // There are some other attributes for block devices, but we can
346 // expose them on an as needed basis.
347}
348
349// OwnerDataHolder represents any MAAS object that can store key/value
350// data.
351type OwnerDataHolder interface {
352 // OwnerData returns a copy of the key/value data stored for this
353 // object.
354 OwnerData() map[string]string
355
356 // SetOwnerData updates the key/value data stored for this object
357 // with the values passed in. Existing keys that aren't specified
358 // in the map passed in will be left in place; to clear a key set
359 // its value to "". All owner data is cleared when the object is
360 // released.
361 SetOwnerData(map[string]string) error
362}