~nskaggs/+junk/xenial-test

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/core/description/interfaces.go

  • Committer: Nicholas Skaggs
  • Date: 2016-10-24 20:56:05 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161024205605-z8lta0uvuhtxwzwl
Initi with beta15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2016 Canonical Ltd.
 
2
// Licensed under the AGPLv3, see LICENCE file for details.
 
3
 
 
4
package description
 
5
 
 
6
import (
 
7
        "time"
 
8
 
 
9
        "github.com/juju/version"
 
10
        "gopkg.in/juju/names.v2"
 
11
)
 
12
 
 
13
// HasAnnotations defines the common methods for setting and
 
14
// getting annotations for the various entities.
 
15
type HasAnnotations interface {
 
16
        Annotations() map[string]string
 
17
        SetAnnotations(map[string]string)
 
18
}
 
19
 
 
20
// HasConstraints defines the common methods for setting and
 
21
// getting constraints for the various entities.
 
22
type HasConstraints interface {
 
23
        Constraints() Constraints
 
24
        SetConstraints(ConstraintsArgs)
 
25
}
 
26
 
 
27
// HasStatus defines the common methods for setting and getting status
 
28
// entries for the various entities.
 
29
type HasStatus interface {
 
30
        Status() Status
 
31
        SetStatus(StatusArgs)
 
32
}
 
33
 
 
34
// HasStatusHistory defines the common methods for setting and
 
35
// getting historical status entries for the various entities.
 
36
type HasStatusHistory interface {
 
37
        StatusHistory() []Status
 
38
        SetStatusHistory([]StatusArgs)
 
39
}
 
40
 
 
41
// Model is a database agnostic representation of an existing model.
 
42
type Model interface {
 
43
        HasAnnotations
 
44
        HasConstraints
 
45
 
 
46
        Cloud() string
 
47
        CloudRegion() string
 
48
        CloudCredential() string
 
49
        Tag() names.ModelTag
 
50
        Owner() names.UserTag
 
51
        Config() map[string]interface{}
 
52
        LatestToolsVersion() version.Number
 
53
 
 
54
        // UpdateConfig overwrites existing config values with those specified.
 
55
        UpdateConfig(map[string]interface{})
 
56
 
 
57
        // Blocks returns a map of block type to the message associated with that
 
58
        // block.
 
59
        Blocks() map[string]string
 
60
 
 
61
        Users() []User
 
62
        AddUser(UserArgs)
 
63
 
 
64
        Machines() []Machine
 
65
        AddMachine(MachineArgs) Machine
 
66
 
 
67
        Applications() []Application
 
68
        AddApplication(ApplicationArgs) Application
 
69
 
 
70
        Relations() []Relation
 
71
        AddRelation(RelationArgs) Relation
 
72
 
 
73
        Spaces() []Space
 
74
        AddSpace(SpaceArgs) Space
 
75
 
 
76
        LinkLayerDevices() []LinkLayerDevice
 
77
        AddLinkLayerDevice(LinkLayerDeviceArgs) LinkLayerDevice
 
78
 
 
79
        Subnets() []Subnet
 
80
        AddSubnet(SubnetArgs) Subnet
 
81
 
 
82
        IPAddresses() []IPAddress
 
83
        AddIPAddress(IPAddressArgs) IPAddress
 
84
 
 
85
        SSHHostKeys() []SSHHostKey
 
86
        AddSSHHostKey(SSHHostKeyArgs) SSHHostKey
 
87
 
 
88
        Sequences() map[string]int
 
89
        SetSequence(name string, value int)
 
90
 
 
91
        Volumes() []Volume
 
92
        AddVolume(VolumeArgs) Volume
 
93
 
 
94
        Filesystems() []Filesystem
 
95
        AddFilesystem(FilesystemArgs) Filesystem
 
96
 
 
97
        Validate() error
 
98
}
 
99
 
 
100
// User represents a user of the model. Users are able to connect to, and
 
101
// depending on the read only flag, modify the model.
 
