-
Notifications
You must be signed in to change notification settings - Fork 23
/
model.go
1976 lines (1722 loc) · 57 KB
/
model.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
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2016 Canonical Ltd.
// Licensed under the LGPLv3, see LICENCE file for details.
package description
import (
"fmt"
"net"
"sort"
"strings"
"time"
"github.com/juju/collections/set"
"github.com/juju/errors"
"github.com/juju/names/v5"
"github.com/juju/schema"
"github.com/juju/version/v2"
"gopkg.in/yaml.v2"
)
const (
// IAAS is the type for IAAS models.
IAAS = "iaas"
// CAAS is the type for CAAS models.
CAAS = "caas"
)
// Model is a database agnostic representation of an existing model.
type Model interface {
HasAnnotations
HasConstraints
HasStatus
HasStatusHistory
// AgentVersion returns the version currently in use by the model.
AgentVersion() string
Type() string
Cloud() string
CloudRegion() string
CloudCredential() CloudCredential
SetCloudCredential(CloudCredentialArgs)
Tag() names.ModelTag
Owner() names.UserTag
Config() map[string]interface{}
LatestToolsVersion() version.Number
EnvironVersion() int
// UpdateConfig overwrites existing config values with those specified.
UpdateConfig(map[string]interface{})
// Blocks returns a map of block type to the message associated with that
// block.
Blocks() map[string]string
Users() []User
AddUser(UserArgs)
Machines() []Machine
AddMachine(MachineArgs) Machine
Applications() []Application
AddApplication(ApplicationArgs) Application
Relations() []Relation
AddRelation(RelationArgs) Relation
RemoteEntities() []RemoteEntity
AddRemoteEntity(RemoteEntityArgs) RemoteEntity
RelationNetworks() []RelationNetwork
AddRelationNetwork(RelationNetworkArgs) RelationNetwork
Spaces() []Space
AddSpace(SpaceArgs) Space
LinkLayerDevices() []LinkLayerDevice
AddLinkLayerDevice(LinkLayerDeviceArgs) LinkLayerDevice
Subnets() []Subnet
AddSubnet(SubnetArgs) Subnet
IPAddresses() []IPAddress
AddIPAddress(IPAddressArgs) IPAddress
SSHHostKeys() []SSHHostKey
AddSSHHostKey(SSHHostKeyArgs) SSHHostKey
CloudImageMetadata() []CloudImageMetadata
AddCloudImageMetadata(CloudImageMetadataArgs) CloudImageMetadata
Actions() []Action
AddAction(ActionArgs) Action
Operations() []Operation
AddOperation(OperationArgs) Operation
Sequences() map[string]int
SetSequence(name string, value int)
Volumes() []Volume
AddVolume(VolumeArgs) Volume
FirewallRules() []FirewallRule
AddFirewallRule(FirewallRuleArgs) FirewallRule
Filesystems() []Filesystem
AddFilesystem(FilesystemArgs) Filesystem
Storages() []Storage
AddStorage(StorageArgs) Storage
StoragePools() []StoragePool
AddStoragePool(StoragePoolArgs) StoragePool
SecretBackendID() string
Secrets() []Secret
AddSecret(args SecretArgs) Secret
RemoteSecrets() []RemoteSecret
AddRemoteSecret(args RemoteSecretArgs) RemoteSecret
RemoteApplications() []RemoteApplication
AddRemoteApplication(RemoteApplicationArgs) RemoteApplication
OfferConnections() []OfferConnection
AddOfferConnection(OfferConnectionArgs) OfferConnection
ExternalControllers() []ExternalController
AddExternalController(ExternalControllerArgs) ExternalController
Validate() error
SetSLA(level, owner, credentials string) SLA
SLA() SLA
SetMeterStatus(code, info string) MeterStatus
MeterStatus() MeterStatus
PasswordHash() string
AddBlockDevice(string, BlockDeviceArgs) error
}
// ModelArgs represent the bare minimum information that is needed
// to represent a model.
type ModelArgs struct {
// AgentVersion defines the current version in use by the model.
AgentVersion string
Type string
Owner names.UserTag
Config map[string]interface{}
LatestToolsVersion version.Number
EnvironVersion int
Blocks map[string]string
Cloud string
CloudRegion string
PasswordHash string
SecretBackendID string
}
// NewModel returns a Model based on the args specified.
func NewModel(args ModelArgs) Model {
m := &model{
Version: 11,
AgentVersion_: args.AgentVersion,
Type_: args.Type,
Owner_: args.Owner.Id(),
Config_: args.Config,
LatestToolsVersion_: args.LatestToolsVersion,
EnvironVersion_: args.EnvironVersion,
Sequences_: make(map[string]int),
Blocks_: args.Blocks,
Cloud_: args.Cloud,
CloudRegion_: args.CloudRegion,
PasswordHash_: args.PasswordHash,
SecretBackendID_: args.SecretBackendID,
StatusHistory_: newStatusHistory(),
}
m.setUsers(nil)
m.setMachines(nil)
m.setApplications(nil)
m.setRelations(nil)
m.setRemoteEntities(nil)
m.setRelationNetworks(nil)
m.setSpaces(nil)
m.setLinkLayerDevices(nil)
m.setSubnets(nil)
m.setIPAddresses(nil)
m.setSSHHostKeys(nil)
m.setCloudImageMetadatas(nil)
m.setActions(nil)
m.setOperations(nil)
m.setVolumes(nil)
m.setFilesystems(nil)
m.setStorages(nil)
m.setStoragePools(nil)
m.setSecrets(nil)
m.setRemoteSecrets(nil)
m.setRemoteApplications(nil)
m.setFirewallRules(nil)
m.setOfferConnections(nil)
m.setExternalControllers(nil)
return m
}
// Serialize mirrors the Deserialize method, and makes sure that
// the same serialization method is used.
func Serialize(model Model) ([]byte, error) {
return yaml.Marshal(model)
}
// Deserialize constructs a Model from a serialized YAML byte stream. The
// normal use for this is to construct the Model representation after getting
// the byte stream from an API connection or read from a file.
func Deserialize(bytes []byte) (Model, error) {
var source map[string]interface{}
err := yaml.Unmarshal(bytes, &source)
if err != nil {
return nil, errors.Trace(err)
}
model, err := importModel(source)
if err != nil {
return nil, errors.Trace(err)
}
return model, nil
}
// parseLinkLayerDeviceGlobalKey is used to validate that the parent device
// referenced by a LinkLayerDevice exists. Copied from state to avoid exporting
// and will be replaced by device.ParentMachineID() at some point.
func parseLinkLayerDeviceGlobalKey(globalKey string) (machineID, deviceName string, canBeGlobalKey bool) {
if !strings.Contains(globalKey, "#") {
// Can't be a global key.
return "", "", false
}
keyParts := strings.Split(globalKey, "#")
if len(keyParts) != 4 || (keyParts[0] != "m" && keyParts[2] != "d") {
// Invalid global key format.
return "", "", true
}
machineID, deviceName = keyParts[1], keyParts[3]
return machineID, deviceName, true
}
// parentId returns the id of the host machine if machineId a container id, or ""
// if machineId is not for a container.
func parentId(machineId string) string {
idParts := strings.Split(machineId, "/")
if len(idParts) < 3 {
return ""
}
return strings.Join(idParts[:len(idParts)-2], "/")
}
type model struct {
Version int `yaml:"version"`
// AgentVersion_ defines the agent version in use by the model.
AgentVersion_ string `yaml:"agent-version"`
Type_ string `yaml:"type"`
Owner_ string `yaml:"owner"`
Config_ map[string]interface{} `yaml:"config"`
Blocks_ map[string]string `yaml:"blocks,omitempty"`
LatestToolsVersion_ version.Number `yaml:"latest-tools,omitempty"`
EnvironVersion_ int `yaml:"environ-version"`
Users_ users `yaml:"users"`
Machines_ machines `yaml:"machines"`
Applications_ applications `yaml:"applications"`
Relations_ relations `yaml:"relations"`
RemoteEntities_ remoteEntities `yaml:"remote-entities"`
RelationNetworks_ relationNetworks `yaml:"relation-networks"`
OfferConnections_ offerConnections `yaml:"offer-connections"`
ExternalControllers_ externalControllers `yaml:"external-controllers"`
Spaces_ spaces `yaml:"spaces"`
LinkLayerDevices_ linklayerdevices `yaml:"link-layer-devices"`
IPAddresses_ ipaddresses `yaml:"ip-addresses"`
Subnets_ subnets `yaml:"subnets"`
CloudImageMetadata_ cloudimagemetadataset `yaml:"cloud-image-metadata"`
Status_ *status `yaml:"status"`
StatusHistory_ `yaml:"status-history"`
Actions_ actions `yaml:"actions"`
Operations_ operations `yaml:"operations"`
SSHHostKeys_ sshHostKeys `yaml:"ssh-host-keys"`
Sequences_ map[string]int `yaml:"sequences"`
Annotations_ `yaml:"annotations,omitempty"`
Constraints_ *constraints `yaml:"constraints,omitempty"`
Cloud_ string `yaml:"cloud"`
CloudRegion_ string `yaml:"cloud-region,omitempty"`
CloudCredential_ *cloudCredential `yaml:"cloud-credential,omitempty"`
Volumes_ volumes `yaml:"volumes"`
Filesystems_ filesystems `yaml:"filesystems"`
Storages_ storages `yaml:"storages"`
StoragePools_ storagepools `yaml:"storage-pools"`
FirewallRules_ firewallRules `yaml:"firewall-rules"`
RemoteApplications_ remoteApplications `yaml:"remote-applications"`
SecretBackendID_ string `yaml:"secret-backend-id,omitempty"`
Secrets_ secrets `yaml:"secrets"`
RemoteSecrets_ remoteSecrets `yaml:"remote-secrets"`
SLA_ sla `yaml:"sla"`
MeterStatus_ meterStatus `yaml:"meter-status"`
PasswordHash_ string `yaml:"password-hash,omitempty"`
}
// AgentVersion returns the current agent version in use the by the model.
func (m *model) AgentVersion() string {
return m.AgentVersion_
}
func (m *model) Type() string {
return m.Type_
}
func (m *model) Tag() names.ModelTag {
// Here we make the assumption that the model UUID is set
// correctly in the Config.
value := m.Config_["uuid"]
// Explicitly ignore the 'ok' aspect of the cast. If we don't have it
// and it is wrong, we panic. Here we fully expect it to exist, but
// paranoia says 'never panic', so worst case is we have an empty string.
uuid, _ := value.(string)
return names.NewModelTag(uuid)
}
// Owner implements Model.
func (m *model) Owner() names.UserTag {
return names.NewUserTag(m.Owner_)
}
// Config implements Model.
func (m *model) Config() map[string]interface{} {
// TODO: consider returning a deep copy.
return m.Config_
}
// UpdateConfig implements Model.
func (m *model) UpdateConfig(config map[string]interface{}) {
for key, value := range config {
m.Config_[key] = value
}
}
// PasswordHash implements Model.
func (m *model) PasswordHash() string {
return m.PasswordHash_
}
// LatestToolsVersion implements Model.
func (m *model) LatestToolsVersion() version.Number {
return m.LatestToolsVersion_
}
// EnvironVersion implements Model.
func (m *model) EnvironVersion() int {
return m.EnvironVersion_
}
// Blocks implements Model.
func (m *model) Blocks() map[string]string {
return m.Blocks_
}
// ByName is a sorting implementation over the UserTag lexicographically, which
// aligns to sort.Interface
type ByName []User
func (a ByName) Len() int { return len(a) }
func (a ByName) Less(i, j int) bool { return a[i].Name().Id() < a[j].Name().Id() }
func (a ByName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
// Users implements Model.
func (m *model) Users() []User {
var result []User
for _, user := range m.Users_.Users_ {
result = append(result, user)
}
sort.Sort(ByName(result))
return result
}
// AddUser implements Model.
func (m *model) AddUser(args UserArgs) {
m.Users_.Users_ = append(m.Users_.Users_, newUser(args))
}
func (m *model) setUsers(userList []*user) {
m.Users_ = users{
Version: 1,
Users_: userList,
}
}
// Status implements Model.
func (m *model) Status() Status {
// To avoid typed nils check nil here.
if m.Status_ == nil {
return nil
}
return m.Status_
}
// SetStatus implements Model.
func (m *model) SetStatus(args StatusArgs) {
m.Status_ = newStatus(args)
}
// Machines implements Model.
func (m *model) Machines() []Machine {
var result []Machine
for _, machine := range m.Machines_.Machines_ {
result = append(result, machine)
}
return result
}
// AddMachine implements Model.
func (m *model) AddMachine(args MachineArgs) Machine {
machine := newMachine(args)
m.Machines_.Machines_ = append(m.Machines_.Machines_, machine)
return machine
}
func (m *model) setMachines(machineList []*machine) {
m.Machines_ = machines{
Version: 3,
Machines_: machineList,
}
}
// AddBlockDevice adds a block device for the specified machine.
func (m *model) AddBlockDevice(machineId string, bdArgs BlockDeviceArgs) error {
for i := range m.Machines_.Machines_ {
if m.Machines_.Machines_[i].Id_ != machineId {
continue
}
m.Machines_.Machines_[i].AddBlockDevice(bdArgs)
return nil
}
return fmt.Errorf("machine %q %w", machineId, errors.NotFound)
}
// Applications implements Model.
func (m *model) Applications() []Application {
var result []Application
for _, application := range m.Applications_.Applications_ {
result = append(result, application)
}
return result
}
func (m *model) application(name string) *application {
for _, application := range m.Applications_.Applications_ {
if application.Name() == name {
return application
}
}
return nil
}
// AddApplication implements Model.
func (m *model) AddApplication(args ApplicationArgs) Application {
application := newApplication(args)
m.Applications_.Applications_ = append(m.Applications_.Applications_, application)
return application
}
func (m *model) setApplications(applicationList []*application) {
m.Applications_ = applications{
Version: 13,
Applications_: applicationList,
}
}
// Relations implements Model.
func (m *model) Relations() []Relation {
var result []Relation
for _, relation := range m.Relations_.Relations_ {
result = append(result, relation)
}
return result
}
// AddRelation implements Model.
func (m *model) AddRelation(args RelationArgs) Relation {
relation := newRelation(args)
m.Relations_.Relations_ = append(m.Relations_.Relations_, relation)
return relation
}
func (m *model) setRelations(relationList []*relation) {
m.Relations_ = relations{
Version: 3,
Relations_: relationList,
}
}
// RemoteEntities implements Model.
func (m *model) RemoteEntities() []RemoteEntity {
var result []RemoteEntity
for _, remoteEntity := range m.RemoteEntities_.RemoteEntities {
result = append(result, remoteEntity)
}
return result
}
// AddRemoteEntity implements Model.
func (m *model) AddRemoteEntity(args RemoteEntityArgs) RemoteEntity {
remoteEntity := newRemoteEntity(args)
m.RemoteEntities_.RemoteEntities = append(m.RemoteEntities_.RemoteEntities, remoteEntity)
return remoteEntity
}
func (m *model) setRemoteEntities(remoteEntityList []*remoteEntity) {
m.RemoteEntities_ = remoteEntities{
Version: 1,
RemoteEntities: remoteEntityList,
}
}
// RelationNetworks implements Model.
func (m *model) RelationNetworks() []RelationNetwork {
result := make([]RelationNetwork, len(m.RelationNetworks_.RelationNetworks))
for i, rn := range m.RelationNetworks_.RelationNetworks {
result[i] = rn
}
return result
}
// AddRelationNetwork implements Model.
func (m *model) AddRelationNetwork(args RelationNetworkArgs) RelationNetwork {
network := newRelationNetwork(args)
m.RelationNetworks_.RelationNetworks = append(m.RelationNetworks_.RelationNetworks, network)
return network
}
func (m *model) setRelationNetworks(relationNetworkList []*relationNetwork) {
m.RelationNetworks_ = relationNetworks{
Version: 1,
RelationNetworks: relationNetworkList,
}
}
// Spaces implements Model.
func (m *model) Spaces() []Space {
var result []Space
for _, space := range m.Spaces_.Spaces_ {
result = append(result, space)
}
return result
}
// AddSpace implements Model.
func (m *model) AddSpace(args SpaceArgs) Space {
space := newSpace(args)
m.Spaces_.Spaces_ = append(m.Spaces_.Spaces_, space)
return space
}
func (m *model) setSpaces(spaceList []*space) {
m.Spaces_ = spaces{
Version: 2,
Spaces_: spaceList,
}
}
// LinkLayerDevices implements Model.
func (m *model) LinkLayerDevices() []LinkLayerDevice {
var result []LinkLayerDevice
for _, device := range m.LinkLayerDevices_.LinkLayerDevices_ {
result = append(result, device)
}
return result
}
// AddLinkLayerDevice implements Model.
func (m *model) AddLinkLayerDevice(args LinkLayerDeviceArgs) LinkLayerDevice {
device := newLinkLayerDevice(args)
m.LinkLayerDevices_.LinkLayerDevices_ = append(m.LinkLayerDevices_.LinkLayerDevices_, device)
return device
}
func (m *model) setLinkLayerDevices(devicesList []*linklayerdevice) {
m.LinkLayerDevices_ = linklayerdevices{
Version: 1,
LinkLayerDevices_: devicesList,
}
}
// Subnets implements Model.
func (m *model) Subnets() []Subnet {
var result []Subnet
for _, subnet := range m.Subnets_.Subnets_ {
result = append(result, subnet)
}
return result
}
// AddSubnet implements Model.
func (m *model) AddSubnet(args SubnetArgs) Subnet {
subnet := newSubnet(args)
m.Subnets_.Subnets_ = append(m.Subnets_.Subnets_, subnet)
return subnet
}
func (m *model) setSubnets(subnetList []*subnet) {
m.Subnets_ = subnets{
Version: 6,
Subnets_: subnetList,
}
}
// IPAddresses implements Model.
func (m *model) IPAddresses() []IPAddress {
var result []IPAddress
for _, addr := range m.IPAddresses_.IPAddresses_ {
result = append(result, addr)
}
return result
}
// AddIPAddress implements Model.
func (m *model) AddIPAddress(args IPAddressArgs) IPAddress {
addr := newIPAddress(args)
m.IPAddresses_.IPAddresses_ = append(m.IPAddresses_.IPAddresses_, addr)
return addr
}
func (m *model) setIPAddresses(addressesList []*ipaddress) {
m.IPAddresses_ = ipaddresses{
Version: 5,
IPAddresses_: addressesList,
}
}
// SSHHostKeys implements Model.
func (m *model) SSHHostKeys() []SSHHostKey {
var result []SSHHostKey
for _, addr := range m.SSHHostKeys_.SSHHostKeys_ {
result = append(result, addr)
}
return result
}
// AddSSHHostKey implements Model.
func (m *model) AddSSHHostKey(args SSHHostKeyArgs) SSHHostKey {
addr := newSSHHostKey(args)
m.SSHHostKeys_.SSHHostKeys_ = append(m.SSHHostKeys_.SSHHostKeys_, addr)
return addr
}
func (m *model) setSSHHostKeys(addressesList []*sshHostKey) {
m.SSHHostKeys_ = sshHostKeys{
Version: 1,
SSHHostKeys_: addressesList,
}
}
// CloudImageMetadatas implements Model.
func (m *model) CloudImageMetadata() []CloudImageMetadata {
var result []CloudImageMetadata
for _, addr := range m.CloudImageMetadata_.CloudImageMetadata_ {
result = append(result, addr)
}
return result
}
// Actions implements Model.
func (m *model) Actions() []Action {
var result []Action
for _, addr := range m.Actions_.Actions_ {
result = append(result, addr)
}
return result
}
// Operations implements Model.
func (m *model) Operations() []Operation {
var result []Operation
for _, op := range m.Operations_.Operations_ {
result = append(result, op)
}
return result
}
// AddCloudImageMetadata implements Model.
func (m *model) AddCloudImageMetadata(args CloudImageMetadataArgs) CloudImageMetadata {
md := newCloudImageMetadata(args)
m.CloudImageMetadata_.CloudImageMetadata_ = append(m.CloudImageMetadata_.CloudImageMetadata_, md)
return md
}
func (m *model) setCloudImageMetadatas(cloudimagemetadataList []*cloudimagemetadata) {
m.CloudImageMetadata_ = cloudimagemetadataset{
Version: 2,
CloudImageMetadata_: cloudimagemetadataList,
}
}
// AddAction implements Model.
func (m *model) AddAction(args ActionArgs) Action {
addr := newAction(args)
m.Actions_.Actions_ = append(m.Actions_.Actions_, addr)
return addr
}
func (m *model) setActions(actionsList []*action) {
m.Actions_ = actions{
Version: 4,
Actions_: actionsList,
}
}
// AddOperation implements Model.
func (m *model) AddOperation(args OperationArgs) Operation {
op := newOperation(args)
m.Operations_.Operations_ = append(m.Operations_.Operations_, op)
return op
}
func (m *model) setOperations(operationsList []*operation) {
m.Operations_ = operations{
Version: 2,
Operations_: operationsList,
}
}
// Sequences implements Model.
func (m *model) Sequences() map[string]int {
return m.Sequences_
}
// SetSequence implements Model.
func (m *model) SetSequence(name string, value int) {
m.Sequences_[name] = value
}
// Constraints implements HasConstraints.
func (m *model) Constraints() Constraints {
if m.Constraints_ == nil {
return nil
}
return m.Constraints_
}
// SetConstraints implements HasConstraints.
func (m *model) SetConstraints(args ConstraintsArgs) {
m.Constraints_ = newConstraints(args)
}
// Cloud implements Model.
func (m *model) Cloud() string {
return m.Cloud_
}
// CloudRegion implements Model.
func (m *model) CloudRegion() string {
return m.CloudRegion_
}
// CloudCredential implements Model.
func (m *model) CloudCredential() CloudCredential {
if m.CloudCredential_ == nil {
return nil
}
return m.CloudCredential_
}
// SetCloudCredential implements Model.
func (m *model) SetCloudCredential(args CloudCredentialArgs) {
m.CloudCredential_ = newCloudCredential(args)
}
// SetSLA implements Model.
func (m *model) SetSLA(level, owner, creds string) SLA {
m.SLA_ = sla{
Level_: level,
Owner_: owner,
Credentials_: creds,
}
return m.SLA_
}
// SetMeterStatus implements Model.
func (m *model) SetMeterStatus(code, info string) MeterStatus {
m.MeterStatus_ = meterStatus{
Code_: code,
Info_: info,
}
return m.MeterStatus_
}
// SLA implements Model.
func (m *model) SLA() SLA {
return m.SLA_
}
// MeterStatus implements Model.
func (m *model) MeterStatus() MeterStatus {
return m.MeterStatus_
}
// Volumes implements Model.
func (m *model) Volumes() []Volume {
var result []Volume
for _, volume := range m.Volumes_.Volumes_ {
result = append(result, volume)
}
return result
}
// AddVolume implements Model.
func (m *model) AddVolume(args VolumeArgs) Volume {
volume := newVolume(args)
m.Volumes_.Volumes_ = append(m.Volumes_.Volumes_, volume)
return volume
}
func (m *model) setVolumes(volumeList []*volume) {
m.Volumes_ = volumes{
Version: 1,
Volumes_: volumeList,
}
}
// Filesystems implements Model.
func (m *model) Filesystems() []Filesystem {
var result []Filesystem
for _, filesystem := range m.Filesystems_.Filesystems_ {
result = append(result, filesystem)
}
return result
}
// AddFilesystem implemets Model.
func (m *model) AddFilesystem(args FilesystemArgs) Filesystem {
filesystem := newFilesystem(args)
m.Filesystems_.Filesystems_ = append(m.Filesystems_.Filesystems_, filesystem)
return filesystem
}
func (m *model) setFilesystems(filesystemList []*filesystem) {
m.Filesystems_ = filesystems{
Version: 1,
Filesystems_: filesystemList,
}
}
func (m *model) FirewallRules() []FirewallRule {
var result []FirewallRule
for _, firewallRule := range m.FirewallRules_.FirewallRules {
result = append(result, firewallRule)
}
return result
}
func (m *model) AddFirewallRule(args FirewallRuleArgs) FirewallRule {
firewallRule := newFirewallRule(args)
m.FirewallRules_.FirewallRules = append(m.FirewallRules_.FirewallRules, firewallRule)
return firewallRule
}
func (m *model) setFirewallRules(firewallRulesList []*firewallRule) {
m.FirewallRules_ = firewallRules{
Version: 1,
FirewallRules: firewallRulesList,
}
}
// Storages implements Model.
func (m *model) Storages() []Storage {
var result []Storage
for _, storage := range m.Storages_.Storages_ {
result = append(result, storage)
}
return result
}
// AddStorage implemets Model.
func (m *model) AddStorage(args StorageArgs) Storage {
storage := newStorage(args)
m.Storages_.Storages_ = append(m.Storages_.Storages_, storage)
return storage
}
func (m *model) setStorages(storageList []*storage) {
m.Storages_ = storages{
Version: 3,
Storages_: storageList,
}
}
// StoragePools implements Model.
func (m *model) StoragePools() []StoragePool {
var result []StoragePool
for _, pool := range m.StoragePools_.Pools_ {
result = append(result, pool)
}
return result
}
// AddStoragePool implemets Model.
func (m *model) AddStoragePool(args StoragePoolArgs) StoragePool {
pool := newStoragePool(args)
m.StoragePools_.Pools_ = append(m.StoragePools_.Pools_, pool)
return pool
}
func (m *model) setStoragePools(poolList []*storagepool) {
m.StoragePools_ = storagepools{
Version: 1,
Pools_: poolList,
}
}
// SecretBackendID implements Model.
func (m *model) SecretBackendID() string {
return m.SecretBackendID_
}
// Secrets implements Model.
func (m *model) Secrets() []Secret {
var result []Secret
for _, secret := range m.Secrets_.Secrets_ {
result = append(result, secret)
}
return result
}
// AddSecret implements Model.
func (m *model) AddSecret(args SecretArgs) Secret {
secret := newSecret(args)
m.Secrets_.Secrets_ = append(m.Secrets_.Secrets_, secret)
return secret
}
func (m *model) setSecrets(secretList []*secret) {
m.Secrets_ = secrets{
Version: 2,
Secrets_: secretList,
}
}
// RemoteSecrets implements Model.
func (m *model) RemoteSecrets() []RemoteSecret {
var result []RemoteSecret
for _, remoteSecret := range m.RemoteSecrets_.RemoteSecrets_ {
result = append(result, remoteSecret)
}
return result
}
// AddRemoteSecret implements Model.
func (m *model) AddRemoteSecret(args RemoteSecretArgs) RemoteSecret {
remoteSecret := newRemoteSecret(args)
m.RemoteSecrets_.RemoteSecrets_ = append(m.RemoteSecrets_.RemoteSecrets_, remoteSecret)
return remoteSecret
}
func (m *model) setRemoteSecrets(remoteSecretsList []*remoteSecret) {
m.RemoteSecrets_ = remoteSecrets{
Version: 1,
RemoteSecrets_: remoteSecretsList,
}
}
// RemoteApplications implements Model.
func (m *model) RemoteApplications() []RemoteApplication {
var result []RemoteApplication
for _, app := range m.RemoteApplications_.RemoteApplications {
result = append(result, app)
}
return result
}
func (m *model) remoteApplication(name string) *remoteApplication {
for _, remoteApp := range m.RemoteApplications_.RemoteApplications {
if remoteApp.Name() == name {
return remoteApp