forked from juju/juju
/
storage.go
670 lines (553 loc) · 22.2 KB
/
storage.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
// Copyright 2015 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package params
import "github.com/juju/juju/storage"
// MachineBlockDevices holds a machine tag and the block devices present
// on that machine.
type MachineBlockDevices struct {
Machine string `json:"machine"`
BlockDevices []storage.BlockDevice `json:"block-devices,omitempty"`
}
// SetMachineBlockDevices holds the arguments for recording the block
// devices present on a set of machines.
type SetMachineBlockDevices struct {
MachineBlockDevices []MachineBlockDevices `json:"machine-block-devices"`
}
// BlockDeviceResult holds the result of an API call to retrieve details
// of a block device.
type BlockDeviceResult struct {
Result storage.BlockDevice `json:"result"`
Error *Error `json:"error,omitempty"`
}
// BlockDeviceResults holds the result of an API call to retrieve details
// of multiple block devices.
type BlockDeviceResults struct {
Results []BlockDeviceResult `json:"results,omitempty"`
}
// BlockDevicesResult holds the result of an API call to retrieve details
// of all block devices relating to some entity.
type BlockDevicesResult struct {
Result []storage.BlockDevice `json:"result"`
Error *Error `json:"error,omitempty"`
}
// BlockDevicseResults holds the result of an API call to retrieve details
// of all block devices relating to some entities.
type BlockDevicesResults struct {
Results []BlockDevicesResult `json:"results,omitempty"`
}
// StorageInstance describes a storage instance.
type StorageInstance struct {
StorageTag string `json:"storage-tag"`
OwnerTag string `json:"owner-tag"`
Kind StorageKind `json:"kind"`
}
// StorageKind is the kind of a storage instance.
type StorageKind int
const (
StorageKindUnknown StorageKind = iota
StorageKindBlock
StorageKindFilesystem
)
// String returns representation of StorageKind for readability.
func (k *StorageKind) String() string {
switch *k {
case StorageKindBlock:
return "block"
case StorageKindFilesystem:
return "filesystem"
default:
return "unknown"
}
}
// StorageInstanceResult holds the result of an API call to retrieve details
// of a storage instance.
type StorageInstanceResult struct {
Result StorageInstance `json:"result"`
Error *Error `json:"error,omitempty"`
}
// StorageInstanceResults holds the result of an API call to retrieve details
// of multiple storage instances.
type StorageInstanceResults struct {
Results []StorageInstanceResult `json:"results,omitempty"`
}
// StorageAttachment describes a unit's attached storage instance.
type StorageAttachment struct {
StorageTag string `json:"storage-tag"`
OwnerTag string `json:"owner-tag"`
UnitTag string `json:"unit-tag"`
Kind StorageKind `json:"kind"`
Location string `json:"location"`
Life Life `json:"life"`
}
// StorageAttachmentId identifies a storage attachment by the tags of the
// related unit and storage instance.
type StorageAttachmentId struct {
StorageTag string `json:"storage-tag"`
UnitTag string `json:"unit-tag"`
}
// StorageAttachmentIds holds a set of storage attachment identifiers.
type StorageAttachmentIds struct {
Ids []StorageAttachmentId `json:"ids"`
}
// StorageAttachmentIdsResult holds the result of an API call to retrieve the
// IDs of a unit's attached storage instances.
type StorageAttachmentIdsResult struct {
Result StorageAttachmentIds `json:"result"`
Error *Error `json:"error,omitempty"`
}
// StorageAttachmentIdsResult holds the result of an API call to retrieve the
// IDs of multiple units attached storage instances.
type StorageAttachmentIdsResults struct {
Results []StorageAttachmentIdsResult `json:"results,omitempty"`
}
// StorageAttachmentsResult holds the result of an API call to retrieve details
// of a unit's attached storage instances.
type StorageAttachmentsResult struct {
Result []StorageAttachment `json:"result"`
Error *Error `json:"error,omitempty"`
}
// StorageAttachmentsResults holds the result of an API call to retrieve details
// of multiple units' attached storage instances.
type StorageAttachmentsResults struct {
Results []StorageAttachmentsResult `json:"results,omitempty"`
}
// StorageAttachmentResult holds the result of an API call to retrieve details
// of a storage attachment.
type StorageAttachmentResult struct {
Result StorageAttachment `json:"result"`
Error *Error `json:"error,omitempty"`
}
// StorageAttachmentResults holds the result of an API call to retrieve details
// of multiple storage attachments.
type StorageAttachmentResults struct {
Results []StorageAttachmentResult `json:"results,omitempty"`
}
// MachineStorageId identifies the attachment of a storage entity
// to a machine, by their tags.
type MachineStorageId struct {
MachineTag string `json:"machine-tag"`
// AttachmentTag is the tag of the volume or filesystem whose
// attachment to the machine is represented.
AttachmentTag string `json:"attachment-tag"`
}
// MachineStorageIds holds a set of machine/storage-entity
// attachment identifiers.
type MachineStorageIds struct {
Ids []MachineStorageId `json:"ids"`
}
// Volume identifies and describes a storage volume in the model.
type Volume struct {
VolumeTag string `json:"volume-tag"`
Info VolumeInfo `json:"info"`
}
// Volume describes a storage volume in the model.
type VolumeInfo struct {
VolumeId string `json:"volume-id"`
HardwareId string `json:"hardware-id,omitempty"`
// Size is the size of the volume in MiB.
Size uint64 `json:"size"`
Persistent bool `json:"persistent"`
}
// Volumes describes a set of storage volumes in the model.
type Volumes struct {
Volumes []Volume `json:"volumes"`
}
// VolumeAttachment identifies and describes a volume attachment.
type VolumeAttachment struct {
VolumeTag string `json:"volume-tag"`
MachineTag string `json:"machine-tag"`
Info VolumeAttachmentInfo `json:"info"`
}
// VolumeAttachmentInfo describes a volume attachment.
type VolumeAttachmentInfo struct {
DeviceName string `json:"device-name,omitempty"`
DeviceLink string `json:"device-link,omitempty"`
BusAddress string `json:"bus-address,omitempty"`
ReadOnly bool `json:"read-only,omitempty"`
}
// VolumeAttachments describes a set of storage volume attachments.
type VolumeAttachments struct {
VolumeAttachments []VolumeAttachment `json:"volume-attachments"`
}
// VolumeParams holds the parameters for creating a storage volume.
type VolumeParams struct {
VolumeTag string `json:"volume-tag"`
Size uint64 `json:"size"`
Provider string `json:"provider"`
Attributes map[string]interface{} `json:"attributes,omitempty"`
Tags map[string]string `json:"tags,omitempty"`
Attachment *VolumeAttachmentParams `json:"attachment,omitempty"`
}
// VolumeAttachmentParams holds the parameters for creating a volume
// attachment.
type VolumeAttachmentParams struct {
VolumeTag string `json:"volume-tag"`
MachineTag string `json:"machine-tag"`
VolumeId string `json:"volume-id,omitempty"`
InstanceId string `json:"instance-id,omitempty"`
Provider string `json:"provider"`
ReadOnly bool `json:"read-only,omitempty"`
}
// VolumeAttachmentsResult holds the volume attachments for a single
// machine, or an error.
type VolumeAttachmentsResult struct {
Attachments []VolumeAttachment `json:"attachments,omitempty"`
Error *Error `json:"error,omitempty"`
}
// VolumeAttachmentsResults holds a set of VolumeAttachmentsResults for
// a set of machines.
type VolumeAttachmentsResults struct {
Results []VolumeAttachmentsResult `json:"results,omitempty"`
}
// VolumeAttachmentResult holds the details of a single volume attachment,
// or an error.
type VolumeAttachmentResult struct {
Result VolumeAttachment `json:"result"`
Error *Error `json:"error,omitempty"`
}
// VolumeAttachmentResults holds a set of VolumeAttachmentResults.
type VolumeAttachmentResults struct {
Results []VolumeAttachmentResult `json:"results,omitempty"`
}
// VolumeResult holds information about a volume.
type VolumeResult struct {
Result Volume `json:"result"`
Error *Error `json:"error,omitempty"`
}
// VolumeResults holds information about multiple volumes.
type VolumeResults struct {
Results []VolumeResult `json:"results,omitempty"`
}
// VolumeParamsResults holds provisioning parameters for a volume.
type VolumeParamsResult struct {
Result VolumeParams `json:"result"`
Error *Error `json:"error,omitempty"`
}
// VolumeParamsResults holds provisioning parameters for multiple volumes.
type VolumeParamsResults struct {
Results []VolumeParamsResult `json:"results,omitempty"`
}
// VolumeAttachmentParamsResults holds provisioning parameters for a volume
// attachment.
type VolumeAttachmentParamsResult struct {
Result VolumeAttachmentParams `json:"result"`
Error *Error `json:"error,omitempty"`
}
// VolumeAttachmentParamsResults holds provisioning parameters for multiple
// volume attachments.
type VolumeAttachmentParamsResults struct {
Results []VolumeAttachmentParamsResult `json:"results,omitempty"`
}
// Filesystem identifies and describes a storage filesystem in the model.
type Filesystem struct {
FilesystemTag string `json:"filesystem-tag"`
VolumeTag string `json:"volume-tag,omitempty"`
Info FilesystemInfo `json:"info"`
}
// Filesystem describes a storage filesystem in the model.
type FilesystemInfo struct {
FilesystemId string `json:"filesystem-id"`
// Size is the size of the filesystem in MiB.
Size uint64 `json:"size"`
}
// Filesystems describes a set of storage filesystems in the model.
type Filesystems struct {
Filesystems []Filesystem `json:"filesystems"`
}
// FilesystemAttachment identifies and describes a filesystem attachment.
type FilesystemAttachment struct {
FilesystemTag string `json:"filesystem-tag"`
MachineTag string `json:"machine-tag"`
Info FilesystemAttachmentInfo `json:"info"`
}
// FilesystemAttachmentInfo describes a filesystem attachment.
type FilesystemAttachmentInfo struct {
MountPoint string `json:"mount-point,omitempty"`
ReadOnly bool `json:"read-only,omitempty"`
}
// FilesystemAttachments describes a set of storage filesystem attachments.
type FilesystemAttachments struct {
FilesystemAttachments []FilesystemAttachment `json:"filesystem-attachments"`
}
// FilesystemParams holds the parameters for creating a storage filesystem.
type FilesystemParams struct {
FilesystemTag string `json:"filesystem-tag"`
VolumeTag string `json:"volume-tag,omitempty"`
Size uint64 `json:"size"`
Provider string `json:"provider"`
Attributes map[string]interface{} `json:"attributes,omitempty"`
Tags map[string]string `json:"tags,omitempty"`
Attachment *FilesystemAttachmentParams `json:"attachment,omitempty"`
}
// FilesystemAttachmentParams holds the parameters for creating a filesystem
// attachment.
type FilesystemAttachmentParams struct {
FilesystemTag string `json:"filesystem-tag"`
MachineTag string `json:"machine-tag"`
FilesystemId string `json:"filesystem-id,omitempty"`
InstanceId string `json:"instance-id,omitempty"`
Provider string `json:"provider"`
MountPoint string `json:"mount-point,omitempty"`
ReadOnly bool `json:"read-only,omitempty"`
}
// FilesystemAttachmentResult holds the details of a single filesystem attachment,
// or an error.
type FilesystemAttachmentResult struct {
Result FilesystemAttachment `json:"result"`
Error *Error `json:"error,omitempty"`
}
// FilesystemAttachmentResults holds a set of FilesystemAttachmentResults.
type FilesystemAttachmentResults struct {
Results []FilesystemAttachmentResult `json:"results,omitempty"`
}
// FilesystemResult holds information about a filesystem.
type FilesystemResult struct {
Result Filesystem `json:"result"`
Error *Error `json:"error,omitempty"`
}
// FilesystemResults holds information about multiple filesystems.
type FilesystemResults struct {
Results []FilesystemResult `json:"results,omitempty"`
}
// FilesystemParamsResults holds provisioning parameters for a filesystem.
type FilesystemParamsResult struct {
Result FilesystemParams `json:"result"`
Error *Error `json:"error,omitempty"`
}
// FilesystemParamsResults holds provisioning parameters for multiple filesystems.
type FilesystemParamsResults struct {
Results []FilesystemParamsResult `json:"results,omitempty"`
}
// FilesystemAttachmentParamsResults holds provisioning parameters for a filesystem
// attachment.
type FilesystemAttachmentParamsResult struct {
Result FilesystemAttachmentParams `json:"result"`
Error *Error `json:"error,omitempty"`
}
// FilesystemAttachmentParamsResults holds provisioning parameters for multiple
// filesystem attachments.
type FilesystemAttachmentParamsResults struct {
Results []FilesystemAttachmentParamsResult `json:"results,omitempty"`
}
// StorageDetails holds information about storage.
type StorageDetails struct {
// StorageTag holds tag for this storage.
StorageTag string `json:"storage-tag"`
// OwnerTag holds tag for the owner of this storage, unit or application.
OwnerTag string `json:"owner-tag"`
// Kind holds what kind of storage this instance is.
Kind StorageKind `json:"kind"`
// Status contains the status of the storage instance.
Status EntityStatus `json:"status"`
// Persistent reports whether or not the underlying volume or
// filesystem is persistent; i.e. whether or not it outlives
// the machine that it is attached to.
Persistent bool `json:"persistent"`
// Attachments contains a mapping from unit tag to
// storage attachment details.
Attachments map[string]StorageAttachmentDetails `json:"attachments,omitempty"`
}
// StorageFilter holds filter terms for listing storage details.
type StorageFilter struct {
// We don't currently implement any filters. This exists to get the
// API structure right, and so we can add filters later as necessary.
}
// StorageFilters holds a set of storage filters.
type StorageFilters struct {
Filters []StorageFilter `json:"filters,omitempty"`
}
// StorageDetailsResult holds information about a storage instance
// or error related to its retrieval.
type StorageDetailsResult struct {
Result *StorageDetails `json:"result,omitempty"`
Error *Error `json:"error,omitempty"`
}
// StorageDetailsResults holds results for storage details or related storage error.
type StorageDetailsResults struct {
Results []StorageDetailsResult `json:"results,omitempty"`
}
// StorageDetailsListResult holds a collection of storage details.
type StorageDetailsListResult struct {
Result []StorageDetails `json:"result,omitempty"`
Error *Error `json:"error,omitempty"`
}
// StorageDetailsListResults holds a collection of collections of storage details.
type StorageDetailsListResults struct {
Results []StorageDetailsListResult `json:"results,omitempty"`
}
// StorageAttachmentDetails holds detailed information about a storage attachment.
type StorageAttachmentDetails struct {
// StorageTag is the tag of the storage instance.
StorageTag string `json:"storage-tag"`
// UnitTag is the tag of the unit attached to the storage instance.
UnitTag string `json:"unit-tag"`
// MachineTag is the tag of the machine that the attached unit is assigned to.
MachineTag string `json:"machine-tag"`
// Location holds location (mount point/device path) of
// the attached storage.
Location string `json:"location,omitempty"`
}
// StoragePool holds data for a pool instance.
type StoragePool struct {
// Name is the pool's name.
Name string `json:"name"`
// Provider is the type of storage provider this pool represents, eg "loop", "ebs".
Provider string `json:"provider"`
// Attrs are the pool's configuration attributes.
Attrs map[string]interface{} `json:"attrs"`
}
// StoragePoolFilter holds a filter for matching storage pools.
type StoragePoolFilter struct {
// Names are pool's names to filter on.
Names []string `json:"names,omitempty"`
// Providers are pool's storage provider types to filter on.
Providers []string `json:"providers,omitempty"`
}
// StoragePoolFilters holds a collection of storage pool filters.
type StoragePoolFilters struct {
Filters []StoragePoolFilter `json:"filters,omitempty"`
}
// StoragePoolsResult holds a collection of storage pools.
type StoragePoolsResult struct {
Result []StoragePool `json:"storage-pools,omitempty"`
Error *Error `json:"error,omitempty"`
}
// StoragePoolsResults holds a collection of storage pools results.
type StoragePoolsResults struct {
Results []StoragePoolsResult `json:"results,omitempty"`
}
// VolumeFilter holds a filter for volume list API call.
type VolumeFilter struct {
// Machines are machine tags to filter on.
Machines []string `json:"machines,omitempty"`
}
// IsEmpty determines if filter is empty
func (f *VolumeFilter) IsEmpty() bool {
return len(f.Machines) == 0
}
// VolumeFilters holds a collection of volume filters.
type VolumeFilters struct {
Filters []VolumeFilter `json:"filters,omitempty"`
}
// FilesystemFilter holds a filter for filter list API call.
type FilesystemFilter struct {
// Machines are machine tags to filter on.
Machines []string `json:"machines,omitempty"`
}
// IsEmpty determines if filter is empty
func (f *FilesystemFilter) IsEmpty() bool {
return len(f.Machines) == 0
}
// FilesystemFilters holds a collection of filesystem filters.
type FilesystemFilters struct {
Filters []FilesystemFilter `json:"filters,omitempty"`
}
// VolumeDetails describes a storage volume in the model
// for the purpose of volume CLI commands.
//
// This is kept separate from Volume which contains only information
// specific to the volume model, whereas VolumeDetails is intended
// to contain complete information about a volume and related
// information (status, attachments, storage).
type VolumeDetails struct {
// VolumeTag is the tag for the volume.
VolumeTag string `json:"volume-tag"`
// Info contains information about the volume.
Info VolumeInfo `json:"info"`
// Status contains the status of the volume.
Status EntityStatus `json:"status"`
// MachineAttachments contains a mapping from
// machine tag to volume attachment information.
MachineAttachments map[string]VolumeAttachmentInfo `json:"machine-attachments,omitempty"`
// Storage contains details about the storage instance
// that the volume is assigned to, if any.
Storage *StorageDetails `json:"storage,omitempty"`
}
// VolumeDetailsResult contains details about a volume, its attachments or
// an error preventing retrieving those details.
type VolumeDetailsResult struct {
// Result describes the volume in detail.
Result *VolumeDetails `json:"details,omitempty"`
// Error contains volume retrieval error.
Error *Error `json:"error,omitempty"`
}
// VolumeDetailsResults holds volume details.
type VolumeDetailsResults struct {
Results []VolumeDetailsResult `json:"results,omitempty"`
}
// VolumeDetailsListResult holds a collection of volume details.
type VolumeDetailsListResult struct {
Result []VolumeDetails `json:"result,omitempty"`
Error *Error `json:"error,omitempty"`
}
// VolumeDetailsListResults holds a collection of collections of volume details.
type VolumeDetailsListResults struct {
Results []VolumeDetailsListResult `json:"results,omitempty"`
}
// FilesystemDetails describes a storage filesystem in the model
// for the purpose of filesystem CLI commands.
//
// This is kept separate from Filesystem which contains only information
// specific to the filesystem model, whereas FilesystemDetails is intended
// to contain complete information about a filesystem and related
// information (status, attachments, storage).
type FilesystemDetails struct {
// FilesystemTag is the tag for the filesystem.
FilesystemTag string `json:"filesystem-tag"`
// VolumeTag is the tag for the volume backing the
// filesystem, if any.
VolumeTag string `json:"volume-tag,omitempty"`
// Info contains information about the filesystem.
Info FilesystemInfo `json:"info"`
// Status contains the status of the filesystem.
Status EntityStatus `json:"status"`
// MachineAttachments contains a mapping from
// machine tag to filesystem attachment information.
MachineAttachments map[string]FilesystemAttachmentInfo `json:"machine-attachments,omitempty"`
// Storage contains details about the storage instance
// that the volume is assigned to, if any.
Storage *StorageDetails `json:"storage,omitempty"`
}
// FilesystemDetailsResult contains details about a filesystem, its attachments or
// an error preventing retrieving those details.
type FilesystemDetailsResult struct {
Result *FilesystemDetails `json:"result,omitempty"`
Error *Error `json:"error,omitempty"`
}
// FilesystemDetailsResults holds filesystem details.
type FilesystemDetailsResults struct {
Results []FilesystemDetailsResult `json:"results,omitempty"`
}
// FilesystemDetailsListResult holds a collection of filesystem details.
type FilesystemDetailsListResult struct {
Result []FilesystemDetails `json:"result,omitempty"`
Error *Error `json:"error,omitempty"`
}
// FilesystemDetailsListResults holds a collection of collections of
// filesystem details.
type FilesystemDetailsListResults struct {
Results []FilesystemDetailsListResult `json:"results,omitempty"`
}
// StorageConstraints contains constraints for storage instance.
type StorageConstraints struct {
// Pool is the name of the storage pool from which to provision the
// storage instance.
Pool string `json:"pool,omitempty"`
// Size is the required size of the storage instance, in MiB.
Size *uint64 `json:"size,omitempty"`
// Count is the required number of storage instances.
Count *uint64 `json:"count,omitempty"`
}
// StorageAddParams holds storage details to add to a unit dynamically.
type StorageAddParams struct {
// UnitTag is unit name.
UnitTag string `json:"unit"`
// StorageName is the name of the storage as specified in the charm.
StorageName string `json:"name"`
// Constraints are specified storage constraints.
Constraints StorageConstraints `json:"storage"`
}
// StoragesAddParams holds storage details to add to units dynamically.
type StoragesAddParams struct {
Storages []StorageAddParams `json:"storages"`
}