This repository has been archived by the owner on Jan 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
converterfromapi.go
329 lines (306 loc) · 12.4 KB
/
converterfromapi.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
package api
import (
"fmt"
"github.com/blang/semver"
"github.com/Azure/dcos-engine/pkg/api/vlabs"
)
///////////////////////////////////////////////////////////
// The converter exposes functions to convert the top level
// ContainerService resource
//
// All other functions are internal helper functions used
// for converting.
///////////////////////////////////////////////////////////
// ConvertContainerServiceToVLabs converts an unversioned ContainerService to a vlabs ContainerService
func ConvertContainerServiceToVLabs(api *ContainerService) *vlabs.ContainerService {
vlabsCS := &vlabs.ContainerService{}
vlabsCS.ID = api.ID
vlabsCS.Location = api.Location
vlabsCS.Name = api.Name
if api.Plan != nil {
vlabsCS.Plan = &vlabs.ResourcePurchasePlan{}
convertResourcePurchasePlanToVLabs(api.Plan, vlabsCS.Plan)
}
vlabsCS.Tags = map[string]string{}
for k, v := range api.Tags {
vlabsCS.Tags[k] = v
}
vlabsCS.Type = api.Type
vlabsCS.Properties = &vlabs.Properties{}
convertPropertiesToVLabs(api.Properties, vlabsCS.Properties)
return vlabsCS
}
// ConvertOrchestratorVersionProfileToVLabs converts an unversioned OrchestratorVersionProfile to a vlabs OrchestratorVersionProfile
func ConvertOrchestratorVersionProfileToVLabs(api *OrchestratorVersionProfile) *vlabs.OrchestratorVersionProfile {
vlabsProfile := &vlabs.OrchestratorVersionProfile{}
switch api.OrchestratorType {
case DCOS:
vlabsProfile.OrchestratorType = vlabs.DCOS
}
vlabsProfile.OrchestratorVersion = api.OrchestratorVersion
vlabsProfile.Default = api.Default
if api.Upgrades != nil {
vlabsProfile.Upgrades = make([]string, len(api.Upgrades))
copy(vlabsProfile.Upgrades, api.Upgrades)
}
return vlabsProfile
}
// convertResourcePurchasePlanToVLabs converts a vlabs ResourcePurchasePlan to an unversioned ResourcePurchasePlan
func convertResourcePurchasePlanToVLabs(api *ResourcePurchasePlan, vlabs *vlabs.ResourcePurchasePlan) {
vlabs.Name = api.Name
vlabs.Product = api.Product
vlabs.PromotionCode = api.PromotionCode
vlabs.Publisher = api.Publisher
}
func convertPropertiesToVLabs(api *Properties, vlabsProps *vlabs.Properties) {
vlabsProps.ProvisioningState = vlabs.ProvisioningState(api.ProvisioningState)
if api.OrchestratorProfile != nil {
vlabsProps.OrchestratorProfile = &vlabs.OrchestratorProfile{}
convertOrchestratorProfileToVLabs(api.OrchestratorProfile, vlabsProps.OrchestratorProfile)
}
if api.MasterProfile != nil {
vlabsProps.MasterProfile = &vlabs.MasterProfile{}
convertMasterProfileToVLabs(api.MasterProfile, vlabsProps.MasterProfile)
}
vlabsProps.AgentPoolProfiles = []*vlabs.AgentPoolProfile{}
for _, apiProfile := range api.AgentPoolProfiles {
vlabsProfile := &vlabs.AgentPoolProfile{}
convertAgentPoolProfileToVLabs(apiProfile, vlabsProfile)
vlabsProps.AgentPoolProfiles = append(vlabsProps.AgentPoolProfiles, vlabsProfile)
}
if api.LinuxProfile != nil {
vlabsProps.LinuxProfile = &vlabs.LinuxProfile{}
convertLinuxProfileToVLabs(api.LinuxProfile, vlabsProps.LinuxProfile)
}
vlabsProps.ExtensionProfiles = []*vlabs.ExtensionProfile{}
for _, extensionProfile := range api.ExtensionProfiles {
vlabsExtensionProfile := &vlabs.ExtensionProfile{}
convertExtensionProfileToVLabs(extensionProfile, vlabsExtensionProfile)
vlabsProps.ExtensionProfiles = append(vlabsProps.ExtensionProfiles, vlabsExtensionProfile)
}
if api.WindowsProfile != nil {
vlabsProps.WindowsProfile = &vlabs.WindowsProfile{}
convertWindowsProfileToVLabs(api.WindowsProfile, vlabsProps.WindowsProfile)
}
if api.ServicePrincipalProfile != nil {
vlabsProps.ServicePrincipalProfile = &vlabs.ServicePrincipalProfile{}
convertServicePrincipalProfileToVLabs(api.ServicePrincipalProfile, vlabsProps.ServicePrincipalProfile)
}
}
func convertExtensionProfileToVLabs(api *ExtensionProfile, obj *vlabs.ExtensionProfile) {
obj.Name = api.Name
obj.Version = api.Version
obj.ExtensionParameters = api.ExtensionParameters
if api.ExtensionParametersKeyVaultRef != nil {
obj.ExtensionParametersKeyVaultRef = &vlabs.KeyvaultSecretRef{
VaultID: api.ExtensionParametersKeyVaultRef.VaultID,
SecretName: api.ExtensionParametersKeyVaultRef.SecretName,
SecretVersion: api.ExtensionParametersKeyVaultRef.SecretVersion,
}
}
obj.RootURL = api.RootURL
obj.Script = api.Script
obj.URLQuery = api.URLQuery
}
func convertExtensionToVLabs(api *Extension, vlabs *vlabs.Extension) {
vlabs.Name = api.Name
vlabs.SingleOrAll = api.SingleOrAll
vlabs.Template = api.Template
}
func convertLinuxProfileToVLabs(obj *LinuxProfile, vlabsProfile *vlabs.LinuxProfile) {
vlabsProfile.AdminUsername = obj.AdminUsername
vlabsProfile.SSH.PublicKeys = []vlabs.PublicKey{}
for _, d := range obj.SSH.PublicKeys {
vlabsProfile.SSH.PublicKeys = append(vlabsProfile.SSH.PublicKeys,
vlabs.PublicKey{KeyData: d.KeyData})
}
vlabsProfile.Secrets = []vlabs.KeyVaultSecrets{}
for _, s := range obj.Secrets {
secret := &vlabs.KeyVaultSecrets{}
convertKeyVaultSecretsToVlabs(&s, secret)
vlabsProfile.Secrets = append(vlabsProfile.Secrets, *secret)
}
vlabsProfile.ScriptRootURL = obj.ScriptRootURL
if obj.CustomSearchDomain != nil {
vlabsProfile.CustomSearchDomain = &vlabs.CustomSearchDomain{}
vlabsProfile.CustomSearchDomain.Name = obj.CustomSearchDomain.Name
vlabsProfile.CustomSearchDomain.RealmUser = obj.CustomSearchDomain.RealmUser
vlabsProfile.CustomSearchDomain.RealmPassword = obj.CustomSearchDomain.RealmPassword
}
if obj.CustomNodesDNS != nil {
vlabsProfile.CustomNodesDNS = &vlabs.CustomNodesDNS{}
vlabsProfile.CustomNodesDNS.DNSServer = obj.CustomNodesDNS.DNSServer
}
}
func convertWindowsProfileToVLabs(api *WindowsProfile, vlabsProfile *vlabs.WindowsProfile) {
vlabsProfile.AdminUsername = api.AdminUsername
vlabsProfile.AdminPassword = api.AdminPassword
vlabsProfile.ImageVersion = api.ImageVersion
vlabsProfile.WindowsImageSourceURL = api.WindowsImageSourceURL
vlabsProfile.WindowsPublisher = api.WindowsPublisher
vlabsProfile.WindowsOffer = api.WindowsOffer
vlabsProfile.WindowsSku = api.WindowsSku
vlabsProfile.Secrets = []vlabs.KeyVaultSecrets{}
for _, s := range api.Secrets {
secret := &vlabs.KeyVaultSecrets{}
convertKeyVaultSecretsToVlabs(&s, secret)
vlabsProfile.Secrets = append(vlabsProfile.Secrets, *secret)
}
}
func convertOrchestratorProfileToVLabs(api *OrchestratorProfile, o *vlabs.OrchestratorProfile) {
o.OrchestratorType = api.OrchestratorType
if api.OrchestratorVersion != "" {
o.OrchestratorVersion = api.OrchestratorVersion
sv, _ := semver.Make(o.OrchestratorVersion)
o.OrchestratorRelease = fmt.Sprintf("%d.%d", sv.Major, sv.Minor)
}
o.OAuthEnabled = api.OAuthEnabled
o.OpenAccess = api.OpenAccess
if api.LinuxBootstrapProfile != nil {
o.LinuxBootstrapProfile = &vlabs.BootstrapProfile{
BootstrapURL: api.LinuxBootstrapProfile.BootstrapURL,
DockerVersion: api.LinuxBootstrapProfile.DockerVersion,
Hosted: api.LinuxBootstrapProfile.Hosted,
VMSize: api.LinuxBootstrapProfile.VMSize,
OSDiskSizeGB: api.LinuxBootstrapProfile.OSDiskSizeGB,
StaticIP: api.LinuxBootstrapProfile.StaticIP,
HasPublicIP: api.LinuxBootstrapProfile.HasPublicIP,
Subnet: api.LinuxBootstrapProfile.Subnet,
EnableIPv6: api.LinuxBootstrapProfile.EnableIPv6,
ExtraConfigs: api.LinuxBootstrapProfile.ExtraConfigs,
}
}
if api.WindowsBootstrapProfile != nil {
o.WindowsBootstrapProfile = &vlabs.BootstrapProfile{
BootstrapURL: api.WindowsBootstrapProfile.BootstrapURL,
DockerVersion: api.WindowsBootstrapProfile.DockerVersion,
Hosted: api.WindowsBootstrapProfile.Hosted,
VMSize: api.WindowsBootstrapProfile.VMSize,
OSDiskSizeGB: api.WindowsBootstrapProfile.OSDiskSizeGB,
StaticIP: api.WindowsBootstrapProfile.StaticIP,
HasPublicIP: api.WindowsBootstrapProfile.HasPublicIP,
Subnet: api.WindowsBootstrapProfile.Subnet,
EnableIPv6: api.WindowsBootstrapProfile.EnableIPv6,
ExtraConfigs: api.WindowsBootstrapProfile.ExtraConfigs,
}
}
o.Registry = api.Registry
o.RegistryUser = api.RegistryUser
o.RegistryPass = api.RegistryPass
}
func convertCustomFilesToVlabs(a *MasterProfile, v *vlabs.MasterProfile) {
if a.CustomFiles != nil {
v.CustomFiles = &[]vlabs.CustomFile{}
for i := range *a.CustomFiles {
*v.CustomFiles = append(*v.CustomFiles, vlabs.CustomFile{
Dest: (*a.CustomFiles)[i].Dest,
Source: (*a.CustomFiles)[i].Source,
})
}
}
}
func convertMasterProfileToVLabs(api *MasterProfile, vlabsProfile *vlabs.MasterProfile) {
vlabsProfile.Count = api.Count
vlabsProfile.DNSPrefix = api.DNSPrefix
vlabsProfile.SubjectAltNames = api.SubjectAltNames
vlabsProfile.VMSize = api.VMSize
vlabsProfile.OSDiskSizeGB = api.OSDiskSizeGB
vlabsProfile.VnetSubnetID = api.VnetSubnetID
vlabsProfile.FirstConsecutiveStaticIP = api.FirstConsecutiveStaticIP
vlabsProfile.VnetCidr = api.VnetCidr
vlabsProfile.SetSubnet(api.Subnet)
vlabsProfile.FQDN = api.FQDN
vlabsProfile.StorageProfile = api.StorageProfile
if api.PreprovisionExtension != nil {
vlabsExtension := &vlabs.Extension{}
convertExtensionToVLabs(api.PreprovisionExtension, vlabsExtension)
vlabsProfile.PreProvisionExtension = vlabsExtension
}
if api.PostprovisionExtension != nil {
vlabsExtension := &vlabs.Extension{}
convertExtensionToVLabs(api.PostprovisionExtension, vlabsExtension)
vlabsProfile.PostProvisionExtension = vlabsExtension
}
vlabsProfile.Extensions = []vlabs.Extension{}
for _, extension := range api.Extensions {
vlabsExtension := &vlabs.Extension{}
convertExtensionToVLabs(&extension, vlabsExtension)
vlabsProfile.Extensions = append(vlabsProfile.Extensions, *vlabsExtension)
}
vlabsProfile.Distro = vlabs.Distro(api.Distro)
if api.ImageRef != nil {
vlabsProfile.ImageRef = &vlabs.ImageReference{}
vlabsProfile.ImageRef.Name = api.ImageRef.Name
vlabsProfile.ImageRef.ResourceGroup = api.ImageRef.ResourceGroup
}
convertCustomFilesToVlabs(api, vlabsProfile)
}
func convertKeyVaultSecretsToVlabs(api *KeyVaultSecrets, vlabsSecrets *vlabs.KeyVaultSecrets) {
vlabsSecrets.SourceVault = &vlabs.KeyVaultID{ID: api.SourceVault.ID}
vlabsSecrets.VaultCertificates = []vlabs.KeyVaultCertificate{}
for _, c := range api.VaultCertificates {
cert := vlabs.KeyVaultCertificate{}
cert.CertificateStore = c.CertificateStore
cert.CertificateURL = c.CertificateURL
vlabsSecrets.VaultCertificates = append(vlabsSecrets.VaultCertificates, cert)
}
}
func convertAgentPoolProfileToVLabs(api *AgentPoolProfile, p *vlabs.AgentPoolProfile) {
p.Name = api.Name
p.Count = api.Count
p.VMSize = api.VMSize
p.OSDiskSizeGB = api.OSDiskSizeGB
p.DNSPrefix = api.DNSPrefix
p.OSType = vlabs.OSType(api.OSType)
p.Ports = []int{}
p.Ports = append(p.Ports, api.Ports...)
p.AvailabilityProfile = api.AvailabilityProfile
p.ScaleSetPriority = api.ScaleSetPriority
p.ScaleSetEvictionPolicy = api.ScaleSetEvictionPolicy
p.StorageProfile = api.StorageProfile
p.DiskSizesGB = []int{}
p.DiskSizesGB = append(p.DiskSizesGB, api.DiskSizesGB...)
p.VnetSubnetID = api.VnetSubnetID
p.SetSubnet(api.Subnet)
p.FQDN = api.FQDN
p.CustomNodeLabels = map[string]string{}
p.AcceleratedNetworkingEnabled = api.AcceleratedNetworkingEnabled
for k, v := range api.CustomNodeLabels {
p.CustomNodeLabels[k] = v
}
if api.PreprovisionExtension != nil {
vlabsExtension := &vlabs.Extension{}
convertExtensionToVLabs(api.PreprovisionExtension, vlabsExtension)
p.PreProvisionExtension = vlabsExtension
}
if api.PostprovisionExtension != nil {
vlabsExtension := &vlabs.Extension{}
convertExtensionToVLabs(api.PostprovisionExtension, vlabsExtension)
p.PostProvisionExtension = vlabsExtension
}
p.Extensions = []vlabs.Extension{}
for _, extension := range api.Extensions {
vlabsExtension := &vlabs.Extension{}
convertExtensionToVLabs(&extension, vlabsExtension)
p.Extensions = append(p.Extensions, *vlabsExtension)
}
p.Distro = vlabs.Distro(api.Distro)
if api.ImageRef != nil {
p.ImageRef = &vlabs.ImageReference{}
p.ImageRef.Name = api.ImageRef.Name
p.ImageRef.ResourceGroup = api.ImageRef.ResourceGroup
}
p.Role = vlabs.AgentPoolProfileRole(api.Role)
}
func convertServicePrincipalProfileToVLabs(api *ServicePrincipalProfile, v *vlabs.ServicePrincipalProfile) {
v.ClientID = api.ClientID
v.Secret = api.Secret
v.ObjectID = api.ObjectID
if api.KeyvaultSecretRef != nil {
v.KeyvaultSecretRef = &vlabs.KeyvaultSecretRef{
VaultID: api.KeyvaultSecretRef.VaultID,
SecretName: api.KeyvaultSecretRef.SecretName,
SecretVersion: api.KeyvaultSecretRef.SecretVersion,
}
}
}