forked from hashicorp/terraform-provider-vsphere
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdistributed_virtual_switch_structure.go
635 lines (582 loc) · 24 KB
/
distributed_virtual_switch_structure.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
package vsphere
import (
"fmt"
"strings"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
"github.com/terraform-providers/terraform-provider-vsphere/vsphere/internal/helper/structure"
"github.com/vmware/govmomi/vim25/types"
)
var lacpAPIVersionAllowedValues = []string{
string(types.VMwareDvsLacpApiVersionSingleLag),
string(types.VMwareDvsLacpApiVersionMultipleLag),
}
var multicastFilteringModeAllowedValues = []string{
string(types.VMwareDvsMulticastFilteringModeLegacyFiltering),
string(types.VMwareDvsMulticastFilteringModeSnooping),
}
var privateVLANTypeAllowedValues = []string{
string(types.VmwareDistributedVirtualSwitchPvlanPortTypePromiscuous),
string(types.VmwareDistributedVirtualSwitchPvlanPortTypeIsolated),
string(types.VmwareDistributedVirtualSwitchPvlanPortTypeCommunity),
}
var networkResourceControlAllowedValues = []string{
string(types.DistributedVirtualSwitchNetworkResourceControlVersionVersion2),
string(types.DistributedVirtualSwitchNetworkResourceControlVersionVersion3),
}
var infrastructureTrafficClassValues = []string{
string(types.DistributedVirtualSwitchHostInfrastructureTrafficClassManagement),
string(types.DistributedVirtualSwitchHostInfrastructureTrafficClassFaultTolerance),
string(types.DistributedVirtualSwitchHostInfrastructureTrafficClassVmotion),
string(types.DistributedVirtualSwitchHostInfrastructureTrafficClassVirtualMachine),
string(types.DistributedVirtualSwitchHostInfrastructureTrafficClassISCSI),
string(types.DistributedVirtualSwitchHostInfrastructureTrafficClassNfs),
string(types.DistributedVirtualSwitchHostInfrastructureTrafficClassHbr),
string(types.DistributedVirtualSwitchHostInfrastructureTrafficClassVsan),
string(types.DistributedVirtualSwitchHostInfrastructureTrafficClassVdp),
}
var sharesLevelAllowedValues = []string{
string(types.SharesLevelLow),
string(types.SharesLevelNormal),
string(types.SharesLevelHigh),
string(types.SharesLevelCustom),
}
// schemaVMwareDVSConfigSpec returns schema items for resources that need to work
// with a VMwareDVSConfigSpec.
func schemaVMwareDVSConfigSpec() map[string]*schema.Schema {
s := map[string]*schema.Schema{
// DVSContactInfo
"contact_detail": {
Type: schema.TypeString,
Optional: true,
Description: "The contact detail for this DVS.",
},
"contact_name": {
Type: schema.TypeString,
Optional: true,
Description: "The contact name for this DVS.",
},
// DistributedVirtualSwitchHostMemberConfigSpec
"host": {
Type: schema.TypeSet,
Optional: true,
Description: "A host member specification.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
// DistributedVirtualSwitchHostMemberPnicSpec
"devices": {
Type: schema.TypeList,
Description: "Name of the physical NIC to be added to the proxy switch.",
Required: true,
MinItems: 1,
Elem: &schema.Schema{Type: schema.TypeString},
},
"host_system_id": {
Type: schema.TypeString,
Required: true,
Description: "The managed object ID of the host this specification applies to.",
ValidateFunc: validation.NoZeroValues,
},
},
},
},
// VMwareIpfixConfig (Netflow)
"netflow_active_flow_timeout": {
Type: schema.TypeInt,
Optional: true,
Description: "The number of seconds after which active flows are forced to be exported to the collector.",
Default: 60,
ValidateFunc: validation.IntBetween(60, 3600),
},
"netflow_collector_ip_address": {
Type: schema.TypeString,
Optional: true,
Description: "IP address for the netflow collector, using IPv4 or IPv6. IPv6 is supported in vSphere Distributed Switch Version 6.0 or later.",
},
"netflow_collector_port": {
Type: schema.TypeInt,
Optional: true,
Description: "The port for the netflow collector.",
ValidateFunc: validation.IntBetween(0, 65535),
},
"netflow_idle_flow_timeout": {
Type: schema.TypeInt,
Optional: true,
Description: "The number of seconds after which idle flows are forced to be exported to the collector.",
Default: 15,
ValidateFunc: validation.IntBetween(10, 600),
},
"netflow_internal_flows_only": {
Type: schema.TypeBool,
Optional: true,
Description: "Whether to limit analysis to traffic that has both source and destination served by the same host.",
},
"netflow_observation_domain_id": {
Type: schema.TypeInt,
Optional: true,
Description: "The observation Domain ID for the netflow collector.",
ValidateFunc: validation.IntAtLeast(0),
},
"netflow_sampling_rate": {
Type: schema.TypeInt,
Optional: true,
Description: "The ratio of total number of packets to the number of packets analyzed. Set to 0 to disable sampling, meaning that all packets are analyzed.",
ValidateFunc: validation.IntAtLeast(0),
},
// LinkDiscoveryProtocolConfig
"link_discovery_operation": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Description: "Whether to advertise or listen for link discovery. Valid values are advertise, both, listen, and none.",
Default: string(types.LinkDiscoveryProtocolConfigOperationTypeListen),
ValidateFunc: validation.StringInSlice(linkDiscoveryProtocolConfigOperationAllowedValues, false),
},
"link_discovery_protocol": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Description: "The discovery protocol type. Valid values are cdp and lldp.",
Default: string(types.LinkDiscoveryProtocolConfigProtocolTypeCdp),
ValidateFunc: validation.StringInSlice(linkDiscoveryProtocolConfigProtocolAllowedValues, false),
},
// DVSNameArrayUplinkPortPolicy
"uplinks": &schema.Schema{
Type: schema.TypeList,
Optional: true,
Computed: true,
Description: "A list of uplink ports. The contents of this list control both the uplink count and names of the uplinks on the DVS across hosts.",
Elem: &schema.Schema{Type: schema.TypeString},
},
"name": {
Type: schema.TypeString,
Required: true,
Description: "The name for the DVS. Must be unique in the folder that it is being created in.",
},
"description": {
Type: schema.TypeString,
Optional: true,
Description: "The description of the DVS.",
},
"ipv4_address": {
Type: schema.TypeString,
Optional: true,
Description: "The IPv4 address of the switch. This can be used to see the DVS as a unique device with NetFlow.",
},
"lacp_api_version": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "The Link Aggregation Control Protocol group version in the switch. Can be one of singleLag or multipleLag.",
ValidateFunc: validation.StringInSlice(lacpAPIVersionAllowedValues, false),
},
"max_mtu": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "The maximum MTU on the switch.",
ValidateFunc: validation.IntBetween(1, 9000),
},
"multicast_filtering_mode": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "The multicast filtering mode on the switch. Can be one of legacyFiltering, or snooping.",
ValidateFunc: validation.StringInSlice(multicastFilteringModeAllowedValues, false),
},
"network_resource_control_version": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "The network I/O control version to use. Can be one of version2 or version3.",
ValidateFunc: validation.StringInSlice(networkResourceControlAllowedValues, false),
},
"config_version": {
Type: schema.TypeString,
Computed: true,
Description: "The version string of the configuration that this spec is trying to change.",
},
}
structure.MergeSchema(s, schemaVMwareDVSPortSetting())
structure.MergeSchema(s, schemaDvsHostInfrastructureTrafficResource())
return s
}
// expandDVSContactInfo reads certain ResourceData keys and
// returns a DVSContactInfo.
func expandDVSContactInfo(d *schema.ResourceData) *types.DVSContactInfo {
obj := &types.DVSContactInfo{
Name: d.Get("contact_name").(string),
Contact: d.Get("contact_detail").(string),
}
return obj
}
// flattenDVSContactInfo reads various fields from a
// DVSContactInfo into the passed in ResourceData.
func flattenDVSContactInfo(d *schema.ResourceData, obj types.DVSContactInfo) error {
d.Set("contact_name", obj.Name)
d.Set("conatct_detail", obj.Contact)
return nil
}
// expandDistributedVirtualSwitchHostMemberConfigSpec reads certain keys from a
// Set object map and returns a DistributedVirtualSwitchHostMemberConfigSpec.
func expandDistributedVirtualSwitchHostMemberConfigSpec(d map[string]interface{}) types.DistributedVirtualSwitchHostMemberConfigSpec {
hostRef := &types.ManagedObjectReference{
Type: "HostSystem",
Value: d["host_system_id"].(string),
}
var pnSpecs []types.DistributedVirtualSwitchHostMemberPnicSpec
nics := structure.SliceInterfacesToStrings(d["devices"].([]interface{}))
for _, nic := range nics {
pnSpec := types.DistributedVirtualSwitchHostMemberPnicSpec{
PnicDevice: nic,
}
pnSpecs = append(pnSpecs, pnSpec)
}
backing := types.DistributedVirtualSwitchHostMemberPnicBacking{
PnicSpec: pnSpecs,
}
obj := types.DistributedVirtualSwitchHostMemberConfigSpec{
Host: *hostRef,
Backing: &backing,
}
return obj
}
// flattenDistributedVirtualSwitchHostMemberConfigSpec reads various fields
// from a DistributedVirtualSwitchHostMemberConfigSpec and returns a Set object
// map.
//
// This is the flatten counterpart to
// expandDistributedVirtualSwitchHostMemberConfigSpec.
func flattenDistributedVirtualSwitchHostMember(obj types.DistributedVirtualSwitchHostMember) map[string]interface{} {
d := make(map[string]interface{})
d["host_system_id"] = obj.Config.Host.Value
var devices []string
backing := obj.Config.Backing.(*types.DistributedVirtualSwitchHostMemberPnicBacking)
for _, spec := range backing.PnicSpec {
devices = append(devices, spec.PnicDevice)
}
d["devices"] = devices
return d
}
// expandSliceOfDistributedVirtualSwitchHostMemberConfigSpec expands all host
// entires for a VMware DVS, detecting if a host spec needs to be added,
// removed, or updated as well. The whole slice is returned.
func expandSliceOfDistributedVirtualSwitchHostMemberConfigSpec(d *schema.ResourceData) []types.DistributedVirtualSwitchHostMemberConfigSpec {
var specs []types.DistributedVirtualSwitchHostMemberConfigSpec
o, n := d.GetChange("host")
os := o.(*schema.Set)
ns := n.(*schema.Set)
// Make an intersection set. These hosts have not changed so we don't bother
// with them.
is := os.Intersection(ns)
os = os.Difference(is)
ns = ns.Difference(is)
// Our old and new sets now have an accurate description of hosts that may
// have been added, removed, or changed. Add removed and modified hosts
// first.
for _, oe := range os.List() {
om := oe.(map[string]interface{})
var found bool
for _, ne := range ns.List() {
nm := ne.(map[string]interface{})
if nm["host_system_id"] == om["host_system_id"] {
found = true
}
}
if !found {
spec := expandDistributedVirtualSwitchHostMemberConfigSpec(om)
spec.Operation = string(types.ConfigSpecOperationRemove)
specs = append(specs, spec)
}
}
// Process new hosts now. These are ones that are only present in the new
// set.
for _, ne := range ns.List() {
nm := ne.(map[string]interface{})
var found bool
for _, oe := range os.List() {
om := oe.(map[string]interface{})
if om["host_system_id"] == nm["host_system_id"] {
found = true
}
}
spec := expandDistributedVirtualSwitchHostMemberConfigSpec(nm)
if !found {
spec.Operation = string(types.ConfigSpecOperationAdd)
} else {
spec.Operation = string(types.ConfigSpecOperationEdit)
}
specs = append(specs, spec)
}
// Done!
return specs
}
// flattenSliceOfDistributedVirtualSwitchHostMember creates a set of all host
// entries for a supplied slice of DistributedVirtualSwitchHostMember.
//
// This is the flatten counterpart to
// expandSliceOfDistributedVirtualSwitchHostMemberConfigSpec.
func flattenSliceOfDistributedVirtualSwitchHostMember(d *schema.ResourceData, members []types.DistributedVirtualSwitchHostMember) error {
var hosts []map[string]interface{}
for _, m := range members {
hosts = append(hosts, flattenDistributedVirtualSwitchHostMember(m))
}
if err := d.Set("host", hosts); err != nil {
return err
}
return nil
}
// expandVMwareIpfixConfig reads certain ResourceData keys and
// returns a VMwareIpfixConfig.
func expandVMwareIpfixConfig(d *schema.ResourceData) *types.VMwareIpfixConfig {
obj := &types.VMwareIpfixConfig{
ActiveFlowTimeout: int32(d.Get("netflow_active_flow_timeout").(int)),
CollectorIpAddress: d.Get("netflow_collector_ip_address").(string),
CollectorPort: int32(d.Get("netflow_collector_port").(int)),
IdleFlowTimeout: int32(d.Get("netflow_idle_flow_timeout").(int)),
InternalFlowsOnly: d.Get("netflow_internal_flows_only").(bool),
ObservationDomainId: int64(d.Get("netflow_observation_domain_id").(int)),
SamplingRate: int32(d.Get("netflow_sampling_rate").(int)),
}
return obj
}
// flattenVMwareIpfixConfig reads various fields from a
// VMwareIpfixConfig into the passed in ResourceData.
func flattenVMwareIpfixConfig(d *schema.ResourceData, obj *types.VMwareIpfixConfig) error {
d.Set("netflow_active_flow_timeout", obj.ActiveFlowTimeout)
d.Set("netflow_collector_ip_address", obj.CollectorIpAddress)
d.Set("netflow_collector_port", obj.CollectorPort)
d.Set("netflow_idle_flow_timeout", obj.IdleFlowTimeout)
d.Set("netflow_internal_flows_only", obj.InternalFlowsOnly)
d.Set("netflow_observation_domain_id", obj.ObservationDomainId)
d.Set("netflow_sampling_rate", obj.SamplingRate)
return nil
}
// schemaDvsHostInfrastructureTrafficResource returns the respective schema
// keys for the various kinds of network I/O control traffic classes. The
// schema items are generated dynamically off of the list of available traffic
// classes for the currently supported vSphere API. Not all traffic classes may
// be supported across all DVS and network I/O control versions.
func schemaDvsHostInfrastructureTrafficResource() map[string]*schema.Schema {
s := make(map[string]*schema.Schema)
shareLevelFmt := "The allocation level for the %s traffic class. Can be one of high, low, normal, or custom."
shareCountFmt := "The amount of shares to allocate to the %s traffic class for a custom share level."
maxMbitFmt := "The maximum allowed usage for the %s traffic class, in Mbits/sec."
resMbitFmt := "The amount of guaranteed bandwidth for the %s traffic class, in Mbits/sec."
for _, class := range infrastructureTrafficClassValues {
shareLevelKey := fmt.Sprintf("%s_share_level", strings.ToLower(class))
shareCountKey := fmt.Sprintf("%s_share_count", strings.ToLower(class))
maxMbitKey := fmt.Sprintf("%s_maximum_mbit", strings.ToLower(class))
resMbitKey := fmt.Sprintf("%s_reservation_mbit", strings.ToLower(class))
s[shareLevelKey] = &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: fmt.Sprintf(shareLevelFmt, class),
ValidateFunc: validation.StringInSlice(sharesLevelAllowedValues, false),
}
s[shareCountKey] = &schema.Schema{
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: fmt.Sprintf(shareCountFmt, class),
ValidateFunc: validation.IntAtLeast(0),
}
s[maxMbitKey] = &schema.Schema{
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: fmt.Sprintf(maxMbitFmt, class),
ValidateFunc: validation.IntAtLeast(-1),
}
s[resMbitKey] = &schema.Schema{
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: fmt.Sprintf(resMbitFmt, class),
ValidateFunc: validation.IntAtLeast(-1),
}
}
return s
}
// expandDvsHostInfrastructureTrafficResource reads the network I/O control
// resource data keys for the traffic class supplied by key and returns an
// appropriate types.DvsHostInfrastructureTrafficResource reference. This
// should be checked for nil to see if it should be added to the slice in the
// config.
func expandDvsHostInfrastructureTrafficResource(d *schema.ResourceData, key string) *types.DvsHostInfrastructureTrafficResource {
shareLevelKey := fmt.Sprintf("%s_share_level", strings.ToLower(key))
shareCountKey := fmt.Sprintf("%s_share_count", strings.ToLower(key))
maxMbitKey := fmt.Sprintf("%s_maximum_mbit", strings.ToLower(key))
resMbitKey := fmt.Sprintf("%s_reservation_mbit", strings.ToLower(key))
obj := &types.DvsHostInfrastructureTrafficResource{
AllocationInfo: types.DvsHostInfrastructureTrafficResourceAllocation{
Limit: structure.GetInt64Ptr(d, maxMbitKey),
Reservation: structure.GetInt64Ptr(d, resMbitKey),
},
}
shares := &types.SharesInfo{
Level: types.SharesLevel(d.Get(shareLevelKey).(string)),
Shares: int32(d.Get(shareCountKey).(int)),
}
if !structure.AllFieldsEmpty(shares) {
obj.AllocationInfo.Shares = shares
}
if structure.AllFieldsEmpty(obj) {
return nil
}
obj.Key = key
return obj
}
// flattenDvsHostInfrastructureTrafficResource reads various fields from a
// DvsHostInfrastructureTrafficResource and sets appropriate keys in the
// supplied ResourceData.
func flattenDvsHostInfrastructureTrafficResource(d *schema.ResourceData, obj types.DvsHostInfrastructureTrafficResource, key string) error {
shareLevelKey := fmt.Sprintf("%s_share_level", strings.ToLower(key))
shareCountKey := fmt.Sprintf("%s_share_count", strings.ToLower(key))
maxMbitKey := fmt.Sprintf("%s_maximum_mbit", strings.ToLower(key))
resMbitKey := fmt.Sprintf("%s_reservation_mbit", strings.ToLower(key))
structure.SetInt64Ptr(d, maxMbitKey, obj.AllocationInfo.Limit)
structure.SetInt64Ptr(d, resMbitKey, obj.AllocationInfo.Reservation)
if obj.AllocationInfo.Shares != nil {
d.Set(shareLevelKey, obj.AllocationInfo.Shares.Level)
d.Set(shareCountKey, obj.AllocationInfo.Shares.Shares)
}
return nil
}
// expandSliceOfDvsHostInfrastructureTrafficResource expands all network I/O
// control resource entries that are currently supported in API, and returns a
// slice of DvsHostInfrastructureTrafficResource.
func expandSliceOfDvsHostInfrastructureTrafficResource(d *schema.ResourceData) []types.DvsHostInfrastructureTrafficResource {
var s []types.DvsHostInfrastructureTrafficResource
for _, key := range infrastructureTrafficClassValues {
v := expandDvsHostInfrastructureTrafficResource(d, key)
if v != nil {
s = append(s, *v)
}
}
return s
}
// flattenSliceOfDvsHostInfrastructureTrafficResource reads in the supplied network I/O control allocation entries supplied via a respective DVSConfigInfo field and sets the appropriate keys in the supplied ResourceData.
func flattenSliceOfDvsHostInfrastructureTrafficResource(d *schema.ResourceData, s []types.DvsHostInfrastructureTrafficResource) error {
for _, v := range s {
if err := flattenDvsHostInfrastructureTrafficResource(d, v, v.Key); err != nil {
return err
}
}
return nil
}
// expandDVSNameArrayUplinkPortPolicy reads certain ResourceData keys and
// returns a DVSNameArrayUplinkPortPolicy.
func expandDVSNameArrayUplinkPortPolicy(d *schema.ResourceData) *types.DVSNameArrayUplinkPortPolicy {
obj := &types.DVSNameArrayUplinkPortPolicy{
UplinkPortName: structure.SliceInterfacesToStrings(d.Get("uplinks").([]interface{})),
}
if structure.AllFieldsEmpty(obj) {
return nil
}
return obj
}
// flattenDVSNameArrayUplinkPortPolicy reads various fields from a
// DVSNameArrayUplinkPortPolicy into the passed in ResourceData.
func flattenDVSNameArrayUplinkPortPolicy(d *schema.ResourceData, obj *types.DVSNameArrayUplinkPortPolicy) error {
if err := d.Set("uplinks", obj.UplinkPortName); err != nil {
return err
}
return nil
}
// expandVMwareDVSConfigSpec reads certain ResourceData keys and
// returns a VMwareDVSConfigSpec.
func expandVMwareDVSConfigSpec(d *schema.ResourceData) *types.VMwareDVSConfigSpec {
obj := &types.VMwareDVSConfigSpec{
DVSConfigSpec: types.DVSConfigSpec{
Name: d.Get("name").(string),
ConfigVersion: d.Get("config_version").(string),
DefaultPortConfig: expandVMwareDVSPortSetting(d),
Host: expandSliceOfDistributedVirtualSwitchHostMemberConfigSpec(d),
Description: d.Get("description").(string),
Contact: expandDVSContactInfo(d),
SwitchIpAddress: d.Get("ipv4_address").(string),
InfrastructureTrafficResourceConfig: expandSliceOfDvsHostInfrastructureTrafficResource(d),
NetworkResourceControlVersion: d.Get("network_resource_control_version").(string),
UplinkPortPolicy: expandDVSNameArrayUplinkPortPolicy(d),
},
MaxMtu: int32(d.Get("max_mtu").(int)),
LinkDiscoveryProtocolConfig: expandLinkDiscoveryProtocolConfig(d),
IpfixConfig: expandVMwareIpfixConfig(d),
LacpApiVersion: d.Get("lacp_api_version").(string),
MulticastFilteringMode: d.Get("multicast_filtering_mode").(string),
}
return obj
}
// flattenVMwareDVSConfigInfo reads various fields from a
// VMwareDVSConfigInfo into the passed in ResourceData.
//
// This is the flatten counterpart to expandVMwareDVSConfigSpec, as the
// configuration info from a DVS comes back as this type instead of a specific
// ConfigSpec.
func flattenVMwareDVSConfigInfo(d *schema.ResourceData, obj *types.VMwareDVSConfigInfo) error {
d.Set("name", obj.Name)
d.Set("config_version", obj.ConfigVersion)
d.Set("description", obj.Description)
d.Set("ipv4_address", obj.SwitchIpAddress)
d.Set("max_mtu", obj.MaxMtu)
d.Set("lacp_api_version", obj.LacpApiVersion)
d.Set("multicast_filtering_mode", obj.MulticastFilteringMode)
d.Set("network_resource_control_version", obj.NetworkResourceControlVersion)
// This is not available in ConfigSpec but is available in ConfigInfo, so
// flatten it here.
d.Set("network_resource_control_enabled", obj.NetworkResourceManagementEnabled)
// Version is set in this object too as ConfigInfo has the productInfo
// property that is outside of this ConfigSpec structure.
d.Set("version", obj.ProductInfo.Version)
if err := flattenDVSNameArrayUplinkPortPolicy(d, obj.UplinkPortPolicy.(*types.DVSNameArrayUplinkPortPolicy)); err != nil {
return err
}
if err := flattenVMwareDVSPortSetting(d, obj.DefaultPortConfig.(*types.VMwareDVSPortSetting)); err != nil {
return err
}
if err := flattenSliceOfDistributedVirtualSwitchHostMember(d, obj.Host); err != nil {
return err
}
if err := flattenSliceOfDvsHostInfrastructureTrafficResource(d, obj.InfrastructureTrafficResourceConfig); err != nil {
return err
}
if err := flattenDVSContactInfo(d, obj.Contact); err != nil {
return err
}
if err := flattenLinkDiscoveryProtocolConfig(d, obj.LinkDiscoveryProtocolConfig); err != nil {
return err
}
if err := flattenVMwareIpfixConfig(d, obj.IpfixConfig); err != nil {
return err
}
return nil
}
// schemaDVSCreateSpec returns schema items for resources that
// need to work with a DVSCreateSpec.
func schemaDVSCreateSpec() map[string]*schema.Schema {
s := map[string]*schema.Schema{
// DistributedVirtualSwitchProductSpec
"version": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The version of this virtual switch. Allowed versions are 6.5.0, 6.0.0, 5.5.0, 5.1.0, and 5.0.0.",
Optional: true,
ValidateFunc: validation.StringInSlice(dvsVersions, false),
},
}
structure.MergeSchema(s, schemaVMwareDVSConfigSpec())
return s
}
// expandDVSCreateSpec reads certain ResourceData keys and
// returns a DVSCreateSpec.
func expandDVSCreateSpec(d *schema.ResourceData) types.DVSCreateSpec {
// Since we are only working with the version string from the product spec,
// we don't have a separate expander/flattener for it. Just do that here.
obj := types.DVSCreateSpec{
ProductInfo: &types.DistributedVirtualSwitchProductSpec{
Version: d.Get("version").(string),
},
ConfigSpec: expandVMwareDVSConfigSpec(d),
}
return obj
}