From cc9ee463c6b83c36ada873918156fb4d7bdd03e2 Mon Sep 17 00:00:00 2001 From: Dainius Serplis Date: Sun, 16 Oct 2022 08:27:59 +0300 Subject: [PATCH 01/11] WIP Signed-off-by: Dainius Serplis --- govcd/openapi_endpoints.go | 1 + govcd/vdc_network_profile.go | 97 +++++++++++++++++++++++++++++++ govcd/vdc_network_profile_test.go | 60 +++++++++++++++++++ types/v56/constants.go | 1 + types/v56/nsxt_types.go | 41 +++++++++++++ 5 files changed, 200 insertions(+) create mode 100644 govcd/vdc_network_profile.go create mode 100644 govcd/vdc_network_profile_test.go diff --git a/govcd/openapi_endpoints.go b/govcd/openapi_endpoints.go index 9e0d61292..278948731 100644 --- a/govcd/openapi_endpoints.go +++ b/govcd/openapi_endpoints.go @@ -78,6 +78,7 @@ var endpointMinApiVersions = map[string]string{ types.OpenApiPathVersion2_0_0 + types.OpenApiEndpointVdcAssignedComputePolicies: "35.0", types.OpenApiPathVersion2_0_0 + types.OpenApiEndpointVdcComputePolicies: "35.0", + types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointVdcNetworkProfile: "36.0", // VCD 10.3+ } // elevateNsxtNatRuleApiVersion helps to elevate API version to consume newer NSX-T NAT Rule features diff --git a/govcd/vdc_network_profile.go b/govcd/vdc_network_profile.go new file mode 100644 index 000000000..e5ac56910 --- /dev/null +++ b/govcd/vdc_network_profile.go @@ -0,0 +1,97 @@ +/* + * Copyright 2022 VMware, Inc. All rights reserved. Licensed under the Apache v2 License. + */ + +package govcd + +import ( + "fmt" + + "github.com/vmware/go-vcloud-director/v2/types/v56" +) + +// VDC Network profiles have 1:1 mapping + +// GetVdcNetworkProfile retrieves VDC Network Profile configuration +// vdc.Vdc.ID must be set and valid present +func (vdc *Vdc) GetVdcNetworkProfile() (*types.VdcNetworkProfile, error) { + client := vdc.client + endpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointVdcNetworkProfile + apiVersion, err := client.getOpenApiHighestElevatedVersion(endpoint) + if err != nil { + return nil, err + } + + if vdc == nil || vdc.Vdc == nil || vdc.Vdc.ID == "" { + return nil, fmt.Errorf("cannot lookup VDC Network Profile configuration without VDC ID") + } + + urlRef, err := client.OpenApiBuildEndpoint(fmt.Sprintf(endpoint, vdc.Vdc.ID)) + if err != nil { + return nil, err + } + + returnObject := &types.VdcNetworkProfile{} + err = client.OpenApiGetItem(apiVersion, urlRef, nil, returnObject, nil) + if err != nil { + return nil, err + } + + return returnObject, nil +} + +// UpdateVdcNetworkProfile updates the VDC Network Profile configuration +// +// Note. It is VDC Network Profile configuration must have +func (vdc *Vdc) UpdateVdcNetworkProfile(vdcNetworkProfileConfig *types.VdcNetworkProfile) (*types.VdcNetworkProfile, error) { + client := vdc.client + endpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointVdcNetworkProfile + apiVersion, err := client.getOpenApiHighestElevatedVersion(endpoint) + if err != nil { + return nil, err + } + + if vdc == nil || vdc.Vdc == nil || vdc.Vdc.ID == "" { + return nil, fmt.Errorf("cannot update VDC Network Profile configuration without ID") + } + + urlRef, err := client.OpenApiBuildEndpoint(fmt.Sprintf(endpoint, vdc.Vdc.ID)) + if err != nil { + return nil, err + } + + returnObject := &types.VdcNetworkProfile{} + err = client.OpenApiPutItem(apiVersion, urlRef, nil, vdcNetworkProfileConfig, returnObject, nil) + if err != nil { + return nil, fmt.Errorf("error updating VDC Network Profile configuration: %s", err) + } + + return returnObject, nil +} + +// DeleteVdcNetworkProfile deletes VDC Network Profile Configuration +func (vdc *Vdc) DeleteVdcNetworkProfile() error { + client := vdc.client + endpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointVdcNetworkProfile + apiVersion, err := client.getOpenApiHighestElevatedVersion(endpoint) + if err != nil { + return err + } + + if vdc == nil || vdc.Vdc == nil || vdc.Vdc.ID == "" { + return fmt.Errorf("cannot lookup VDC Network Profile without VDC ID") + } + + urlRef, err := client.OpenApiBuildEndpoint(fmt.Sprintf(endpoint, vdc.Vdc.ID)) + if err != nil { + return err + } + + err = client.OpenApiDeleteItem(apiVersion, urlRef, nil, nil) + + if err != nil { + return fmt.Errorf("error deleting VDC Network Profile configuration: %s", err) + } + + return nil +} diff --git a/govcd/vdc_network_profile_test.go b/govcd/vdc_network_profile_test.go new file mode 100644 index 000000000..81124f88c --- /dev/null +++ b/govcd/vdc_network_profile_test.go @@ -0,0 +1,60 @@ +//go:build network || nsxt || functional || openapi || ALL +// +build network nsxt functional openapi ALL + +package govcd + +import ( + "github.com/davecgh/go-spew/spew" + "github.com/vmware/go-vcloud-director/v2/types/v56" + . "gopkg.in/check.v1" +) + +// Test_NsxtFirewall creates 20 firewall rules with randomized parameters +func (vcd *TestVCD) Test_VdcNetworkProfile(check *C) { + skipNoNsxtConfiguration(vcd, check) + + org, err := vcd.client.GetOrgByName(vcd.config.VCD.Org) + check.Assert(err, IsNil) + nsxtVdc, err := org.GetVDCByName(vcd.config.VCD.Nsxt.Vdc, false) + check.Assert(err, IsNil) + + existingVdcNetworkProfile, err := nsxtVdc.GetVdcNetworkProfile() + check.Assert(err, IsNil) + check.Assert(existingVdcNetworkProfile, NotNil) + + spew.Dump(existingVdcNetworkProfile) + + // Lookup Edge available Edge Cluster + allEdgeClusters, err := nsxtVdc.GetAllNsxtEdgeClusters(nil) + check.Assert(err, IsNil) + check.Assert(allEdgeClusters, NotNil) + + networkProfileConfig := &types.VdcNetworkProfile{ + ServicesEdgeCluster: &types.VdcNetworkProfileServicesEdgeCluster{ + BackingID: allEdgeClusters[0].NsxtEdgeCluster.ID, + }, + } + + newVdcNetworkProfile, err := nsxtVdc.UpdateVdcNetworkProfile(networkProfileConfig) + check.Assert(err, IsNil) + check.Assert(newVdcNetworkProfile, NotNil) + check.Assert(newVdcNetworkProfile.ServicesEdgeCluster.BackingID, Equals, allEdgeClusters[0].NsxtEdgeCluster.ID) + + // Try to unset the value + + unsetNetworkProfileConfig := &types.VdcNetworkProfile{ + ServicesEdgeCluster: &types.VdcNetworkProfileServicesEdgeCluster{}, + VdcNetworkSegmentProfileTemplateRef: &types.OpenApiReferenceEE{ID: ""}, + } + spew.Dump(unsetNetworkProfileConfig) + + unsetVdcNetworkProfile, err := nsxtVdc.UpdateVdcNetworkProfile(unsetNetworkProfileConfig) + check.Assert(err, IsNil) + check.Assert(unsetVdcNetworkProfile, NotNil) + + // Cleanup + + // err = nsxtVdc.DeleteVdcNetworkProfile() + // check.Assert(err, IsNil) + +} diff --git a/types/v56/constants.go b/types/v56/constants.go index ddc4699ef..1e69d6d13 100644 --- a/types/v56/constants.go +++ b/types/v56/constants.go @@ -356,6 +356,7 @@ const ( OpenApiEndpointVdcComputePolicies = "vdcComputePolicies/" OpenApiEndpointVdcAssignedComputePolicies = "vdcs/%s/computePolicies" OpenApiEndpointVdcCapabilities = "vdcs/%s/capabilities" + OpenApiEndpointVdcNetworkProfile = "vdcs/%s/networkProfile" OpenApiEndpointEdgeGateways = "edgeGateways/" OpenApiEndpointNsxtFirewallRules = "edgeGateways/%s/firewall/rules" OpenApiEndpointFirewallGroups = "firewallGroups/" diff --git a/types/v56/nsxt_types.go b/types/v56/nsxt_types.go index 4eb949fd1..36e650d2f 100644 --- a/types/v56/nsxt_types.go +++ b/types/v56/nsxt_types.go @@ -1452,3 +1452,44 @@ type EdgeBgpGracefulRestartConfig struct { type EdgeBgpConfigVersion struct { Version int `json:"version"` } + +// VdcNetworkProfile defines a VDC Network Profile. +// +// All fields are optional. They do not have `omitempty` struct tags as sending a `null` value for +// particular fields will ignore overriding existing value. +type VdcNetworkProfile struct { + // PrimaryEdgeCluster defines NSX-V Edge Cluster where the primary appliance for an NSX-V Edge + // Gateway will be deployed. (NSX-V only) + PrimaryEdgeCluster *OpenApiReference `json:"primaryEdgeCluster,omitempty"` + + // SecondaryEdgeCluster defines NSX-V Edge Cluster where the secondary appliance for an NSX-V + // Edge Gateway will be deployed if HA is enabled on the Edge. (NSX-V only) + SecondaryEdgeCluster *OpenApiReference `json:"secondaryEdgeCluster,omitempty"` + + // ServicesEdgeCluster contains NSX-T Edge Cluster where the DHCP server profile will be stored + // for NSX-T networks using NETWORK mode DHCP. (NSX-T only) + ServicesEdgeCluster *VdcNetworkProfileServicesEdgeCluster `json:"servicesEdgeCluster,omitempty"` + + // VappNetworkSegmentProfileTemplateRef defines vApp Network Segment Profile Template that is to + // be used when any new vApp Network is created under this VDC. Setting this will override any + // global level vApp Network Segment Profile Template. This field is only applicable for (NSX-T + // only) + VappNetworkSegmentProfileTemplateRef *OpenApiReferenceEE `json:"vappNetworkSegmentProfileTemplateRef,omitempty"` + + // VdcNetworkSegmentProfileTemplateRef defines Org vDC Network Segment Profile Template that is + // to be used when any new Org vDC Network is created under this VDC. Setting this will override + // any global level Org vDC Network Segment Profile Template. (NSX-T only) + VdcNetworkSegmentProfileTemplateRef *OpenApiReferenceEE `json:"vdcNetworkSegmentProfileTemplateRef,omitempty"` +} + +// VdcNetworkProfileServicesEdgeCluster contains reference to NSX-T Edge Cluster used in +// VdcNetworkProfile +type VdcNetworkProfileServicesEdgeCluster struct { + BackingID string `json:"backingId"` + EdgeClusterRef *OpenApiReference `json:"edgeClusterRef,omitempty"` +} + +type OpenApiReferenceEE struct { + Name string `json:"name"` + ID string `json:"id"` +} From 186191e5673f22449cbc5293748b5c2e350b631d Mon Sep 17 00:00:00 2001 From: Dainius Serplis Date: Fri, 21 Oct 2022 11:50:21 +0300 Subject: [PATCH 02/11] Improvements Signed-off-by: Dainius Serplis --- .changes/v2.17.0/505-improvements.md | 1 - .changes/v2.17.0/XXX-improvements.md | 5 ++ govcd/api_vcd_test.go | 1 + govcd/nsxt_edge_cluster.go | 40 +++++++---- govcd/nsxt_edge_cluster_test.go | 12 +++- govcd/openapi_endpoints.go | 4 ++ govcd/sample_govcd_test_config.yaml | 2 + govcd/vdc_network_profile.go | 87 ++++++++++++++++++----- govcd/vdc_network_profile_test.go | 30 +++----- types/v56/nsxt_types.go | 102 +++++++++++++++++++++++++-- types/v56/openapi.go | 10 +++ util/logging.go | 6 -- 12 files changed, 232 insertions(+), 68 deletions(-) create mode 100644 .changes/v2.17.0/XXX-improvements.md diff --git a/.changes/v2.17.0/505-improvements.md b/.changes/v2.17.0/505-improvements.md index 898d44b5d..bdd945f40 100644 --- a/.changes/v2.17.0/505-improvements.md +++ b/.changes/v2.17.0/505-improvements.md @@ -1,2 +1 @@ * Simplify `Test_LDAP` by using a pre-configured LDAP server [GH-505] - diff --git a/.changes/v2.17.0/XXX-improvements.md b/.changes/v2.17.0/XXX-improvements.md new file mode 100644 index 000000000..04f6238a4 --- /dev/null +++ b/.changes/v2.17.0/XXX-improvements.md @@ -0,0 +1,5 @@ +* Added VCDClient.GetAllNsxtEdgeClusters for lookup of NSX-T Edge Clusters in wider scopes - + Provider VDC, VDC Group or VDC [GH-XXX] +* Removed a few log lines from SetLog() function which were being set before correct logging file + was initialized. This resulted in a file `go-vcloud-director.log` even if other filename was used + [GH-XXX] diff --git a/govcd/api_vcd_test.go b/govcd/api_vcd_test.go index b093807c2..43f60c2d2 100644 --- a/govcd/api_vcd_test.go +++ b/govcd/api_vcd_test.go @@ -177,6 +177,7 @@ type TestConfig struct { NsxtImportSegment string `yaml:"nsxtImportSegment"` VdcGroup string `yaml:"vdcGroup"` VdcGroupEdgeGateway string `yaml:"vdcGroupEdgeGateway"` + NsxtEdgeCluster string `yaml:"nsxtEdgeCluster"` NsxtAlbControllerUrl string `yaml:"nsxtAlbControllerUrl"` NsxtAlbControllerUser string `yaml:"nsxtAlbControllerUser"` diff --git a/govcd/nsxt_edge_cluster.go b/govcd/nsxt_edge_cluster.go index 09991a7d0..e01c11935 100644 --- a/govcd/nsxt_edge_cluster.go +++ b/govcd/nsxt_edge_cluster.go @@ -68,7 +68,6 @@ func filterNsxtEdgeClusters(name string, allNnsxtEdgeCluster []*NsxtEdgeCluster) } return filteredNsxtEdgeClusters - } // GetAllNsxtEdgeClusters retrieves all available Edge Clusters for a particular VDC @@ -77,28 +76,41 @@ func (vdc *Vdc) GetAllNsxtEdgeClusters(queryParameters url.Values) ([]*NsxtEdgeC return nil, fmt.Errorf("VDC must have ID populated to retrieve NSX-T edge clusters") } + // Get all NSX-T Edge clusters that are accessible to an organization VDC. The 'orgVdcId'filter + // key must be set with the ID of the VDC for which we want to get available Edge Clusters for. + // + // orgVdcId==urn:vcloud:vdc:09722307-aee0-4623-af95-7f8e577c9ebc + + // Create a copy of queryParameters so that original queryParameters are not mutated (because a map is always a + // reference) + queryParams := queryParameterFilterAnd("orgVdcId=="+vdc.Vdc.ID, queryParameters) + + return getAllNsxtEdgeClusters(vdc.client, queryParams) +} + +// GetAllNsxtEdgeClusters retrieves all NSX-T Edge Clusters in the system +// +// orgVdcId - | The filter orgVdcId must be set equal to the id of the NSX-T backed Org vDC for which we want to get the edge clusters. Example: (orgVdcId==urn:vcloud:vdc:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx) +// vdcGroupId - | The filter vdcGroupId must be set equal to the id of the NSX-T VDC Group for which we want to get the edge clusters. Example: (vdcGroupId==urn:vcloud:vdcGroup:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx) +// pvdcId - | The filter pvdcId must be set equal to the id of the NSX-T backed Provider VDC for which we want to get the edge clusters. pvdcId filter is supported from version 35.2 Example: (pvdcId==urn:vcloud:providervdc:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx) +func (vcdClient *VCDClient) GetAllNsxtEdgeClusters(queryParameters url.Values) ([]*NsxtEdgeCluster, error) { + return getAllNsxtEdgeClusters(&vcdClient.Client, queryParameters) +} + +func getAllNsxtEdgeClusters(client *Client, queryParams url.Values) ([]*NsxtEdgeCluster, error) { endpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointEdgeClusters - minimumApiVersion, err := vdc.client.checkOpenApiEndpointCompatibility(endpoint) + apiVersion, err := client.getOpenApiHighestElevatedVersion(endpoint) if err != nil { return nil, err } - urlRef, err := vdc.client.OpenApiBuildEndpoint(endpoint) + urlRef, err := client.OpenApiBuildEndpoint(endpoint) if err != nil { return nil, err } - // Get all NSX-T Edge clusters that are accessible to an organization VDC. The “_context” filter key must be set with - // the ID of the VDC for which we want to get available Edge Clusters for. - // - // _context==urn:vcloud:vdc:09722307-aee0-4623-af95-7f8e577c9ebc - - // Create a copy of queryParameters so that original queryParameters are not mutated (because a map is always a - // reference) - queryParams := queryParameterFilterAnd("_context=="+vdc.Vdc.ID, queryParameters) - typeResponses := []*types.NsxtEdgeCluster{{}} - err = vdc.client.OpenApiGetAllItems(minimumApiVersion, urlRef, queryParams, &typeResponses, nil) + err = client.OpenApiGetAllItems(apiVersion, urlRef, queryParams, &typeResponses, nil) if err != nil { return nil, err } @@ -107,7 +119,7 @@ func (vdc *Vdc) GetAllNsxtEdgeClusters(queryParameters url.Values) ([]*NsxtEdgeC for sliceIndex := range typeResponses { returnObjects[sliceIndex] = &NsxtEdgeCluster{ NsxtEdgeCluster: typeResponses[sliceIndex], - client: vdc.client, + client: client, } } diff --git a/govcd/nsxt_edge_cluster_test.go b/govcd/nsxt_edge_cluster_test.go index 6463496f0..4eccad501 100644 --- a/govcd/nsxt_edge_cluster_test.go +++ b/govcd/nsxt_edge_cluster_test.go @@ -23,10 +23,16 @@ func (vcd *TestVCD) Test_GetAllNsxtEdgeClusters(check *C) { nsxtVdc, err := vcd.org.GetVDCByNameOrId(vcd.config.VCD.Nsxt.Vdc, true) check.Assert(err, IsNil) - tier0Router, err := nsxtVdc.GetAllNsxtEdgeClusters(nil) + edgeClusters, err := nsxtVdc.GetAllNsxtEdgeClusters(nil) check.Assert(err, IsNil) - check.Assert(tier0Router, NotNil) - check.Assert(len(tier0Router) > 0, Equals, true) + check.Assert(edgeClusters, NotNil) + check.Assert(len(edgeClusters) > 0, Equals, true) + + allEdgeClusters, err := vcd.client.GetAllNsxtEdgeClusters(nil) + check.Assert(err, IsNil) + check.Assert(allEdgeClusters, NotNil) + check.Assert(len(allEdgeClusters) > 0, Equals, true) + } func (vcd *TestVCD) Test_GetNsxtEdgeClusterByName(check *C) { diff --git a/govcd/openapi_endpoints.go b/govcd/openapi_endpoints.go index 278948731..4db35cbeb 100644 --- a/govcd/openapi_endpoints.go +++ b/govcd/openapi_endpoints.go @@ -122,6 +122,10 @@ var endpointElevatedApiVersions = map[string][]string{ //"35.0", // Basic minimum required version "37.0", // Deprecates LicenseType in favor of SupportedFeatureSet }, + types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointVdcNetworkProfile: { + //"36.0", // Introduced support + "36.2", // + }, } // checkOpenApiEndpointCompatibility checks if VCD version (to which the client is connected) is sufficient to work with diff --git a/govcd/sample_govcd_test_config.yaml b/govcd/sample_govcd_test_config.yaml index 7fe7d09ae..0a450b6a9 100644 --- a/govcd/sample_govcd_test_config.yaml +++ b/govcd/sample_govcd_test_config.yaml @@ -76,6 +76,8 @@ vcd: edgeGateway: nsxt-gw-name # Existing NSX-T segment to test NSX-T Imported Org Vdc network nsxtImportSegment: vcd-org-vdc-imported-network-backing + # Existing NSX-T Edge Cluster name + nsxtEdgeCluster: existing-nsxt-edge-cluster # An Org catalog, possibly containing at least one item catalog: name: mycat diff --git a/govcd/vdc_network_profile.go b/govcd/vdc_network_profile.go index e5ac56910..6cd75f597 100644 --- a/govcd/vdc_network_profile.go +++ b/govcd/vdc_network_profile.go @@ -10,23 +10,82 @@ import ( "github.com/vmware/go-vcloud-director/v2/types/v56" ) -// VDC Network profiles have 1:1 mapping +// VDC Network profiles have 1:1 mapping with VDC - each VDC has an option to configure VDC Network +// Profiles. types.VdcNetworkProfile holds more information about possible configurations // GetVdcNetworkProfile retrieves VDC Network Profile configuration // vdc.Vdc.ID must be set and valid present func (vdc *Vdc) GetVdcNetworkProfile() (*types.VdcNetworkProfile, error) { - client := vdc.client + if vdc == nil || vdc.Vdc == nil || vdc.Vdc.ID == "" { + return nil, fmt.Errorf("cannot lookup VDC Network Profile configuration without VDC ID") + } + + return getVdcNetworkProfile(vdc.client, vdc.Vdc.ID) +} + +// GetVdcNetworkProfile retrieves VDC Network Profile configuration +// vdc.Vdc.ID must be set and valid present +func (adminVdc *AdminVdc) GetVdcNetworkProfile() (*types.VdcNetworkProfile, error) { + if adminVdc == nil || adminVdc.AdminVdc == nil || adminVdc.AdminVdc.ID == "" { + return nil, fmt.Errorf("cannot lookup VDC Network Profile configuration without VDC ID") + } + + return getVdcNetworkProfile(adminVdc.client, adminVdc.AdminVdc.ID) +} + +// UpdateVdcNetworkProfile updates the VDC Network Profile configuration +// +// Note. Whenever updating VDC Network Profile it is required to send all fields (not only the +// change one) as VCD will remove other configuration. Best practice is to fetch current +// configuration of VDC Network Profile using GetVdcNetworkProfile, alter it with new values and +// submit it to UpdateVdcNetworkProfile. +func (vdc *Vdc) UpdateVdcNetworkProfile(vdcNetworkProfileConfig *types.VdcNetworkProfile) (*types.VdcNetworkProfile, error) { + if vdc == nil || vdc.Vdc == nil || vdc.Vdc.ID == "" { + return nil, fmt.Errorf("cannot update VDC Network Profile configuration without ID") + } + + return updateVdcNetworkProfile(vdc.client, vdc.Vdc.ID, vdcNetworkProfileConfig) +} + +// UpdateVdcNetworkProfile updates the VDC Network Profile configuration +func (adminVdc *AdminVdc) UpdateVdcNetworkProfile(vdcNetworkProfileConfig *types.VdcNetworkProfile) (*types.VdcNetworkProfile, error) { + if adminVdc == nil || adminVdc.AdminVdc == nil || adminVdc.AdminVdc.ID == "" { + return nil, fmt.Errorf("cannot update VDC Network Profile configuration without ID") + } + + return updateVdcNetworkProfile(adminVdc.client, adminVdc.AdminVdc.ID, vdcNetworkProfileConfig) +} + +// DeleteVdcNetworkProfile deletes VDC Network Profile Configuration +func (vdc *Vdc) DeleteVdcNetworkProfile() error { + if vdc == nil || vdc.Vdc == nil || vdc.Vdc.ID == "" { + return fmt.Errorf("cannot lookup VDC Network Profile without VDC ID") + } + + return deleteVdcNetworkProfile(vdc.client, vdc.Vdc.ID) +} + +// DeleteVdcNetworkProfile deletes VDC Network Profile Configuration +func (adminVdc *AdminVdc) DeleteVdcNetworkProfile() error { + if adminVdc == nil || adminVdc.AdminVdc == nil || adminVdc.AdminVdc.ID == "" { + return fmt.Errorf("cannot lookup VDC Network Profile without VDC ID") + } + + return deleteVdcNetworkProfile(adminVdc.client, adminVdc.AdminVdc.ID) +} + +func getVdcNetworkProfile(client *Client, vdcId string) (*types.VdcNetworkProfile, error) { endpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointVdcNetworkProfile apiVersion, err := client.getOpenApiHighestElevatedVersion(endpoint) if err != nil { return nil, err } - if vdc == nil || vdc.Vdc == nil || vdc.Vdc.ID == "" { + if vdcId == "" { return nil, fmt.Errorf("cannot lookup VDC Network Profile configuration without VDC ID") } - urlRef, err := client.OpenApiBuildEndpoint(fmt.Sprintf(endpoint, vdc.Vdc.ID)) + urlRef, err := client.OpenApiBuildEndpoint(fmt.Sprintf(endpoint, vdcId)) if err != nil { return nil, err } @@ -40,22 +99,18 @@ func (vdc *Vdc) GetVdcNetworkProfile() (*types.VdcNetworkProfile, error) { return returnObject, nil } -// UpdateVdcNetworkProfile updates the VDC Network Profile configuration -// -// Note. It is VDC Network Profile configuration must have -func (vdc *Vdc) UpdateVdcNetworkProfile(vdcNetworkProfileConfig *types.VdcNetworkProfile) (*types.VdcNetworkProfile, error) { - client := vdc.client +func updateVdcNetworkProfile(client *Client, vdcId string, vdcNetworkProfileConfig *types.VdcNetworkProfile) (*types.VdcNetworkProfile, error) { endpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointVdcNetworkProfile apiVersion, err := client.getOpenApiHighestElevatedVersion(endpoint) if err != nil { return nil, err } - if vdc == nil || vdc.Vdc == nil || vdc.Vdc.ID == "" { + if vdcId == "" { return nil, fmt.Errorf("cannot update VDC Network Profile configuration without ID") } - urlRef, err := client.OpenApiBuildEndpoint(fmt.Sprintf(endpoint, vdc.Vdc.ID)) + urlRef, err := client.OpenApiBuildEndpoint(fmt.Sprintf(endpoint, vdcId)) if err != nil { return nil, err } @@ -69,20 +124,14 @@ func (vdc *Vdc) UpdateVdcNetworkProfile(vdcNetworkProfileConfig *types.VdcNetwor return returnObject, nil } -// DeleteVdcNetworkProfile deletes VDC Network Profile Configuration -func (vdc *Vdc) DeleteVdcNetworkProfile() error { - client := vdc.client +func deleteVdcNetworkProfile(client *Client, vdcId string) error { endpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointVdcNetworkProfile apiVersion, err := client.getOpenApiHighestElevatedVersion(endpoint) if err != nil { return err } - if vdc == nil || vdc.Vdc == nil || vdc.Vdc.ID == "" { - return fmt.Errorf("cannot lookup VDC Network Profile without VDC ID") - } - - urlRef, err := client.OpenApiBuildEndpoint(fmt.Sprintf(endpoint, vdc.Vdc.ID)) + urlRef, err := client.OpenApiBuildEndpoint(fmt.Sprintf(endpoint, vdcId)) if err != nil { return err } diff --git a/govcd/vdc_network_profile_test.go b/govcd/vdc_network_profile_test.go index 81124f88c..dbd81b0e9 100644 --- a/govcd/vdc_network_profile_test.go +++ b/govcd/vdc_network_profile_test.go @@ -4,12 +4,10 @@ package govcd import ( - "github.com/davecgh/go-spew/spew" "github.com/vmware/go-vcloud-director/v2/types/v56" . "gopkg.in/check.v1" ) -// Test_NsxtFirewall creates 20 firewall rules with randomized parameters func (vcd *TestVCD) Test_VdcNetworkProfile(check *C) { skipNoNsxtConfiguration(vcd, check) @@ -22,39 +20,33 @@ func (vcd *TestVCD) Test_VdcNetworkProfile(check *C) { check.Assert(err, IsNil) check.Assert(existingVdcNetworkProfile, NotNil) - spew.Dump(existingVdcNetworkProfile) - // Lookup Edge available Edge Cluster - allEdgeClusters, err := nsxtVdc.GetAllNsxtEdgeClusters(nil) + edgeCluster, err := nsxtVdc.GetNsxtEdgeClusterByName(vcd.config.VCD.Nsxt.NsxtEdgeCluster) check.Assert(err, IsNil) - check.Assert(allEdgeClusters, NotNil) + check.Assert(edgeCluster, NotNil) networkProfileConfig := &types.VdcNetworkProfile{ ServicesEdgeCluster: &types.VdcNetworkProfileServicesEdgeCluster{ - BackingID: allEdgeClusters[0].NsxtEdgeCluster.ID, + BackingID: edgeCluster.NsxtEdgeCluster.ID, }, } newVdcNetworkProfile, err := nsxtVdc.UpdateVdcNetworkProfile(networkProfileConfig) check.Assert(err, IsNil) check.Assert(newVdcNetworkProfile, NotNil) - check.Assert(newVdcNetworkProfile.ServicesEdgeCluster.BackingID, Equals, allEdgeClusters[0].NsxtEdgeCluster.ID) - - // Try to unset the value - - unsetNetworkProfileConfig := &types.VdcNetworkProfile{ - ServicesEdgeCluster: &types.VdcNetworkProfileServicesEdgeCluster{}, - VdcNetworkSegmentProfileTemplateRef: &types.OpenApiReferenceEE{ID: ""}, - } - spew.Dump(unsetNetworkProfileConfig) + check.Assert(newVdcNetworkProfile.ServicesEdgeCluster.BackingID, Equals, edgeCluster.NsxtEdgeCluster.ID) + // Unset Edge Cluster (and other values) by sending empty structure + unsetNetworkProfileConfig := &types.VdcNetworkProfile{} unsetVdcNetworkProfile, err := nsxtVdc.UpdateVdcNetworkProfile(unsetNetworkProfileConfig) check.Assert(err, IsNil) check.Assert(unsetVdcNetworkProfile, NotNil) + networkProfileAfterCleanup, err := nsxtVdc.GetVdcNetworkProfile() + check.Assert(err, IsNil) + check.Assert(networkProfileAfterCleanup.ServicesEdgeCluster, IsNil) // Cleanup - // err = nsxtVdc.DeleteVdcNetworkProfile() - // check.Assert(err, IsNil) - + err = nsxtVdc.DeleteVdcNetworkProfile() + check.Assert(err, IsNil) } diff --git a/types/v56/nsxt_types.go b/types/v56/nsxt_types.go index 36e650d2f..45afddc46 100644 --- a/types/v56/nsxt_types.go +++ b/types/v56/nsxt_types.go @@ -1,5 +1,7 @@ package types +import "encoding/json" + // OpenAPIEdgeGateway structure supports marshalling both - NSX-V and NSX-T edge gateways as returned by OpenAPI // endpoint (cloudapi/1.0.0edgeGateways/), but the endpoint only allows users to create NSX-T edge gateways. type OpenAPIEdgeGateway struct { @@ -1455,8 +1457,9 @@ type EdgeBgpConfigVersion struct { // VdcNetworkProfile defines a VDC Network Profile. // -// All fields are optional. They do not have `omitempty` struct tags as sending a `null` value for -// particular fields will ignore overriding existing value. +// All fields are optional. They have `omitempty` to ignore overriding values for some fields. In +// case there is a need to unset particular value - one can send empty `OpenApiReferenceEmpty` which +// does not have `omitempty` on its fields. type VdcNetworkProfile struct { // PrimaryEdgeCluster defines NSX-V Edge Cluster where the primary appliance for an NSX-V Edge // Gateway will be deployed. (NSX-V only) @@ -1474,12 +1477,14 @@ type VdcNetworkProfile struct { // be used when any new vApp Network is created under this VDC. Setting this will override any // global level vApp Network Segment Profile Template. This field is only applicable for (NSX-T // only) - VappNetworkSegmentProfileTemplateRef *OpenApiReferenceEE `json:"vappNetworkSegmentProfileTemplateRef,omitempty"` + // VCD 10.3.2+ (API 36.2+) + VappNetworkSegmentProfileTemplateRef *OpenApiReference `json:"vappNetworkSegmentProfileTemplateRef,omitempty"` // VdcNetworkSegmentProfileTemplateRef defines Org vDC Network Segment Profile Template that is // to be used when any new Org vDC Network is created under this VDC. Setting this will override // any global level Org vDC Network Segment Profile Template. (NSX-T only) - VdcNetworkSegmentProfileTemplateRef *OpenApiReferenceEE `json:"vdcNetworkSegmentProfileTemplateRef,omitempty"` + // VCD 10.3.2+ (API 36.2+) + VdcNetworkSegmentProfileTemplateRef *OpenApiReference `json:"vdcNetworkSegmentProfileTemplateRef,omitempty"` } // VdcNetworkProfileServicesEdgeCluster contains reference to NSX-T Edge Cluster used in @@ -1489,7 +1494,92 @@ type VdcNetworkProfileServicesEdgeCluster struct { EdgeClusterRef *OpenApiReference `json:"edgeClusterRef,omitempty"` } -type OpenApiReferenceEE struct { - Name string `json:"name"` +// OpenApiReferenceNullOnEmpty is like OpenApiReference but its Marshalling behavior is altered +// using pointer receiver MarshalJSON which implements Marshaler interface and is able to modify +// Marshaling behavior for this type to match VCD API requirement +// +// There is a need to handle 3 cases: +// 1. Be able to send an OpenApi reference so that it can be set on VCD (normal behavior when values +// are properly set) +// +// 2. Be able to send JSON "null" value for some reference to remove their configuration from VCD +// (this is where default implementation falls short, and this type with modified behavior is +// required) +// +// 3. Be able to avoid sending a value at all (omitempty tag). Mainly to support scenario where +// particular VCD version did not yet support a field and sending it could cause VCD validation +// error +// +// Below is an example of how it would work in a sample structure: +// +// Given a sample type: +// +// type VdcNetworkProfile struct { +// PrimaryEdgeCluster *OpenApiReference `json:"primaryEdgeCluster,omitempty"` +// VappNetworkSegmentProfileTemplateRef *OpenApiReferenceNullOnEmpty `json:"vappNetworkSegmentProfileTemplateRef,omitempty"` +// } +// +// Case 1 - Send OpenAPI references (works with both types OpenApiReference and OpenApiReferenceNullOnEmpty) +// Type definition: +// +// t := &VdcNetworkProfile{ +// PrimaryEdgeCluster: &types.OpenApiReference{ +// Name: "edge-cluster-1", +// ID: "XXXXXXXX", +// }, +// VappNetworkSegmentProfileTemplateRef: &types.OpenApiReferenceNullOnEmpty{ +// Name: "manual-template-1", +// ID: "urn:vcloud:segmentProfileTemplate:fbf270e4-ae1c-4c46-ae78-cca13c75eb75", +// } +// } +// +// Marshals to: +// +// { +// "primaryEdgeCluster": { +// "name": "edge-cluster-1", +// "id" : "XXXXXXXX", +// }, +// "vdcNetworkSegmentProfileTemplateRef": { +// "name": "manual-template-1", +// "id": "urn:vcloud:segmentProfileTemplate:fbf270e4-ae1c-4c46-ae78-cca13c75eb75" +// } +// } +// +// Case 2 - send JSON "null" value for some reference to remove their configuration from VCD (does not work with OpenApiReference type) +// Type definition: +// +// t := &VdcNetworkProfile{ +// PrimaryEdgeCluster: &types.OpenApiReference{}, +// VappNetworkSegmentProfileTemplateRef: &types.OpenApiReferenceNullOnEmpty{} +// } +// +// Marshals to: +// +// { +// "primaryEdgeCluster" : {}, <----------- This is the part that makes VCD validation break +// "vdcNetworkSegmentProfileTemplateRef": null <----------- `null` works fine and removes value from configuration +// } +// +// Case 3 - Do not send value at all using `omitempty` (to support VCD versions that don't have this field yet) +// Type definition: +// t := &VdcNetworkProfile{} +// +// Marshals to: +// {} +type OpenApiReferenceNullOnEmpty struct { ID string `json:"id"` + Name string `json:"name"` +} + +// MarshalJSON handles marshaling a bit differently than original json.Marshal. This function is +// automatically invoked by json.Marshal as it implements Marshaler interface It check of both `ID“ +// and `Name` fields are empty and then immediatelly returns 'null' while Go native Marshaller would +// return empty string object {} +func (o *OpenApiReferenceNullOnEmpty) MarshalJSON() ([]byte, error) { + if o.ID == "" && o.Name == "" { + return []byte("null"), nil + } + type ref2 OpenApiReferenceNullOnEmpty + return json.Marshal((*ref2)(o)) } diff --git a/types/v56/openapi.go b/types/v56/openapi.go index 2ac05c705..13b84470d 100644 --- a/types/v56/openapi.go +++ b/types/v56/openapi.go @@ -216,6 +216,16 @@ type OpenApiReference struct { ID string `json:"id,omitempty"` } +// OpenApiReferenceEmpty is like OpenApiReference but it does not have `omitempty` tags and would +// still be sent if no values are specified. +// +// This is helpful in strucutres which use `null` value to ignore the change for particular field, +// but accepts empty values to unset it +type OpenApiReferenceEmpty struct { + ID string `json:"id"` + Name string `json:"name"` +} + type OpenApiReferences []OpenApiReference // VdcCapability can be used to determine VDC capabilities, including such: diff --git a/util/logging.go b/util/logging.go index 7c00ded86..dab563945 100644 --- a/util/logging.go +++ b/util/logging.go @@ -152,12 +152,6 @@ func SetLog() { } else { Logger = newLogger(ApiLogFileName) } - if len(skipTags) > 0 { - Logger.Printf("### WILL SKIP THE FOLLOWING TAGS: %+v", skipTags) - } - if len(apiLogFunctions) > 0 { - Logger.Printf("### WILL ONLY INCLUDE API LOGS FROM THE FOLLOWING FUNCTIONS: %+v", apiLogFunctions) - } } // hideSensitive hides passwords, tokens, and certificate details From 69d4f9ce22348f4619038e071d239736b22e9567 Mon Sep 17 00:00:00 2001 From: Dainius Serplis Date: Fri, 21 Oct 2022 11:51:57 +0300 Subject: [PATCH 03/11] Cleanup Signed-off-by: Dainius Serplis --- types/v56/nsxt_types.go | 92 ----------------------------------------- types/v56/openapi.go | 10 ----- 2 files changed, 102 deletions(-) diff --git a/types/v56/nsxt_types.go b/types/v56/nsxt_types.go index 45afddc46..cf80986f8 100644 --- a/types/v56/nsxt_types.go +++ b/types/v56/nsxt_types.go @@ -1,7 +1,5 @@ package types -import "encoding/json" - // OpenAPIEdgeGateway structure supports marshalling both - NSX-V and NSX-T edge gateways as returned by OpenAPI // endpoint (cloudapi/1.0.0edgeGateways/), but the endpoint only allows users to create NSX-T edge gateways. type OpenAPIEdgeGateway struct { @@ -1493,93 +1491,3 @@ type VdcNetworkProfileServicesEdgeCluster struct { BackingID string `json:"backingId"` EdgeClusterRef *OpenApiReference `json:"edgeClusterRef,omitempty"` } - -// OpenApiReferenceNullOnEmpty is like OpenApiReference but its Marshalling behavior is altered -// using pointer receiver MarshalJSON which implements Marshaler interface and is able to modify -// Marshaling behavior for this type to match VCD API requirement -// -// There is a need to handle 3 cases: -// 1. Be able to send an OpenApi reference so that it can be set on VCD (normal behavior when values -// are properly set) -// -// 2. Be able to send JSON "null" value for some reference to remove their configuration from VCD -// (this is where default implementation falls short, and this type with modified behavior is -// required) -// -// 3. Be able to avoid sending a value at all (omitempty tag). Mainly to support scenario where -// particular VCD version did not yet support a field and sending it could cause VCD validation -// error -// -// Below is an example of how it would work in a sample structure: -// -// Given a sample type: -// -// type VdcNetworkProfile struct { -// PrimaryEdgeCluster *OpenApiReference `json:"primaryEdgeCluster,omitempty"` -// VappNetworkSegmentProfileTemplateRef *OpenApiReferenceNullOnEmpty `json:"vappNetworkSegmentProfileTemplateRef,omitempty"` -// } -// -// Case 1 - Send OpenAPI references (works with both types OpenApiReference and OpenApiReferenceNullOnEmpty) -// Type definition: -// -// t := &VdcNetworkProfile{ -// PrimaryEdgeCluster: &types.OpenApiReference{ -// Name: "edge-cluster-1", -// ID: "XXXXXXXX", -// }, -// VappNetworkSegmentProfileTemplateRef: &types.OpenApiReferenceNullOnEmpty{ -// Name: "manual-template-1", -// ID: "urn:vcloud:segmentProfileTemplate:fbf270e4-ae1c-4c46-ae78-cca13c75eb75", -// } -// } -// -// Marshals to: -// -// { -// "primaryEdgeCluster": { -// "name": "edge-cluster-1", -// "id" : "XXXXXXXX", -// }, -// "vdcNetworkSegmentProfileTemplateRef": { -// "name": "manual-template-1", -// "id": "urn:vcloud:segmentProfileTemplate:fbf270e4-ae1c-4c46-ae78-cca13c75eb75" -// } -// } -// -// Case 2 - send JSON "null" value for some reference to remove their configuration from VCD (does not work with OpenApiReference type) -// Type definition: -// -// t := &VdcNetworkProfile{ -// PrimaryEdgeCluster: &types.OpenApiReference{}, -// VappNetworkSegmentProfileTemplateRef: &types.OpenApiReferenceNullOnEmpty{} -// } -// -// Marshals to: -// -// { -// "primaryEdgeCluster" : {}, <----------- This is the part that makes VCD validation break -// "vdcNetworkSegmentProfileTemplateRef": null <----------- `null` works fine and removes value from configuration -// } -// -// Case 3 - Do not send value at all using `omitempty` (to support VCD versions that don't have this field yet) -// Type definition: -// t := &VdcNetworkProfile{} -// -// Marshals to: -// {} -type OpenApiReferenceNullOnEmpty struct { - ID string `json:"id"` - Name string `json:"name"` -} - -// MarshalJSON handles marshaling a bit differently than original json.Marshal. This function is -// automatically invoked by json.Marshal as it implements Marshaler interface It check of both `ID“ -// and `Name` fields are empty and then immediatelly returns 'null' while Go native Marshaller would -// return empty string object {} -func (o *OpenApiReferenceNullOnEmpty) MarshalJSON() ([]byte, error) { - if o.ID == "" && o.Name == "" { - return []byte("null"), nil - } - type ref2 OpenApiReferenceNullOnEmpty - return json.Marshal((*ref2)(o)) -} diff --git a/types/v56/openapi.go b/types/v56/openapi.go index 13b84470d..2ac05c705 100644 --- a/types/v56/openapi.go +++ b/types/v56/openapi.go @@ -216,16 +216,6 @@ type OpenApiReference struct { ID string `json:"id,omitempty"` } -// OpenApiReferenceEmpty is like OpenApiReference but it does not have `omitempty` tags and would -// still be sent if no values are specified. -// -// This is helpful in strucutres which use `null` value to ignore the change for particular field, -// but accepts empty values to unset it -type OpenApiReferenceEmpty struct { - ID string `json:"id"` - Name string `json:"name"` -} - type OpenApiReferences []OpenApiReference // VdcCapability can be used to determine VDC capabilities, including such: From 184ca8d500ae9ba61ae6a7168636e66fff236332 Mon Sep 17 00:00:00 2001 From: Dainius Serplis Date: Fri, 21 Oct 2022 12:09:40 +0300 Subject: [PATCH 04/11] Improve tst Signed-off-by: Dainius Serplis --- .changes/v2.17.0/XXX-improvements.md | 2 ++ govcd/nsxt_edge_cluster.go | 13 ++++++++++--- govcd/nsxt_edge_cluster_test.go | 16 +++++++--------- govcd/openapi_endpoints.go | 2 +- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/.changes/v2.17.0/XXX-improvements.md b/.changes/v2.17.0/XXX-improvements.md index 04f6238a4..b82841113 100644 --- a/.changes/v2.17.0/XXX-improvements.md +++ b/.changes/v2.17.0/XXX-improvements.md @@ -1,5 +1,7 @@ * Added VCDClient.GetAllNsxtEdgeClusters for lookup of NSX-T Edge Clusters in wider scopes - Provider VDC, VDC Group or VDC [GH-XXX] +* Switch VDC.GetAllNsxtEdgeClusters to use 'orgVdcId' filter instead of '_context' (now deprecated) + [GH-XXX] * Removed a few log lines from SetLog() function which were being set before correct logging file was initialized. This resulted in a file `go-vcloud-director.log` even if other filename was used [GH-XXX] diff --git a/govcd/nsxt_edge_cluster.go b/govcd/nsxt_edge_cluster.go index e01c11935..382806c51 100644 --- a/govcd/nsxt_edge_cluster.go +++ b/govcd/nsxt_edge_cluster.go @@ -90,9 +90,16 @@ func (vdc *Vdc) GetAllNsxtEdgeClusters(queryParameters url.Values) ([]*NsxtEdgeC // GetAllNsxtEdgeClusters retrieves all NSX-T Edge Clusters in the system // -// orgVdcId - | The filter orgVdcId must be set equal to the id of the NSX-T backed Org vDC for which we want to get the edge clusters. Example: (orgVdcId==urn:vcloud:vdc:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx) -// vdcGroupId - | The filter vdcGroupId must be set equal to the id of the NSX-T VDC Group for which we want to get the edge clusters. Example: (vdcGroupId==urn:vcloud:vdcGroup:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx) -// pvdcId - | The filter pvdcId must be set equal to the id of the NSX-T backed Provider VDC for which we want to get the edge clusters. pvdcId filter is supported from version 35.2 Example: (pvdcId==urn:vcloud:providervdc:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx) +// A filter is mandatory as otherwise request will fail +// orgVdcId - | The filter orgVdcId must be set equal to the id of the NSX-T backed Org vDC for +// which we want to get the edge clusters. Example: +// (orgVdcId==urn:vcloud:vdc:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx) +// vdcGroupId - | The filter vdcGroupId must be set equal to the id of the NSX-T VDC Group for which +// we want to get the edge clusters. Example: +// (vdcGroupId==urn:vcloud:vdcGroup:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx) +// pvdcId - | The filter pvdcId must be set equal to the id of the NSX-T backed Provider VDC for +// which we want to get the edge clusters. pvdcId filter is supported from version 35.2 Example: +// (pvdcId==urn:vcloud:providervdc:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx) func (vcdClient *VCDClient) GetAllNsxtEdgeClusters(queryParameters url.Values) ([]*NsxtEdgeCluster, error) { return getAllNsxtEdgeClusters(&vcdClient.Client, queryParameters) } diff --git a/govcd/nsxt_edge_cluster_test.go b/govcd/nsxt_edge_cluster_test.go index 4eccad501..67bfdee6e 100644 --- a/govcd/nsxt_edge_cluster_test.go +++ b/govcd/nsxt_edge_cluster_test.go @@ -9,6 +9,7 @@ package govcd import ( "fmt" + "net/url" . "gopkg.in/check.v1" ) @@ -28,11 +29,12 @@ func (vcd *TestVCD) Test_GetAllNsxtEdgeClusters(check *C) { check.Assert(edgeClusters, NotNil) check.Assert(len(edgeClusters) > 0, Equals, true) - allEdgeClusters, err := vcd.client.GetAllNsxtEdgeClusters(nil) + queryParams := url.Values{} + queryParams.Add("filter", fmt.Sprintf("orgVdcId==%s", nsxtVdc.Vdc.ID)) + allEdgeClusters, err := vcd.client.GetAllNsxtEdgeClusters(queryParams) check.Assert(err, IsNil) check.Assert(allEdgeClusters, NotNil) check.Assert(len(allEdgeClusters) > 0, Equals, true) - } func (vcd *TestVCD) Test_GetNsxtEdgeClusterByName(check *C) { @@ -45,13 +47,9 @@ func (vcd *TestVCD) Test_GetNsxtEdgeClusterByName(check *C) { nsxtVdc, err := vcd.org.GetVDCByNameOrId(vcd.config.VCD.Nsxt.Vdc, true) check.Assert(err, IsNil) - allEdgeClusters, err := nsxtVdc.GetAllNsxtEdgeClusters(nil) + edgeCluster, err := nsxtVdc.GetNsxtEdgeClusterByName(vcd.config.VCD.Nsxt.NsxtEdgeCluster) check.Assert(err, IsNil) - check.Assert(allEdgeClusters, NotNil) - - edgeCluster, err := nsxtVdc.GetNsxtEdgeClusterByName(allEdgeClusters[0].NsxtEdgeCluster.Name) - check.Assert(err, IsNil) - check.Assert(allEdgeClusters, NotNil) - check.Assert(edgeCluster, DeepEquals, allEdgeClusters[0]) + check.Assert(edgeCluster, NotNil) + check.Assert(edgeCluster.NsxtEdgeCluster.Name, Equals, vcd.config.VCD.Nsxt.NsxtEdgeCluster) } diff --git a/govcd/openapi_endpoints.go b/govcd/openapi_endpoints.go index 4db35cbeb..be84235ce 100644 --- a/govcd/openapi_endpoints.go +++ b/govcd/openapi_endpoints.go @@ -124,7 +124,7 @@ var endpointElevatedApiVersions = map[string][]string{ }, types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointVdcNetworkProfile: { //"36.0", // Introduced support - "36.2", // + "36.2", // 2 additional fields vappNetworkSegmentProfileTemplateRef and vdcNetworkSegmentProfileTemplateRef added }, } From 489de875e29cdee5cee93ab9fd4bf09a794a3e5d Mon Sep 17 00:00:00 2001 From: Dainius Serplis Date: Tue, 25 Oct 2022 10:19:03 +0300 Subject: [PATCH 05/11] Move function Signed-off-by: Dainius Serplis --- .../v2.17.0/{XXX-improvements.md => 512-improvements.md} | 6 +++--- util/logging.go | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) rename .changes/v2.17.0/{XXX-improvements.md => 512-improvements.md} (85%) diff --git a/.changes/v2.17.0/XXX-improvements.md b/.changes/v2.17.0/512-improvements.md similarity index 85% rename from .changes/v2.17.0/XXX-improvements.md rename to .changes/v2.17.0/512-improvements.md index b82841113..6c56c5ac8 100644 --- a/.changes/v2.17.0/XXX-improvements.md +++ b/.changes/v2.17.0/512-improvements.md @@ -1,7 +1,7 @@ * Added VCDClient.GetAllNsxtEdgeClusters for lookup of NSX-T Edge Clusters in wider scopes - - Provider VDC, VDC Group or VDC [GH-XXX] + Provider VDC, VDC Group or VDC [GH-512] * Switch VDC.GetAllNsxtEdgeClusters to use 'orgVdcId' filter instead of '_context' (now deprecated) - [GH-XXX] + [GH-512] * Removed a few log lines from SetLog() function which were being set before correct logging file was initialized. This resulted in a file `go-vcloud-director.log` even if other filename was used - [GH-XXX] + [GH-512] diff --git a/util/logging.go b/util/logging.go index dab563945..a0362d6a6 100644 --- a/util/logging.go +++ b/util/logging.go @@ -103,6 +103,10 @@ var ( hashLine string = strings.Repeat("#", lineLength) ) +func init() { + InitLogging() +} + // TogglePanicEmptyUserAgent allows to enable Panic in test if HTTP User-Agent is missing. This // generally is useful in tests and is off by default. func TogglePanicEmptyUserAgent(willPanic bool) { @@ -409,10 +413,6 @@ func InitLogging() { SetLog() } -func init() { - InitLogging() -} - // Returns the name of the function that called the // current function. // Used by functions that call processResponseOutput and From 65ef692324a04fd6dba2171c84492c688a62dc49 Mon Sep 17 00:00:00 2001 From: Dainius Serplis Date: Tue, 25 Oct 2022 10:27:03 +0300 Subject: [PATCH 06/11] revert --- .changes/v2.17.0/512-improvements.md | 3 --- util/logging.go | 14 ++++++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.changes/v2.17.0/512-improvements.md b/.changes/v2.17.0/512-improvements.md index 6c56c5ac8..549d0e0bc 100644 --- a/.changes/v2.17.0/512-improvements.md +++ b/.changes/v2.17.0/512-improvements.md @@ -2,6 +2,3 @@ Provider VDC, VDC Group or VDC [GH-512] * Switch VDC.GetAllNsxtEdgeClusters to use 'orgVdcId' filter instead of '_context' (now deprecated) [GH-512] -* Removed a few log lines from SetLog() function which were being set before correct logging file - was initialized. This resulted in a file `go-vcloud-director.log` even if other filename was used - [GH-512] diff --git a/util/logging.go b/util/logging.go index a0362d6a6..7c00ded86 100644 --- a/util/logging.go +++ b/util/logging.go @@ -103,10 +103,6 @@ var ( hashLine string = strings.Repeat("#", lineLength) ) -func init() { - InitLogging() -} - // TogglePanicEmptyUserAgent allows to enable Panic in test if HTTP User-Agent is missing. This // generally is useful in tests and is off by default. func TogglePanicEmptyUserAgent(willPanic bool) { @@ -156,6 +152,12 @@ func SetLog() { } else { Logger = newLogger(ApiLogFileName) } + if len(skipTags) > 0 { + Logger.Printf("### WILL SKIP THE FOLLOWING TAGS: %+v", skipTags) + } + if len(apiLogFunctions) > 0 { + Logger.Printf("### WILL ONLY INCLUDE API LOGS FROM THE FOLLOWING FUNCTIONS: %+v", apiLogFunctions) + } } // hideSensitive hides passwords, tokens, and certificate details @@ -413,6 +415,10 @@ func InitLogging() { SetLog() } +func init() { + InitLogging() +} + // Returns the name of the function that called the // current function. // Used by functions that call processResponseOutput and From 2f9c60fd8958171d4e52fcaf1c971394d03f5277 Mon Sep 17 00:00:00 2001 From: Dainius Serplis Date: Tue, 25 Oct 2022 10:36:44 +0300 Subject: [PATCH 07/11] Self review Signed-off-by: Dainius Serplis --- types/v56/nsxt_types.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/types/v56/nsxt_types.go b/types/v56/nsxt_types.go index cf80986f8..9aa239cc8 100644 --- a/types/v56/nsxt_types.go +++ b/types/v56/nsxt_types.go @@ -1455,9 +1455,8 @@ type EdgeBgpConfigVersion struct { // VdcNetworkProfile defines a VDC Network Profile. // -// All fields are optional. They have `omitempty` to ignore overriding values for some fields. In -// case there is a need to unset particular value - one can send empty `OpenApiReferenceEmpty` which -// does not have `omitempty` on its fields. +// All fields are optional, but omiting them will reset value. The general approach while updating +// VdcNetworkProfile should be to retrieve existing configuration and mutate it. type VdcNetworkProfile struct { // PrimaryEdgeCluster defines NSX-V Edge Cluster where the primary appliance for an NSX-V Edge // Gateway will be deployed. (NSX-V only) From 8c55e610a69c821928ff273d48cfe5ec05b41412 Mon Sep 17 00:00:00 2001 From: Dainius Serplis Date: Thu, 27 Oct 2022 11:50:41 +0300 Subject: [PATCH 08/11] Address comment Signed-off-by: Dainius Serplis --- govcd/vdc_network_profile.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/govcd/vdc_network_profile.go b/govcd/vdc_network_profile.go index 6cd75f597..773e55be4 100644 --- a/govcd/vdc_network_profile.go +++ b/govcd/vdc_network_profile.go @@ -36,7 +36,7 @@ func (adminVdc *AdminVdc) GetVdcNetworkProfile() (*types.VdcNetworkProfile, erro // UpdateVdcNetworkProfile updates the VDC Network Profile configuration // // Note. Whenever updating VDC Network Profile it is required to send all fields (not only the -// change one) as VCD will remove other configuration. Best practice is to fetch current +// changed ones) as VCD will remove other configuration. Best practice is to fetch current // configuration of VDC Network Profile using GetVdcNetworkProfile, alter it with new values and // submit it to UpdateVdcNetworkProfile. func (vdc *Vdc) UpdateVdcNetworkProfile(vdcNetworkProfileConfig *types.VdcNetworkProfile) (*types.VdcNetworkProfile, error) { From 9c0d086e1a3c2c2b7172953705c2d7044eca88c8 Mon Sep 17 00:00:00 2001 From: Dainius Serplis Date: Tue, 8 Nov 2022 13:02:24 +0200 Subject: [PATCH 09/11] Add new details to DHCP type Signed-off-by: Dainius Serplis --- types/v56/nsxt_types.go | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/types/v56/nsxt_types.go b/types/v56/nsxt_types.go index 4eb949fd1..cde1e2454 100644 --- a/types/v56/nsxt_types.go +++ b/types/v56/nsxt_types.go @@ -201,28 +201,36 @@ type NsxtImportableSwitch = OpenApiReference // OpenApiOrgVdcNetworkDhcp allows users to manage DHCP configuration for Org VDC networks by using OpenAPI endpoint type OpenApiOrgVdcNetworkDhcp struct { - Enabled *bool `json:"enabled,omitempty"` + Enabled *bool `json:"enabled,omitempty"` + + // LeaseTime specifies the amount of time in seconds of how long a DHCP IP will be leased out + // for. The minimum is 60s while the maximum is 4,294,967,295s, which is roughly 49,710 days. LeaseTime *int `json:"leaseTime,omitempty"` DhcpPools []OpenApiOrgVdcNetworkDhcpPools `json:"dhcpPools,omitempty"` + // Mode describes how the DHCP service is configured for this network. Once a DHCP service has been created, the mode // attribute cannot be changed. The mode field will default to 'EDGE' if it is not provided. This field only applies // to networks backed by an NSX-T network provider. // - // The supported values are EDGE (default) and NETWORK. + // The supported values are EDGE ,NETWORK and RELAY (VCD 10.3.1+, API 36.1+). // * If EDGE is specified, the DHCP service of the edge is used to obtain DHCP IPs. - // * If NETWORK is specified, a DHCP server is created for use by this network. (To use NETWORK + // * If NETWORK is specified, a DHCP server is created for use by this network. + // * If RELAY is specified, all the DHCP client requests will be relayed to Gateway DHCP + // Forwarder service. This mode is only supported for Routed Org vDC Networks. // - // In order to use DHCP for IPV6, NETWORK mode must be used. Routed networks which are using NETWORK DHCP services can - // be disconnected from the edge gateway and still retain their DHCP configuration, however network using EDGE DHCP - // cannot be disconnected from the gateway until DHCP has been disabled. + // In order to use DHCP for IPV6, NETWORK mode must be used. Routed networks which are using + // NETWORK DHCP services can be disconnected from the edge gateway and still retain their DHCP + // configuration, however DHCP configuration will be removed during connection change for + // networks using EDGE or RELAY DHCP mode. Mode string `json:"mode,omitempty"` + // IPAddress is only applicable when mode=NETWORK. This will specify IP address of DHCP server in network. IPAddress string `json:"ipAddress,omitempty"` // New fields starting with 36.1 - // DnsServers are the IPs to be assigned by this DHCP service. The IP type must match the IP type of the subnet on - // which the DHCP config is being created. + // DnsServers are the IPs to be assigned by this DHCP service. The IP type must match the IP + // type of the subnet on which the DHCP config is being created. DnsServers []string `json:"dnsServers,omitempty"` } From 8727a0593678aeb3b656de715b5f709fc20437a1 Mon Sep 17 00:00:00 2001 From: Dainius Serplis Date: Fri, 11 Nov 2022 10:25:37 +0200 Subject: [PATCH 10/11] Changelog and tests Signed-off-by: Dainius Serplis --- .changes/v2.17.0/505-improvements.md | 2 +- .changes/v2.17.0/517-notes.md | 1 + govcd/openapi_org_network_test.go | 103 ++++++++++++++++++++++----- 3 files changed, 86 insertions(+), 20 deletions(-) create mode 100644 .changes/v2.17.0/517-notes.md diff --git a/.changes/v2.17.0/505-improvements.md b/.changes/v2.17.0/505-improvements.md index bdd945f40..6ebaaee2b 100644 --- a/.changes/v2.17.0/505-improvements.md +++ b/.changes/v2.17.0/505-improvements.md @@ -1 +1 @@ -* Simplify `Test_LDAP` by using a pre-configured LDAP server [GH-505] +* Simplify `Test_LDAP` by using a pre-configured LDAP server [GH-505] \ No newline at end of file diff --git a/.changes/v2.17.0/517-notes.md b/.changes/v2.17.0/517-notes.md new file mode 100644 index 000000000..7f0385a9a --- /dev/null +++ b/.changes/v2.17.0/517-notes.md @@ -0,0 +1 @@ +* Improve documentation for `types.OpenApiOrgVdcNetworkDhcp` [GH-517] diff --git a/govcd/openapi_org_network_test.go b/govcd/openapi_org_network_test.go index ac0357dbb..cdf620a5c 100644 --- a/govcd/openapi_org_network_test.go +++ b/govcd/openapi_org_network_test.go @@ -21,10 +21,7 @@ func (vcd *TestVCD) Test_NsxtOrgVdcNetworkIsolated(check *C) { orgVdcNetworkConfig := &types.OpenApiOrgVdcNetwork{ Name: check.TestName(), Description: check.TestName() + "-description", - - // On v35.0 orgVdc is not supported anymore. Using ownerRef instead. - OwnerRef: &types.OpenApiReference{ID: vcd.nsxtVdc.Vdc.ID}, - + OwnerRef: &types.OpenApiReference{ID: vcd.nsxtVdc.Vdc.ID}, NetworkType: types.OrgVdcNetworkTypeIsolated, Subnets: types.OrgVdcNetworkSubnets{ Values: []types.OrgVdcNetworkSubnetValues{ @@ -54,8 +51,8 @@ func (vcd *TestVCD) Test_NsxtOrgVdcNetworkIsolated(check *C) { }, } - runOpenApiOrgVdcNetworkTest(check, vcd, vcd.nsxtVdc, orgVdcNetworkConfig, types.OrgVdcNetworkTypeIsolated, nil) - runOpenApiOrgVdcNetworkWithVdcGroupTest(check, vcd, orgVdcNetworkConfig, types.OrgVdcNetworkTypeIsolated, nil) + runOpenApiOrgVdcNetworkTest(check, vcd, vcd.nsxtVdc, orgVdcNetworkConfig, types.OrgVdcNetworkTypeIsolated, []dhcpConfigFunc{nsxtDhcpConfigNetworkMode}) + runOpenApiOrgVdcNetworkWithVdcGroupTest(check, vcd, orgVdcNetworkConfig, types.OrgVdcNetworkTypeIsolated, []dhcpConfigFunc{nsxtDhcpConfigNetworkMode}) } func (vcd *TestVCD) Test_NsxtOrgVdcNetworkRouted(check *C) { @@ -68,10 +65,7 @@ func (vcd *TestVCD) Test_NsxtOrgVdcNetworkRouted(check *C) { orgVdcNetworkConfig := &types.OpenApiOrgVdcNetwork{ Name: check.TestName(), Description: check.TestName() + "-description", - - // On v35.0 orgVdc is not supported anymore. Using ownerRef instead. - OwnerRef: &types.OpenApiReference{ID: vcd.nsxtVdc.Vdc.ID}, - + OwnerRef: &types.OpenApiReference{ID: vcd.nsxtVdc.Vdc.ID}, NetworkType: types.OrgVdcNetworkTypeRouted, // Connection is used for "routed" network @@ -115,8 +109,8 @@ func (vcd *TestVCD) Test_NsxtOrgVdcNetworkRouted(check *C) { }, } - runOpenApiOrgVdcNetworkTest(check, vcd, vcd.nsxtVdc, orgVdcNetworkConfig, types.OrgVdcNetworkTypeRouted, nsxtRoutedDhcpConfig) - runOpenApiOrgVdcNetworkWithVdcGroupTest(check, vcd, orgVdcNetworkConfig, types.OrgVdcNetworkTypeRouted, nsxtRoutedDhcpConfig) + runOpenApiOrgVdcNetworkTest(check, vcd, vcd.nsxtVdc, orgVdcNetworkConfig, types.OrgVdcNetworkTypeRouted, []dhcpConfigFunc{nsxtRoutedDhcpConfigEdgeMode, nsxtDhcpConfigNetworkMode}) + runOpenApiOrgVdcNetworkWithVdcGroupTest(check, vcd, orgVdcNetworkConfig, types.OrgVdcNetworkTypeRouted, []dhcpConfigFunc{nsxtRoutedDhcpConfigEdgeMode, nsxtDhcpConfigNetworkMode}) } func (vcd *TestVCD) Test_NsxtOrgVdcNetworkImported(check *C) { @@ -330,7 +324,7 @@ func (vcd *TestVCD) Test_NsxvOrgVdcNetworkDirect(check *C) { runOpenApiOrgVdcNetworkTest(check, vcd, vcd.vdc, orgVdcNetworkConfig, types.OrgVdcNetworkTypeDirect, nil) } -func runOpenApiOrgVdcNetworkTest(check *C, vcd *TestVCD, vdc *Vdc, orgVdcNetworkConfig *types.OpenApiOrgVdcNetwork, expectNetworkType string, dhcpFunc dhcpConfigFunc) { +func runOpenApiOrgVdcNetworkTest(check *C, vcd *TestVCD, vdc *Vdc, orgVdcNetworkConfig *types.OpenApiOrgVdcNetwork, expectNetworkType string, dhcpFunc []dhcpConfigFunc) { orgVdcNet, err := vdc.CreateOpenApiOrgVdcNetwork(orgVdcNetworkConfig) check.Assert(err, IsNil) @@ -370,8 +364,8 @@ func runOpenApiOrgVdcNetworkTest(check *C, vcd *TestVCD, vdc *Vdc, orgVdcNetwork check.Assert(updatedOrgVdcNet.OpenApiOrgVdcNetwork.Description, Equals, orgVdcNet.OpenApiOrgVdcNetwork.Description) // Configure DHCP if specified - if dhcpFunc != nil { - dhcpFunc(check, vcd, vdc, updatedOrgVdcNet.OpenApiOrgVdcNetwork.ID) + for i := range dhcpFunc { + dhcpFunc[i](check, vcd, vdc, updatedOrgVdcNet.OpenApiOrgVdcNetwork.ID) } // Delete err = orgVdcNet.Delete() @@ -387,7 +381,7 @@ func runOpenApiOrgVdcNetworkTest(check *C, vcd *TestVCD, vdc *Vdc, orgVdcNetwork type dhcpConfigFunc func(check *C, vcd *TestVCD, vdc *Vdc, orgNetId string) -func nsxtRoutedDhcpConfig(check *C, vcd *TestVCD, vdc *Vdc, orgNetId string) { +func nsxtRoutedDhcpConfigEdgeMode(check *C, vcd *TestVCD, vdc *Vdc, orgNetId string) { dhcpDefinition := &types.OpenApiOrgVdcNetworkDhcp{ Enabled: takeBoolPointer(true), DhcpPools: []types.OpenApiOrgVdcNetworkDhcpPools{ @@ -435,10 +429,81 @@ func nsxtRoutedDhcpConfig(check *C, vcd *TestVCD, vdc *Vdc, orgNetId string) { check.Assert(err, IsNil) check.Assert(len(deletedDhcp.OpenApiOrgVdcNetworkDhcp.DhcpPools), Equals, 0) check.Assert(len(deletedDhcp.OpenApiOrgVdcNetworkDhcp.DnsServers), Equals, 0) +} + +// nsxtDhcpConfigNetworkMode checks DHCP functionality in NETWORK mode +// It requires that Edge Cluster is set at VDC level therefore this function does it for the +// duration of this test and restores it back +func nsxtDhcpConfigNetworkMode(check *C, vcd *TestVCD, vdc *Vdc, orgNetId string) { + // Only supported in 10.3.1+ + if vdc.client.APIVCDMaxVersionIs("< 36.1") { + return + } + + // DHCP in NETWORK mode requires Edge Cluster to be set for VDC and cleaned up afterwards + edgeCluster, err := vdc.GetNsxtEdgeClusterByName(vcd.config.VCD.Nsxt.NsxtEdgeCluster) + check.Assert(err, IsNil) + vdcNetworkProfile := &types.VdcNetworkProfile{ + ServicesEdgeCluster: &types.VdcNetworkProfileServicesEdgeCluster{ + BackingID: edgeCluster.NsxtEdgeCluster.ID, + }, + } + _, err = vdc.UpdateVdcNetworkProfile(vdcNetworkProfile) + check.Assert(err, IsNil) + defer func() { + err := vdc.DeleteVdcNetworkProfile() + if err != nil { + check.Errorf("error cleaning up VDC Network Profile: %s", err) + } + }() + dhcpDefinition := &types.OpenApiOrgVdcNetworkDhcp{ + Enabled: takeBoolPointer(true), + Mode: "NETWORK", + IPAddress: "2.1.1.252", + DhcpPools: []types.OpenApiOrgVdcNetworkDhcpPools{ + { + Enabled: takeBoolPointer(true), + IPRange: types.OpenApiOrgVdcNetworkDhcpIpRange{ + StartAddress: "2.1.1.200", + EndAddress: "2.1.1.201", + }, + }, + }, + DnsServers: []string{ + "8.8.8.8", + "8.8.4.4", + }, + } + + updatedDhcp, err := vdc.UpdateOpenApiOrgVdcNetworkDhcp(orgNetId, dhcpDefinition) + check.Assert(err, IsNil) + + check.Assert(dhcpDefinition, DeepEquals, updatedDhcp.OpenApiOrgVdcNetworkDhcp) + + err = vdc.DeleteOpenApiOrgVdcNetworkDhcp(orgNetId) + check.Assert(err, IsNil) + + orgVdcNetwork, err := vcd.org.GetOpenApiOrgVdcNetworkById(orgNetId) + check.Assert(err, IsNil) + check.Assert(orgVdcNetwork, NotNil) + + updatedDhcp2, err := orgVdcNetwork.UpdateDhcp(dhcpDefinition) + check.Assert(err, IsNil) + check.Assert(updatedDhcp2, NotNil) + + check.Assert(dhcpDefinition, DeepEquals, updatedDhcp2.OpenApiOrgVdcNetworkDhcp) + + err = orgVdcNetwork.DeletNetworkDhcp() + check.Assert(err, IsNil) + + deletedDhcp, err := orgVdcNetwork.GetOpenApiOrgVdcNetworkDhcp() + check.Assert(err, IsNil) + check.Assert(len(deletedDhcp.OpenApiOrgVdcNetworkDhcp.DhcpPools), Equals, 0) + check.Assert(len(deletedDhcp.OpenApiOrgVdcNetworkDhcp.DnsServers), Equals, 0) } -func runOpenApiOrgVdcNetworkWithVdcGroupTest(check *C, vcd *TestVCD, orgVdcNetworkConfig *types.OpenApiOrgVdcNetwork, expectNetworkType string, dhcpFunc dhcpConfigFunc) { +func runOpenApiOrgVdcNetworkWithVdcGroupTest(check *C, vcd *TestVCD, orgVdcNetworkConfig *types.OpenApiOrgVdcNetwork, expectNetworkType string, dhcpFunc []dhcpConfigFunc) { adminOrg, err := vcd.client.GetAdminOrgByName(vcd.config.VCD.Org) check.Assert(err, IsNil) @@ -525,8 +590,8 @@ func runOpenApiOrgVdcNetworkWithVdcGroupTest(check *C, vcd *TestVCD, orgVdcNetwo check.Assert(updatedOrgVdcNet.OpenApiOrgVdcNetwork.Description, Equals, orgVdcNet.OpenApiOrgVdcNetwork.Description) // Configure DHCP if specified - if dhcpFunc != nil { - dhcpFunc(check, vcd, vdc, updatedOrgVdcNet.OpenApiOrgVdcNetwork.ID) + for i := range dhcpFunc { + dhcpFunc[i](check, vcd, vdc, updatedOrgVdcNet.OpenApiOrgVdcNetwork.ID) } // Delete err = orgVdcNet.Delete() From ab4b367fdcea0b5c04b0f25a7c192affc8f4cba5 Mon Sep 17 00:00:00 2001 From: Dainius Serplis Date: Tue, 15 Nov 2022 12:30:06 +0200 Subject: [PATCH 11/11] Address comments Signed-off-by: Dainius Serplis --- govcd/openapi_org_network_test.go | 2 +- types/v56/nsxt_types.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/govcd/openapi_org_network_test.go b/govcd/openapi_org_network_test.go index cdf620a5c..68e9eef80 100644 --- a/govcd/openapi_org_network_test.go +++ b/govcd/openapi_org_network_test.go @@ -431,7 +431,7 @@ func nsxtRoutedDhcpConfigEdgeMode(check *C, vcd *TestVCD, vdc *Vdc, orgNetId str check.Assert(len(deletedDhcp.OpenApiOrgVdcNetworkDhcp.DnsServers), Equals, 0) } -// nsxtDhcpConfigNetworkMode checks DHCP functionality in NETWORK mode +// nsxtDhcpConfigNetworkMode checks DHCP functionality in NETWORK mode. // It requires that Edge Cluster is set at VDC level therefore this function does it for the // duration of this test and restores it back func nsxtDhcpConfigNetworkMode(check *C, vcd *TestVCD, vdc *Vdc, orgNetId string) { diff --git a/types/v56/nsxt_types.go b/types/v56/nsxt_types.go index b7fc8d3f1..a68e62d39 100644 --- a/types/v56/nsxt_types.go +++ b/types/v56/nsxt_types.go @@ -212,7 +212,7 @@ type OpenApiOrgVdcNetworkDhcp struct { // attribute cannot be changed. The mode field will default to 'EDGE' if it is not provided. This field only applies // to networks backed by an NSX-T network provider. // - // The supported values are EDGE ,NETWORK and RELAY (VCD 10.3.1+, API 36.1+). + // The supported values are EDGE, NETWORK and RELAY (VCD 10.3.1+, API 36.1+). // * If EDGE is specified, the DHCP service of the edge is used to obtain DHCP IPs. // * If NETWORK is specified, a DHCP server is created for use by this network. // * If RELAY is specified, all the DHCP client requests will be relayed to Gateway DHCP