This repository has been archived by the owner on Jul 11, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcloudconfig_manifest_primatives.go
105 lines (89 loc) · 2.37 KB
/
cloudconfig_manifest_primatives.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
package enaml
import (
"github.com/xchapter7x/lo"
"gopkg.in/yaml.v2"
)
type CloudConfigManifest struct {
AZs []AZ `yaml:"azs,omitempty"`
VMTypes []VMType `yaml:"vm_types,omitempty"`
DiskTypes []DiskType `yaml:"disk_types,omitempty"`
Networks []DeploymentNetwork `yaml:"networks,omitempty"`
Compilation *Compilation `yaml:"compilation,omitempty"`
}
//NewCloudConfigManifest - initialize a cloudconfigmanifest object with a []byte
func NewCloudConfigManifest(b []byte) *CloudConfigManifest {
cm := new(CloudConfigManifest)
yaml.Unmarshal(b, cm)
return cm
}
func (s *CloudConfigManifest) Bytes() (b []byte, err error) {
if b, err = yaml.Marshal(s); err != nil {
lo.G.Error("error grabbing cloud config manifest bytes: ", err)
b = nil
}
return
}
func (s *CloudConfigManifest) GetManifest() CloudConfigManifest {
return *s
}
//ContainsAZName -
func (s *CloudConfigManifest) ContainsAZName(azName string) (result bool) {
result = false
for _, az := range s.AZs {
if az.Name == azName {
result = true
return
}
}
return
}
//ContainsVMType -
func (s *CloudConfigManifest) ContainsVMType(vmTypeName string) (result bool) {
result = false
for _, vmType := range s.VMTypes {
if vmType.Name == vmTypeName {
result = true
return
}
}
return
}
//ContainsDiskType -
func (s *CloudConfigManifest) ContainsDiskType(diskTypeName string) (result bool) {
result = false
for _, diskType := range s.DiskTypes {
if diskType.Name == diskTypeName {
result = true
return
}
}
return
}
type VMType struct {
Name string `yaml:"name,omitempty"`
CloudProperties interface{} `yaml:"cloud_properties,omitempty"`
}
type AZ struct {
Name string `yaml:"name,omitempty"`
CloudProperties interface{} `yaml:"cloud_properties,omitempty"`
}
func (s *CloudConfigManifest) AddAZ(az AZ) (err error) {
s.AZs = append(s.AZs, az)
return
}
func (s *CloudConfigManifest) AddVMType(vmt VMType) (err error) {
s.VMTypes = append(s.VMTypes, vmt)
return
}
func (s *CloudConfigManifest) AddDiskType(dskt DiskType) (err error) {
s.DiskTypes = append(s.DiskTypes, dskt)
return
}
func (s *CloudConfigManifest) AddNetwork(ntw DeploymentNetwork) (err error) {
s.Networks = append(s.Networks, ntw)
return
}
func (s *CloudConfigManifest) SetCompilation(cpl *Compilation) (err error) {
s.Compilation = cpl
return
}