102
type User interface {
 
103
        Name() names.UserTag
 
104
        DisplayName() string
 
105
        CreatedBy() names.UserTag
 
106
        DateCreated() time.Time
 
107
        LastConnection() time.Time
 
108
        Access() Access
 
109
}
 
110
 
 
111
// Address represents an IP Address of some form.
 
112
type Address interface {
 
113
        Value() string
 
114
        Type() string
 
115
        Scope() string
 
116
        Origin() string
 
117
}
 
118
 
 
119
// AgentTools represent the version and related binary file
 
120
// that the machine and unit agents are using.
 
121
type AgentTools interface {
 
122
        Version() version.Binary
 
123
        URL() string
 
124
        SHA256() string
 
125
        Size() int64
 
126
}
 
127
 
 
128
// Machine represents an existing live machine or container running in the
 
129
// model.
 
130
type Machine interface {
 
131
        HasAnnotations
 
132
        HasConstraints
 
133
        HasStatus
 
134
        HasStatusHistory
 
135
 
 
136
        Id() string
 
137
        Tag() names.MachineTag
 
138
        Nonce() string
 
139
        PasswordHash() string
 
140
        Placement() string
 
141
        Series() string
 
142
        ContainerType() string
 
143
        Jobs() []string
 
144
        SupportedContainers() ([]string, bool)
 
145
 
 
146
        Instance() CloudInstance
 
147
        SetInstance(CloudInstanceArgs)
 
148
 
 
149
        // Life() string -- only transmit alive things?
 
150
        ProviderAddresses() []Address
 
151
        MachineAddresses() []Address
 
152
        SetAddresses(machine []AddressArgs, provider []AddressArgs)
 
153
 
 
154
        PreferredPublicAddress() Address
 
155
        PreferredPrivateAddress() Address
 
156
        SetPreferredAddresses(public AddressArgs, private AddressArgs)
 
157
 
 
158
        Tools() AgentTools
 
159
        SetTools(AgentToolsArgs)
 
160
 
 
161
        Containers() []Machine
 
162
        AddContainer(MachineArgs) Machine
 
163
 
 
164
        // TODO:
 
165
        // Storage
 
166
 
 
167
        BlockDevices() []BlockDevice
 
168
        AddBlockDevice(BlockDeviceArgs) BlockDevice
 
169
 
 
170
        OpenedPorts() []OpenedPorts
 
171
        AddOpenedPorts(OpenedPortsArgs) OpenedPorts
 
172
 
 
173
        // THINKING: Validate() error to make sure the machine has
 
174
        // enough stuff set, like tools, and addresses etc.
 
175
        Validate() error
 
176
 
 
177
        // reboot doc
 
178
        // block devices
 
179
        // port docs
 
180
        // machine filesystems
 
181
}
 
182
 
 
183
// OpenedPorts represents a collection of port ranges that are open on a
 
184
// particular subnet. OpenedPorts are always associated with a Machine.
 
185
type OpenedPorts interface {
 
186
        SubnetID() string
 
187
        OpenPorts() []PortRange
 
188
}
 
189
 
 
190
// PortRange represents one or more contiguous ports opened by a particular
 
191
// Unit.
 
192
type PortRange interface {
 
193
        UnitName() string
 
194
        FromPort() int
 
195
        ToPort() int
 
196
        Protocol() string
 
197
}
 
198
 
 
199
// CloudInstance holds information particular to a machine
 
200
// instance in a cloud.
 
201
type CloudInstance interface {
 
202
        InstanceId() string
 
203
        Status() string
 
204
        Architecture() string
 
205
        Memory() uint64
 
206
        RootDisk() uint64
 
207
        CpuCores() uint64
 
208
        CpuPower() uint64
 
209
        Tags() []string
 
210
        AvailabilityZone() string
 
211
}
 
212
 
 
213
// Constraints holds information about particular deployment
 
214
// constraints for entities.
 
