Skip to content

Commit c89dfe5

Browse files
authored
Documentation and test improvements for NSX-T Network DHCP type (#517)
1 parent 696fea7 commit c89dfe5

File tree

3 files changed

+101
-27
lines changed

3 files changed

+101
-27
lines changed

.changes/v2.17.0/517-notes.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* Improve documentation for `types.OpenApiOrgVdcNetworkDhcp` [GH-517]

govcd/openapi_org_network_test.go

+84-19
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ func (vcd *TestVCD) Test_NsxtOrgVdcNetworkIsolated(check *C) {
2121
orgVdcNetworkConfig := &types.OpenApiOrgVdcNetwork{
2222
Name: check.TestName(),
2323
Description: check.TestName() + "-description",
24-
25-
// On v35.0 orgVdc is not supported anymore. Using ownerRef instead.
26-
OwnerRef: &types.OpenApiReference{ID: vcd.nsxtVdc.Vdc.ID},
27-
24+
OwnerRef: &types.OpenApiReference{ID: vcd.nsxtVdc.Vdc.ID},
2825
NetworkType: types.OrgVdcNetworkTypeIsolated,
2926
Subnets: types.OrgVdcNetworkSubnets{
3027
Values: []types.OrgVdcNetworkSubnetValues{
@@ -54,8 +51,8 @@ func (vcd *TestVCD) Test_NsxtOrgVdcNetworkIsolated(check *C) {
5451
},
5552
}
5653

57-
runOpenApiOrgVdcNetworkTest(check, vcd, vcd.nsxtVdc, orgVdcNetworkConfig, types.OrgVdcNetworkTypeIsolated, nil)
58-
runOpenApiOrgVdcNetworkWithVdcGroupTest(check, vcd, orgVdcNetworkConfig, types.OrgVdcNetworkTypeIsolated, nil)
54+
runOpenApiOrgVdcNetworkTest(check, vcd, vcd.nsxtVdc, orgVdcNetworkConfig, types.OrgVdcNetworkTypeIsolated, []dhcpConfigFunc{nsxtDhcpConfigNetworkMode})
55+
runOpenApiOrgVdcNetworkWithVdcGroupTest(check, vcd, orgVdcNetworkConfig, types.OrgVdcNetworkTypeIsolated, []dhcpConfigFunc{nsxtDhcpConfigNetworkMode})
5956
}
6057

6158
func (vcd *TestVCD) Test_NsxtOrgVdcNetworkRouted(check *C) {
@@ -68,10 +65,7 @@ func (vcd *TestVCD) Test_NsxtOrgVdcNetworkRouted(check *C) {
6865
orgVdcNetworkConfig := &types.OpenApiOrgVdcNetwork{
6966
Name: check.TestName(),
7067
Description: check.TestName() + "-description",
71-
72-
// On v35.0 orgVdc is not supported anymore. Using ownerRef instead.
73-
OwnerRef: &types.OpenApiReference{ID: vcd.nsxtVdc.Vdc.ID},
74-
68+
OwnerRef: &types.OpenApiReference{ID: vcd.nsxtVdc.Vdc.ID},
7569
NetworkType: types.OrgVdcNetworkTypeRouted,
7670

7771
// Connection is used for "routed" network
@@ -115,8 +109,8 @@ func (vcd *TestVCD) Test_NsxtOrgVdcNetworkRouted(check *C) {
115109
},
116110
}
117111

118-
runOpenApiOrgVdcNetworkTest(check, vcd, vcd.nsxtVdc, orgVdcNetworkConfig, types.OrgVdcNetworkTypeRouted, nsxtRoutedDhcpConfig)
119-
runOpenApiOrgVdcNetworkWithVdcGroupTest(check, vcd, orgVdcNetworkConfig, types.OrgVdcNetworkTypeRouted, nsxtRoutedDhcpConfig)
112+
runOpenApiOrgVdcNetworkTest(check, vcd, vcd.nsxtVdc, orgVdcNetworkConfig, types.OrgVdcNetworkTypeRouted, []dhcpConfigFunc{nsxtRoutedDhcpConfigEdgeMode, nsxtDhcpConfigNetworkMode})
113+
runOpenApiOrgVdcNetworkWithVdcGroupTest(check, vcd, orgVdcNetworkConfig, types.OrgVdcNetworkTypeRouted, []dhcpConfigFunc{nsxtRoutedDhcpConfigEdgeMode, nsxtDhcpConfigNetworkMode})
120114
}
121115

122116
func (vcd *TestVCD) Test_NsxtOrgVdcNetworkImported(check *C) {
@@ -330,7 +324,7 @@ func (vcd *TestVCD) Test_NsxvOrgVdcNetworkDirect(check *C) {
330324
runOpenApiOrgVdcNetworkTest(check, vcd, vcd.vdc, orgVdcNetworkConfig, types.OrgVdcNetworkTypeDirect, nil)
331325
}
332326

333-
func runOpenApiOrgVdcNetworkTest(check *C, vcd *TestVCD, vdc *Vdc, orgVdcNetworkConfig *types.OpenApiOrgVdcNetwork, expectNetworkType string, dhcpFunc dhcpConfigFunc) {
327+
func runOpenApiOrgVdcNetworkTest(check *C, vcd *TestVCD, vdc *Vdc, orgVdcNetworkConfig *types.OpenApiOrgVdcNetwork, expectNetworkType string, dhcpFunc []dhcpConfigFunc) {
334328
orgVdcNet, err := vdc.CreateOpenApiOrgVdcNetwork(orgVdcNetworkConfig)
335329
check.Assert(err, IsNil)
336330

@@ -370,8 +364,8 @@ func runOpenApiOrgVdcNetworkTest(check *C, vcd *TestVCD, vdc *Vdc, orgVdcNetwork
370364
check.Assert(updatedOrgVdcNet.OpenApiOrgVdcNetwork.Description, Equals, orgVdcNet.OpenApiOrgVdcNetwork.Description)
371365

372366
// Configure DHCP if specified
373-
if dhcpFunc != nil {
374-
dhcpFunc(check, vcd, vdc, updatedOrgVdcNet.OpenApiOrgVdcNetwork.ID)
367+
for i := range dhcpFunc {
368+
dhcpFunc[i](check, vcd, vdc, updatedOrgVdcNet.OpenApiOrgVdcNetwork.ID)
375369
}
376370
// Delete
377371
err = orgVdcNet.Delete()
@@ -387,7 +381,7 @@ func runOpenApiOrgVdcNetworkTest(check *C, vcd *TestVCD, vdc *Vdc, orgVdcNetwork
387381

388382
type dhcpConfigFunc func(check *C, vcd *TestVCD, vdc *Vdc, orgNetId string)
389383

390-
func nsxtRoutedDhcpConfig(check *C, vcd *TestVCD, vdc *Vdc, orgNetId string) {
384+
func nsxtRoutedDhcpConfigEdgeMode(check *C, vcd *TestVCD, vdc *Vdc, orgNetId string) {
391385
dhcpDefinition := &types.OpenApiOrgVdcNetworkDhcp{
392386
Enabled: takeBoolPointer(true),
393387
DhcpPools: []types.OpenApiOrgVdcNetworkDhcpPools{
@@ -435,10 +429,81 @@ func nsxtRoutedDhcpConfig(check *C, vcd *TestVCD, vdc *Vdc, orgNetId string) {
435429
check.Assert(err, IsNil)
436430
check.Assert(len(deletedDhcp.OpenApiOrgVdcNetworkDhcp.DhcpPools), Equals, 0)
437431
check.Assert(len(deletedDhcp.OpenApiOrgVdcNetworkDhcp.DnsServers), Equals, 0)
432+
}
433+
434+
// nsxtDhcpConfigNetworkMode checks DHCP functionality in NETWORK mode.
435+
// It requires that Edge Cluster is set at VDC level therefore this function does it for the
436+
// duration of this test and restores it back
437+
func nsxtDhcpConfigNetworkMode(check *C, vcd *TestVCD, vdc *Vdc, orgNetId string) {
438+
// Only supported in 10.3.1+
439+
if vdc.client.APIVCDMaxVersionIs("< 36.1") {
440+
return
441+
}
442+
443+
// DHCP in NETWORK mode requires Edge Cluster to be set for VDC and cleaned up afterwards
444+
edgeCluster, err := vdc.GetNsxtEdgeClusterByName(vcd.config.VCD.Nsxt.NsxtEdgeCluster)
445+
check.Assert(err, IsNil)
446+
vdcNetworkProfile := &types.VdcNetworkProfile{
447+
ServicesEdgeCluster: &types.VdcNetworkProfileServicesEdgeCluster{
448+
BackingID: edgeCluster.NsxtEdgeCluster.ID,
449+
},
450+
}
451+
_, err = vdc.UpdateVdcNetworkProfile(vdcNetworkProfile)
452+
check.Assert(err, IsNil)
453+
defer func() {
454+
err := vdc.DeleteVdcNetworkProfile()
455+
if err != nil {
456+
check.Errorf("error cleaning up VDC Network Profile: %s", err)
457+
}
458+
}()
438459

460+
dhcpDefinition := &types.OpenApiOrgVdcNetworkDhcp{
461+
Enabled: takeBoolPointer(true),
462+
Mode: "NETWORK",
463+
IPAddress: "2.1.1.252",
464+
DhcpPools: []types.OpenApiOrgVdcNetworkDhcpPools{
465+
{
466+
Enabled: takeBoolPointer(true),
467+
IPRange: types.OpenApiOrgVdcNetworkDhcpIpRange{
468+
StartAddress: "2.1.1.200",
469+
EndAddress: "2.1.1.201",
470+
},
471+
},
472+
},
473+
DnsServers: []string{
474+
"8.8.8.8",
475+
"8.8.4.4",
476+
},
477+
}
478+
479+
updatedDhcp, err := vdc.UpdateOpenApiOrgVdcNetworkDhcp(orgNetId, dhcpDefinition)
480+
check.Assert(err, IsNil)
481+
482+
check.Assert(dhcpDefinition, DeepEquals, updatedDhcp.OpenApiOrgVdcNetworkDhcp)
483+
484+
err = vdc.DeleteOpenApiOrgVdcNetworkDhcp(orgNetId)
485+
check.Assert(err, IsNil)
486+
487+
orgVdcNetwork, err := vcd.org.GetOpenApiOrgVdcNetworkById(orgNetId)
488+
check.Assert(err, IsNil)
489+
check.Assert(orgVdcNetwork, NotNil)
490+
491+
updatedDhcp2, err := orgVdcNetwork.UpdateDhcp(dhcpDefinition)
492+
check.Assert(err, IsNil)
493+
check.Assert(updatedDhcp2, NotNil)
494+
495+
check.Assert(dhcpDefinition, DeepEquals, updatedDhcp2.OpenApiOrgVdcNetworkDhcp)
496+
497+
err = orgVdcNetwork.DeletNetworkDhcp()
498+
check.Assert(err, IsNil)
499+
500+
deletedDhcp, err := orgVdcNetwork.GetOpenApiOrgVdcNetworkDhcp()
501+
check.Assert(err, IsNil)
502+
check.Assert(len(deletedDhcp.OpenApiOrgVdcNetworkDhcp.DhcpPools), Equals, 0)
503+
check.Assert(len(deletedDhcp.OpenApiOrgVdcNetworkDhcp.DnsServers), Equals, 0)
439504
}
440505

441-
func runOpenApiOrgVdcNetworkWithVdcGroupTest(check *C, vcd *TestVCD, orgVdcNetworkConfig *types.OpenApiOrgVdcNetwork, expectNetworkType string, dhcpFunc dhcpConfigFunc) {
506+
func runOpenApiOrgVdcNetworkWithVdcGroupTest(check *C, vcd *TestVCD, orgVdcNetworkConfig *types.OpenApiOrgVdcNetwork, expectNetworkType string, dhcpFunc []dhcpConfigFunc) {
442507
adminOrg, err := vcd.client.GetAdminOrgByName(vcd.config.VCD.Org)
443508
check.Assert(err, IsNil)
444509

@@ -525,8 +590,8 @@ func runOpenApiOrgVdcNetworkWithVdcGroupTest(check *C, vcd *TestVCD, orgVdcNetwo
525590
check.Assert(updatedOrgVdcNet.OpenApiOrgVdcNetwork.Description, Equals, orgVdcNet.OpenApiOrgVdcNetwork.Description)
526591

527592
// Configure DHCP if specified
528-
if dhcpFunc != nil {
529-
dhcpFunc(check, vcd, vdc, updatedOrgVdcNet.OpenApiOrgVdcNetwork.ID)
593+
for i := range dhcpFunc {
594+
dhcpFunc[i](check, vcd, vdc, updatedOrgVdcNet.OpenApiOrgVdcNetwork.ID)
530595
}
531596
// Delete
532597
err = orgVdcNet.Delete()

types/v56/nsxt_types.go

+16-8
Original file line numberDiff line numberDiff line change
@@ -201,28 +201,36 @@ type NsxtImportableSwitch = OpenApiReference
201201

202202
// OpenApiOrgVdcNetworkDhcp allows users to manage DHCP configuration for Org VDC networks by using OpenAPI endpoint
203203
type OpenApiOrgVdcNetworkDhcp struct {
204-
Enabled *bool `json:"enabled,omitempty"`
204+
Enabled *bool `json:"enabled,omitempty"`
205+
206+
// LeaseTime specifies the amount of time in seconds of how long a DHCP IP will be leased out
207+
// for. The minimum is 60s while the maximum is 4,294,967,295s, which is roughly 49,710 days.
205208
LeaseTime *int `json:"leaseTime,omitempty"`
206209
DhcpPools []OpenApiOrgVdcNetworkDhcpPools `json:"dhcpPools,omitempty"`
210+
207211
// Mode describes how the DHCP service is configured for this network. Once a DHCP service has been created, the mode
208212
// attribute cannot be changed. The mode field will default to 'EDGE' if it is not provided. This field only applies
209213
// to networks backed by an NSX-T network provider.
210214
//
211-
// The supported values are EDGE (default) and NETWORK.
215+
// The supported values are EDGE, NETWORK and RELAY (VCD 10.3.1+, API 36.1+).
212216
// * If EDGE is specified, the DHCP service of the edge is used to obtain DHCP IPs.
213-
// * If NETWORK is specified, a DHCP server is created for use by this network. (To use NETWORK
217+
// * If NETWORK is specified, a DHCP server is created for use by this network.
218+
// * If RELAY is specified, all the DHCP client requests will be relayed to Gateway DHCP
219+
// Forwarder service. This mode is only supported for Routed Org vDC Networks.
214220
//
215-
// In order to use DHCP for IPV6, NETWORK mode must be used. Routed networks which are using NETWORK DHCP services can
216-
// be disconnected from the edge gateway and still retain their DHCP configuration, however network using EDGE DHCP
217-
// cannot be disconnected from the gateway until DHCP has been disabled.
221+
// In order to use DHCP for IPV6, NETWORK mode must be used. Routed networks which are using
222+
// NETWORK DHCP services can be disconnected from the edge gateway and still retain their DHCP
223+
// configuration, however DHCP configuration will be removed during connection change for
224+
// networks using EDGE or RELAY DHCP mode.
218225
Mode string `json:"mode,omitempty"`
226+
219227
// IPAddress is only applicable when mode=NETWORK. This will specify IP address of DHCP server in network.
220228
IPAddress string `json:"ipAddress,omitempty"`
221229

222230
// New fields starting with 36.1
223231

224-
// DnsServers are the IPs to be assigned by this DHCP service. The IP type must match the IP type of the subnet on
225-
// which the DHCP config is being created.
232+
// DnsServers are the IPs to be assigned by this DHCP service. The IP type must match the IP
233+
// type of the subnet on which the DHCP config is being created.
226234
DnsServers []string `json:"dnsServers,omitempty"`
227235
}
228236

0 commit comments

Comments
 (0)