215
type Constraints interface {
 
216
        Architecture() string
 
217
        Container() string
 
218
        CpuCores() uint64
 
219
        CpuPower() uint64
 
220
        InstanceType() string
 
221
        Memory() uint64
 
222
        RootDisk() uint64
 
223
 
 
224
        Spaces() []string
 
225
        Tags() []string
 
226
 
 
227
        VirtType() string
 
228
}
 
229
 
 
230
// Status represents an agent, application, or workload status.
 
231
type Status interface {
 
232
        Value() string
 
233
        Message() string
 
234
        Data() map[string]interface{}
 
235
        Updated() time.Time
 
236
}
 
237
 
 
238
// Application represents a deployed charm in a model.
 
239
type Application interface {
 
240
        HasAnnotations
 
241
        HasConstraints
 
242
        HasStatus
 
243
        HasStatusHistory
 
244
 
 
245
        Tag() names.ApplicationTag
 
246
        Name() string
 
247
        Series() string
 
248
        Subordinate() bool
 
249
        CharmURL() string
 
250
        Channel() string
 
251
        CharmModifiedVersion() int
 
252
        ForceCharm() bool
 
253
        Exposed() bool
 
254
        MinUnits() int
 
255
 
 
256
        Settings() map[string]interface{}
 
257
        SettingsRefCount() int
 
258
 
 
259
        Leader() string
 
260
        LeadershipSettings() map[string]interface{}
 
261
 
 
262
        MetricsCredentials() []byte
 
263
 
 
264
        Units() []Unit
 
265
        AddUnit(UnitArgs) Unit
 
266
 
 
267
        Validate() error
 
268
}
 
269
 
 
270
// Unit represents an instance of an application in a model.
 
271
type Unit interface {
 
272
        HasAnnotations
 
273
        HasConstraints
 
274
 
 
275
        Tag() names.UnitTag
 
276
        Name() string
 
277
        Machine() names.MachineTag
 
278
 
 
279
        PasswordHash() string
 
280
 
 
281
        Principal() names.UnitTag
 
282
        Subordinates() []names.UnitTag
 
283
 
 
284
        MeterStatusCode() string
 
285
        MeterStatusInfo() string
 
286
 
 
287
        // TODO: storage
 
288
 
 
289
        Tools() AgentTools
 
290
        SetTools(AgentToolsArgs)
 
291
 
 
292
        WorkloadStatus() Status
 
293
        SetWorkloadStatus(StatusArgs)
 
294
 
 
295
        WorkloadStatusHistory() []Status
 
296
        SetWorkloadStatusHistory([]StatusArgs)
 
297
 
 
298
        WorkloadVersion() string
 
299
 
 
300
        WorkloadVersionHistory() []Status
 
301
        SetWorkloadVersionHistory([]StatusArgs)
 
302
 
 
303
        AgentStatus() Status
 
304
        SetAgentStatus(StatusArgs)
 
305
 
 
306
        AgentStatusHistory() []Status
 
307
        SetAgentStatusHistory([]StatusArgs)
 
308
 
 
309
        Validate() error
 
310
}
 
311
 
 
312
// Relation represents a relationship between two applications,
 
313
// or a peer relation between different instances of an application.
 
314
type Relation interface {
 
315
        Id() int
 
316
        Key() string
 
317
 
 
318
        Endpoints() []Endpoint
 
319
        AddEndpoint(EndpointArgs) Endpoint
 
320
}
 
321
 
 
322
// Endpoint represents one end of a relation. A named endpoint provided
 
323
// by the charm that is deployed for the application.
 
324
type Endpoint interface {
 
325
        ApplicationName() string
 
326
        Name() string
 
327
        // Role, Interface, Optional, Limit, and Scope should all be available
 
328
        // through the Charm associated with the Application. There is no real need
 
329
        // for this information to be denormalised like this. However, for now,
 
330
        // since the import may well take place before the charms have been loaded
 
331
        // into the model, we'll send this information over.
 
332
        Role() string
 
333
        Interface() string
 
334
        Optional() bool
 
335
        Limit() int
 
336
        Scope() string
 
337
 
 
338
        // UnitCount returns the number of units the endpoint has settings for.
 
339
        UnitCount() int
 
340
 
 
341
        Settings(unitName string) map[string]interface{}
 
342
        SetUnitSettings(unitName string, settings map[string]interface{})
 
343
}
 
344
 
 
345
// Space represents a network space, which is a named collection of subnets.
 
346
type Space interface {
 
347
        Name() string
 
348
        Public() bool
 
349
        ProviderID() string
 
350
}
 
351
 
 
352
// LinkLayerDevice represents a link layer device.
 
353
type LinkLayerDevice interface {
 
354
        Name() string
 
355
        MTU() uint
 
356
        ProviderID() string
 
357
        MachineID() string
 
358
        Type() string
 
359
        MACAddress() string
 
360
        IsAutoStart() bool
 
361
        IsUp() bool
 
362
        ParentName() string
 
363
}
 
364
 
 
365
// Subnet represents a network subnet.
 
366
type Subnet interface {
 
367
        ProviderId() string
 
368
        CIDR() string
 
369
        VLANTag() int
 
370
        AvailabilityZone() string
 
371
        SpaceName() string
 
372
        AllocatableIPHigh() string
 
373
        AllocatableIPLow() string
 
374
}
 
375
 
 
376
// IPAddress represents an IP address.
 
377
type IPAddress interface {
 
378
        ProviderID() string
 
379
        DeviceName() string
 
380
        MachineID() string
 
381
        SubnetCIDR() string
 
382
        ConfigMethod() string
 
383
        Value() string
 
384
        DNSServers() []string
 
385
        DNSSearchDomains() []string
 
386
        GatewayAddress() string
 
387
}
 
388
 
 
389
// SSHHostKey represents an ssh host key.
 
390
type SSHHostKey interface {
 
391
        MachineID() string
 
392
        Keys() []string
 
393
}
 
394
 
 
395
// Volume represents a volume (disk, logical volume, etc.) in the model.
 
396
type Volume interface {
 
397
        HasStatus
 
398
        HasStatusHistory
 
399
 
 
400
        Tag() names.VolumeTag
 
401
        Storage() names.StorageTag
 
402
 
 
403
        Binding() (names.Tag, error)
 
404
 
 
405
        Provisioned() bool
 
406
 
 
407
        Size() uint64
 
408
        Pool() string
 
409
 
 
410
        HardwareID() string
 
411
        VolumeID() string
 
412
        Persistent() bool
 
413
 
 
414
        Attachments() []VolumeAttachment
 
415
        AddAttachment(VolumeAttachmentArgs) VolumeAttachment
 
416
}
 
417
 
 
418
// VolumeAttachment represents a volume attached to a machine.
 
419
type VolumeAttachment interface {
 
420
        Machine() names.MachineTag
 
421
        Provisioned() bool
 
422
        ReadOnly() bool
 
423
        DeviceName() string
 
424
        DeviceLink() string
 
425
        BusAddress() string
 
426
}
 
427
 
 
428
// Filesystem represents a filesystem in the model.
 
429
type Filesystem interface {
 
430
        HasStatus
 
431
        HasStatusHistory
 
432
 
 
433
        Tag() names.FilesystemTag
 
434
        Volume() names.VolumeTag
 
435
        Storage() names.StorageTag
 
436
        Binding() (names.Tag, error)
 
437
 
 
438
        Provisioned() bool
 
439
 
 
440
        Size() uint64
 
441
        Pool() string
 
442
 
 
443
        FilesystemID() string
 
444
 
 
445
        Attachments() []FilesystemAttachment
 
446
        AddAttachment(FilesystemAttachmentArgs) FilesystemAttachment
 
447
}
 
448
 
 
449
// FilesystemAttachment represents a filesystem attached to a machine.
 
450
type FilesystemAttachment interface {
 
451
        Machine() names.MachineTag
 
452
        Provisioned() bool
 
453
        MountPoint() string
 
454
        ReadOnly() bool
 
455
}