From c679c1b99cc60c9b4be84d02005b84b4bfd74c80 Mon Sep 17 00:00:00 2001 From: Miguel Sama Date: Wed, 25 May 2022 13:30:00 +0200 Subject: [PATCH 01/20] Add route advertisement endpoints Signed-off-by: Miguel Sama --- govcd/openapi_endpoints.go | 1 + types/v56/constants.go | 1 + 2 files changed, 2 insertions(+) diff --git a/govcd/openapi_endpoints.go b/govcd/openapi_endpoints.go index 234d2b679..d3d6dc01e 100644 --- a/govcd/openapi_endpoints.go +++ b/govcd/openapi_endpoints.go @@ -49,6 +49,7 @@ var endpointMinApiVersions = map[string]string{ types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointVdcGroupsDfwPolicies: "35.0", // VCD 10.2+ types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointVdcGroupsDfwDefaultPolicies: "35.0", // VCD 10.2+ types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointSecurityTags: "36.0", // VCD 10.3+ + types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointNsxtRouteAdvertisement: "34.0", // VCD 10.1+ // NSX-T ALB (Advanced/AVI Load Balancer) support was introduced in 10.2 types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointAlbController: "35.0", // VCD 10.2+ diff --git a/types/v56/constants.go b/types/v56/constants.go index d82b6915d..a8e42facf 100644 --- a/types/v56/constants.go +++ b/types/v56/constants.go @@ -373,6 +373,7 @@ const ( OpenApiEndpointVdcGroupsDfwRules = "vdcGroups/%s/dfwPolicies/%s/rules" OpenApiEndpointNetworkContextProfiles = "networkContextProfiles" OpenApiEndpointSecurityTags = "securityTags" + OpenApiEndpointNsxtRouteAdvertisement = "edgeGateways/%s/routing/advertisement" // NSX-T ALB related endpoints From a275c0c047c6fca88bbea28c571f747d26dd540e Mon Sep 17 00:00:00 2001 From: Miguel Sama Date: Wed, 25 May 2022 13:30:21 +0200 Subject: [PATCH 02/20] Add new RouteAdvertisement struct Signed-off-by: Miguel Sama --- types/v56/nsxt_types.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/types/v56/nsxt_types.go b/types/v56/nsxt_types.go index 642fb0c7a..5789b69ac 100644 --- a/types/v56/nsxt_types.go +++ b/types/v56/nsxt_types.go @@ -1244,3 +1244,13 @@ type EntitySecurityTags struct { // Tags is the list of tags. The value is case-agnostic and will be converted to lower-case. Tags []string `json:"tags"` } + +// RouteAdvertisement lists the subnets that will be advertised so that the Edge Gateway can route out to the +// connected external network. +type RouteAdvertisement struct { + // Enable if true, means that the subnets will be advertised. The default is true. + Enable bool + // Subnets is the list of subnets that will be advertised so that the Edge Gateway can route out to the connected + // external network. + Subnets []string +} From bb7fdc61ae36a59715bee912eba9977a68ad5d96 Mon Sep 17 00:00:00 2001 From: Miguel Sama Date: Wed, 25 May 2022 13:30:48 +0200 Subject: [PATCH 03/20] Add scheleton for route advertisement methods Signed-off-by: Miguel Sama --- govcd/nsxt_route_advertisement.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 govcd/nsxt_route_advertisement.go diff --git a/govcd/nsxt_route_advertisement.go b/govcd/nsxt_route_advertisement.go new file mode 100644 index 000000000..454a9ce13 --- /dev/null +++ b/govcd/nsxt_route_advertisement.go @@ -0,0 +1,20 @@ +/* + * Copyright 2022 VMware, Inc. All rights reserved. Licensed under the Apache v2 License. + */ + +package govcd + +import "github.com/vmware/go-vcloud-director/v2/types/v56" + +func (egw *NsxtEdgeGateway) GetNsxtRouteAdvertisement() (*types.RouteAdvertisement, error) { + + return nil, nil +} + +func (egw *NsxtEdgeGateway) UpdateNsxtRouteAdvertisement(enable bool, subnets []string) (*types.RouteAdvertisement, error) { + return nil, nil +} + +func (egw *NsxtEdgeGateway) DeleteNsxtRouteAdvertisement() error { + return nil +} From 03dec16989203796cc7a805b97e6a3938ed959b7 Mon Sep 17 00:00:00 2001 From: Miguel Sama Date: Wed, 25 May 2022 13:31:23 +0200 Subject: [PATCH 04/20] Add sckeleton for route advertisement tests Signed-off-by: Miguel Sama --- govcd/nsxt_route_advertisement_test.go | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 govcd/nsxt_route_advertisement_test.go diff --git a/govcd/nsxt_route_advertisement_test.go b/govcd/nsxt_route_advertisement_test.go new file mode 100644 index 000000000..a84027d45 --- /dev/null +++ b/govcd/nsxt_route_advertisement_test.go @@ -0,0 +1,5 @@ +/* + * Copyright 2022 VMware, Inc. All rights reserved. Licensed under the Apache v2 License. + */ + +package govcd From 62efc64d639a8a4d52c1a827b66fd24c66718ec1 Mon Sep 17 00:00:00 2001 From: Miguel Sama Date: Wed, 25 May 2022 13:55:19 +0200 Subject: [PATCH 05/20] Add docs to RouteAdvertisement Signed-off-by: Miguel Sama --- types/v56/nsxt_types.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/v56/nsxt_types.go b/types/v56/nsxt_types.go index 5789b69ac..99674e17e 100644 --- a/types/v56/nsxt_types.go +++ b/types/v56/nsxt_types.go @@ -1249,8 +1249,8 @@ type EntitySecurityTags struct { // connected external network. type RouteAdvertisement struct { // Enable if true, means that the subnets will be advertised. The default is true. - Enable bool + Enable bool `json:"enable"` // Subnets is the list of subnets that will be advertised so that the Edge Gateway can route out to the connected // external network. - Subnets []string + Subnets []string `json:"subnets"` } From 30004bc73619d78580a3c5d6918bb1c566b1049d Mon Sep 17 00:00:00 2001 From: Miguel Sama Date: Wed, 25 May 2022 13:55:39 +0200 Subject: [PATCH 06/20] Improve methods Signed-off-by: Miguel Sama --- govcd/nsxt_route_advertisement.go | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/govcd/nsxt_route_advertisement.go b/govcd/nsxt_route_advertisement.go index 454a9ce13..8f11f057d 100644 --- a/govcd/nsxt_route_advertisement.go +++ b/govcd/nsxt_route_advertisement.go @@ -4,17 +4,42 @@ package govcd -import "github.com/vmware/go-vcloud-director/v2/types/v56" +import ( + "fmt" + "github.com/vmware/go-vcloud-director/v2/types/v56" +) +// GetNsxtRouteAdvertisement retrieves the list of subnets that will be advertised so that the Edge Gateway can route +// out to the connected external network. func (egw *NsxtEdgeGateway) GetNsxtRouteAdvertisement() (*types.RouteAdvertisement, error) { + endpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointNsxtRouteAdvertisement + + highestApiVersion, err := egw.client.getOpenApiHighestElevatedVersion(endpoint) + if err != nil { + return nil, err + } + + urlRef, err := egw.client.OpenApiBuildEndpoint(fmt.Sprintf(endpoint, egw.EdgeGateway.ID)) + if err != nil { + return nil, err + } + + routeAdvertisement := &types.RouteAdvertisement{} + err = egw.client.OpenApiGetItem(highestApiVersion, urlRef, nil, routeAdvertisement, nil) return nil, nil } +// UpdateNsxtRouteAdvertisement updates the list of subnets that will be advertised so that the Edge Gateway can route +// out to the connected external network. func (egw *NsxtEdgeGateway) UpdateNsxtRouteAdvertisement(enable bool, subnets []string) (*types.RouteAdvertisement, error) { return nil, nil } +// DeleteNsxtRouteAdvertisement deletes the list of subnets that will be advertised. func (egw *NsxtEdgeGateway) DeleteNsxtRouteAdvertisement() error { return nil } + +// checkSanityNsxtEdgeGatewayRouteAdvertisement +func checkSanityNsxtEdgeGatewayRouteAdvertisement(vdc *Vdc) error {} From 35b56c84c526a03b793241ef5dac0fa29f757822 Mon Sep 17 00:00:00 2001 From: Miguel Sama Date: Wed, 25 May 2022 17:17:15 +0200 Subject: [PATCH 07/20] Add NsxtEdgeGateway.getTenantContext method Signed-off-by: Miguel Sama --- govcd/tenant_context.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/govcd/tenant_context.go b/govcd/tenant_context.go index 6f540cd1d..75efd9916 100644 --- a/govcd/tenant_context.go +++ b/govcd/tenant_context.go @@ -183,3 +183,15 @@ func (vdcGroup *VdcGroup) getTenantContext() (*TenantContext, error) { } return org.tenantContext() } + +func (egw *NsxtEdgeGateway) getTenantContext() (*TenantContext, error) { + if egw != nil && egw.EdgeGateway.Org != nil { + if egw.EdgeGateway.Org.Name == "" || egw.EdgeGateway.Org.ID == "" { + return nil, fmt.Errorf("either parent NsxtEdgeGateway Org name or ID is empty and both must be set. Org name is [%s] and Org ID is [%s]", egw.EdgeGateway.Org.Name, egw.EdgeGateway.Org.ID) + } + + return &TenantContext{OrgId: egw.EdgeGateway.Org.ID, OrgName: egw.EdgeGateway.Org.Name}, nil + } + + return nil, fmt.Errorf("NsxtEdgeGateway is not fully initialized. Please initialized before using this method") +} From 9b0fd54a8ddb440d10cc642ff948b6352a892dbc Mon Sep 17 00:00:00 2001 From: Miguel Sama Date: Wed, 25 May 2022 17:17:39 +0200 Subject: [PATCH 08/20] Finish writing Route advertisement CRUD methods Signed-off-by: Miguel Sama --- govcd/nsxt_route_advertisement.go | 85 +++++++++++++++++++++++++++---- 1 file changed, 76 insertions(+), 9 deletions(-) diff --git a/govcd/nsxt_route_advertisement.go b/govcd/nsxt_route_advertisement.go index 8f11f057d..2749db0ef 100644 --- a/govcd/nsxt_route_advertisement.go +++ b/govcd/nsxt_route_advertisement.go @@ -11,7 +11,12 @@ import ( // GetNsxtRouteAdvertisement retrieves the list of subnets that will be advertised so that the Edge Gateway can route // out to the connected external network. -func (egw *NsxtEdgeGateway) GetNsxtRouteAdvertisement() (*types.RouteAdvertisement, error) { +func (egw *NsxtEdgeGateway) GetNsxtRouteAdvertisement(useTenantContext bool) (*types.RouteAdvertisement, error) { + err := checkSanityNsxtEdgeGatewayRouteAdvertisement(egw) + if err != nil { + return nil, err + } + endpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointNsxtRouteAdvertisement highestApiVersion, err := egw.client.getOpenApiHighestElevatedVersion(endpoint) @@ -24,22 +29,84 @@ func (egw *NsxtEdgeGateway) GetNsxtRouteAdvertisement() (*types.RouteAdvertiseme return nil, err } + var tenantContextHeaders map[string]string + if useTenantContext { + tenantContext, err := egw.getTenantContext() + if err != nil { + return nil, err + } + + tenantContextHeaders = getTenantContextHeader(tenantContext) + } + routeAdvertisement := &types.RouteAdvertisement{} - err = egw.client.OpenApiGetItem(highestApiVersion, urlRef, nil, routeAdvertisement, nil) + err = egw.client.OpenApiGetItem(highestApiVersion, urlRef, nil, routeAdvertisement, tenantContextHeaders) + if err != nil { + return nil, err + } - return nil, nil + return routeAdvertisement, nil } // UpdateNsxtRouteAdvertisement updates the list of subnets that will be advertised so that the Edge Gateway can route // out to the connected external network. -func (egw *NsxtEdgeGateway) UpdateNsxtRouteAdvertisement(enable bool, subnets []string) (*types.RouteAdvertisement, error) { - return nil, nil +func (egw *NsxtEdgeGateway) UpdateNsxtRouteAdvertisement(enable bool, subnets []string, useTenantContext bool) (*types.RouteAdvertisement, error) { + err := checkSanityNsxtEdgeGatewayRouteAdvertisement(egw) + if err != nil { + return nil, err + } + + endpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointNsxtRouteAdvertisement + + highestApiVersion, err := egw.client.getOpenApiHighestElevatedVersion(endpoint) + if err != nil { + return nil, err + } + + urlRef, err := egw.client.OpenApiBuildEndpoint(fmt.Sprintf(endpoint, egw.EdgeGateway.ID)) + if err != nil { + return nil, err + } + + var tenantContextHeaders map[string]string + if useTenantContext { + tenantContext, err := egw.getTenantContext() + if err != nil { + return nil, err + } + + tenantContextHeaders = getTenantContextHeader(tenantContext) + } + + routeAdvertisement := &types.RouteAdvertisement{ + Enable: enable, + Subnets: subnets, + } + + err = egw.client.OpenApiPutItem(highestApiVersion, urlRef, nil, routeAdvertisement, nil, tenantContextHeaders) + if err != nil { + return nil, err + } + + return egw.GetNsxtRouteAdvertisement(useTenantContext) } // DeleteNsxtRouteAdvertisement deletes the list of subnets that will be advertised. -func (egw *NsxtEdgeGateway) DeleteNsxtRouteAdvertisement() error { - return nil +func (egw *NsxtEdgeGateway) DeleteNsxtRouteAdvertisement(useTenantContext bool) error { + _, err := egw.UpdateNsxtRouteAdvertisement(false, []string{}, useTenantContext) + return err } -// checkSanityNsxtEdgeGatewayRouteAdvertisement -func checkSanityNsxtEdgeGatewayRouteAdvertisement(vdc *Vdc) error {} +// checkSanityNsxtEdgeGatewayRouteAdvertisement function performs some checks to *NsxtEdgeGateway parameter and returns error +// if something is wrong. It is useful with methods NsxtEdgeGateway.[Get/Update/Delete]NsxtRouteAdvertisement +func checkSanityNsxtEdgeGatewayRouteAdvertisement(egw *NsxtEdgeGateway) error { + if egw.EdgeGateway == nil { + return fmt.Errorf("the EdgeGateway pointer is nil. Please initialize it first before using this method") + } + + if egw.EdgeGateway.ID == "" { + return fmt.Errorf("the EdgeGateway ID is empty. Please initialize it first before using this method") + } + + return nil +} From 00916403b47ee4fb3195cbe2bb5cae5b5ab0347c Mon Sep 17 00:00:00 2001 From: Miguel Sama Date: Wed, 25 May 2022 18:03:42 +0200 Subject: [PATCH 09/20] Add test Signed-off-by: Miguel Sama --- govcd/nsxt_route_advertisement_test.go | 48 ++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/govcd/nsxt_route_advertisement_test.go b/govcd/nsxt_route_advertisement_test.go index a84027d45..d29735af5 100644 --- a/govcd/nsxt_route_advertisement_test.go +++ b/govcd/nsxt_route_advertisement_test.go @@ -1,5 +1,53 @@ +//go:build network || nsxt || functional || openapi || ALL +// +build network nsxt functional openapi ALL + /* * 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" + . "gopkg.in/check.v1" +) + +func (vcd *TestVCD) Test_NsxtEdgeRouteAdvertisement(check *C) { + skipNoNsxtConfiguration(vcd, check) + skipOpenApiEndpointTest(vcd, check, types.OpenApiPathVersion1_0_0+types.OpenApiEndpointNsxtRouteAdvertisement) + + 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) + edge, err := nsxtVdc.GetNsxtEdgeGatewayByName(vcd.config.VCD.Nsxt.EdgeGateway) + check.Assert(err, IsNil) + + // Make sure we are using a dedicated Tier-0 gateway (otherwise route advertisement won't be available) + edge.EdgeGateway.EdgeGatewayUplinks[0].Dedicated = true + edge, err = edge.Update(edge.EdgeGateway) + check.Assert(err, IsNil) + check.Assert(edge, NotNil) + + network1 := "192.168.1.0/24" + network2 := "192.168.2.0/24" + networksToAdvertise := []string{network1, network2} // Sample networks to advertise + + nsxtEdgeRouteAdvertisement, err := edge.UpdateNsxtRouteAdvertisement(true, networksToAdvertise, true) + check.Assert(err, IsNil) + check.Assert(nsxtEdgeRouteAdvertisement, NotNil) + check.Assert(nsxtEdgeRouteAdvertisement.Enable, Equals, true) + check.Assert(nsxtEdgeRouteAdvertisement.Subnets, Equals, true) + check.Assert(checkNetworkInSubnetsSlice(network1, networksToAdvertise), IsNil) + check.Assert(checkNetworkInSubnetsSlice(network2, networksToAdvertise), IsNil) +} + +func checkNetworkInSubnetsSlice(network string, subnets []string) error { + for _, subnet := range subnets { + if subnet == network { + return nil + } + } + return fmt.Errorf("network %s is not within the slice provided", network) +} From 534e1da7647588db42ed7fc84076dae3e6f66c35 Mon Sep 17 00:00:00 2001 From: Miguel Sama Date: Thu, 26 May 2022 09:44:30 +0200 Subject: [PATCH 10/20] Improve testing Signed-off-by: Miguel Sama --- govcd/nsxt_route_advertisement_test.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/govcd/nsxt_route_advertisement_test.go b/govcd/nsxt_route_advertisement_test.go index d29735af5..62716a35a 100644 --- a/govcd/nsxt_route_advertisement_test.go +++ b/govcd/nsxt_route_advertisement_test.go @@ -34,13 +34,23 @@ func (vcd *TestVCD) Test_NsxtEdgeRouteAdvertisement(check *C) { network2 := "192.168.2.0/24" networksToAdvertise := []string{network1, network2} // Sample networks to advertise + // Test UpdateNsxtRouteAdvertisement nsxtEdgeRouteAdvertisement, err := edge.UpdateNsxtRouteAdvertisement(true, networksToAdvertise, true) check.Assert(err, IsNil) check.Assert(nsxtEdgeRouteAdvertisement, NotNil) check.Assert(nsxtEdgeRouteAdvertisement.Enable, Equals, true) - check.Assert(nsxtEdgeRouteAdvertisement.Subnets, Equals, true) + check.Assert(len(nsxtEdgeRouteAdvertisement.Subnets), Equals, 2) check.Assert(checkNetworkInSubnetsSlice(network1, networksToAdvertise), IsNil) check.Assert(checkNetworkInSubnetsSlice(network2, networksToAdvertise), IsNil) + + // Test DeleteNsxtRouteAdvertisement + err = edge.DeleteNsxtRouteAdvertisement(true) + check.Assert(err, IsNil) + nsxtEdgeRouteAdvertisement, err = edge.GetNsxtRouteAdvertisement(true) + check.Assert(err, IsNil) + check.Assert(nsxtEdgeRouteAdvertisement, NotNil) + check.Assert(nsxtEdgeRouteAdvertisement.Enable, Equals, false) + check.Assert(len(nsxtEdgeRouteAdvertisement.Subnets), Equals, 0) } func checkNetworkInSubnetsSlice(network string, subnets []string) error { From 8b6595d7c9281a94ce23156a60760c08b0a83106 Mon Sep 17 00:00:00 2001 From: Miguel Sama Date: Thu, 26 May 2022 10:05:24 +0200 Subject: [PATCH 11/20] Add changelog Signed-off-by: Miguel Sama --- .changes/v2.16.0/478-features.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 .changes/v2.16.0/478-features.md diff --git a/.changes/v2.16.0/478-features.md b/.changes/v2.16.0/478-features.md new file mode 100644 index 000000000..c2cf83e40 --- /dev/null +++ b/.changes/v2.16.0/478-features.md @@ -0,0 +1 @@ +* Add NSX-T Edge Gateway methods `NsxtEdgeGateway.GetNsxtRouteAdvertisement`, `NsxtEdgeGateway.UpdateNsxtRouteAdvertisement` and `NsxtEdgeGateway.DeleteNsxtRouteAdvertisement` that allows to manage NSX-T route advertisement [GH-478] From 74a0473b89193851b23468d495dce15408f8ab28 Mon Sep 17 00:00:00 2001 From: Miguel Sama Date: Thu, 2 Jun 2022 14:57:20 +0200 Subject: [PATCH 12/20] Change err message Signed-off-by: Miguel Sama --- govcd/catalog_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/govcd/catalog_test.go b/govcd/catalog_test.go index e627be318..364646381 100644 --- a/govcd/catalog_test.go +++ b/govcd/catalog_test.go @@ -969,7 +969,7 @@ func (vcd *TestVCD) Test_CatalogUploadMediaImageWihUdfTypeIso(check *C) { fmt.Printf("Running: %s\n", check.TestName()) if vcd.config.Media.MediaUdfTypePath == "" { - check.Skip("Skipping test because no UDF type iso path given") + check.Skip("Skipping test because no UDF type ISO path was given") } catalog, org := findCatalog(vcd, check, vcd.config.VCD.Catalog.Name) From 7acb54c0e874038417e81112323d4db4a8999808 Mon Sep 17 00:00:00 2001 From: Miguel Sama Date: Thu, 2 Jun 2022 15:00:11 +0200 Subject: [PATCH 13/20] Change Test_CatalogUploadMediaImageWihUdfTypeIso func docs Signed-off-by: Miguel Sama --- govcd/catalog_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/govcd/catalog_test.go b/govcd/catalog_test.go index 364646381..66e4b2fc0 100644 --- a/govcd/catalog_test.go +++ b/govcd/catalog_test.go @@ -964,7 +964,7 @@ func (vcd *TestVCD) Test_CatalogQueryMediaList(check *C) { check.Assert(medias[0].Name, Equals, vcd.config.Media.Media) } -// Tests System function UploadMediaImage by checking if provided UDF type standard iso file uploaded. +// Tests System function UploadMediaImage by checking if provided ISO file of UDF type. func (vcd *TestVCD) Test_CatalogUploadMediaImageWihUdfTypeIso(check *C) { fmt.Printf("Running: %s\n", check.TestName()) From 7c5e91234f9abd014aa72a62a25bbae7ca5c8062 Mon Sep 17 00:00:00 2001 From: Miguel Sama Date: Mon, 6 Jun 2022 10:53:07 +0200 Subject: [PATCH 14/20] Fix bad docs description Signed-off-by: Miguel Sama --- govcd/catalog_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/govcd/catalog_test.go b/govcd/catalog_test.go index 66e4b2fc0..2310f02c0 100644 --- a/govcd/catalog_test.go +++ b/govcd/catalog_test.go @@ -964,7 +964,7 @@ func (vcd *TestVCD) Test_CatalogQueryMediaList(check *C) { check.Assert(medias[0].Name, Equals, vcd.config.Media.Media) } -// Tests System function UploadMediaImage by checking if provided ISO file of UDF type. +// Tests System function UploadMediaImage by using provided ISO file of UDF type. func (vcd *TestVCD) Test_CatalogUploadMediaImageWihUdfTypeIso(check *C) { fmt.Printf("Running: %s\n", check.TestName()) From f2bc11bcdb093c7aca7818fc0f0d52d7b994e898 Mon Sep 17 00:00:00 2001 From: Miguel Sama Date: Thu, 9 Jun 2022 12:25:05 +0200 Subject: [PATCH 15/20] Remove dedicate tier-0 gateway after test execution Signed-off-by: Miguel Sama --- govcd/nsxt_route_advertisement_test.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/govcd/nsxt_route_advertisement_test.go b/govcd/nsxt_route_advertisement_test.go index 62716a35a..9bde1a77b 100644 --- a/govcd/nsxt_route_advertisement_test.go +++ b/govcd/nsxt_route_advertisement_test.go @@ -25,11 +25,13 @@ func (vcd *TestVCD) Test_NsxtEdgeRouteAdvertisement(check *C) { check.Assert(err, IsNil) // Make sure we are using a dedicated Tier-0 gateway (otherwise route advertisement won't be available) - edge.EdgeGateway.EdgeGatewayUplinks[0].Dedicated = true - edge, err = edge.Update(edge.EdgeGateway) + edge, err = setDedicateTier0Gateway(edge, true) check.Assert(err, IsNil) check.Assert(edge, NotNil) + // Make sure that things get back to normal when the test is done + defer setDedicateTier0Gateway(edge, false) + network1 := "192.168.1.0/24" network2 := "192.168.2.0/24" networksToAdvertise := []string{network1, network2} // Sample networks to advertise @@ -61,3 +63,13 @@ func checkNetworkInSubnetsSlice(network string, subnets []string) error { } return fmt.Errorf("network %s is not within the slice provided", network) } + +func setDedicateTier0Gateway(edgeGateway *NsxtEdgeGateway, dedicate bool) (*NsxtEdgeGateway, error) { + edgeGateway.EdgeGateway.EdgeGatewayUplinks[0].Dedicated = dedicate + edgeGateway, err := edgeGateway.Update(edgeGateway.EdgeGateway) + if err != nil { + return nil, err + } + + return edgeGateway, nil +} From eb9cf3ecfa299856cb5a740b1b8134601ba4a567 Mon Sep 17 00:00:00 2001 From: Miguel Sama Date: Thu, 9 Jun 2022 12:25:31 +0200 Subject: [PATCH 16/20] Fix docs typo Signed-off-by: Miguel Sama --- govcd/tenant_context.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/govcd/tenant_context.go b/govcd/tenant_context.go index 75efd9916..4e8e90f40 100644 --- a/govcd/tenant_context.go +++ b/govcd/tenant_context.go @@ -193,5 +193,5 @@ func (egw *NsxtEdgeGateway) getTenantContext() (*TenantContext, error) { return &TenantContext{OrgId: egw.EdgeGateway.Org.ID, OrgName: egw.EdgeGateway.Org.Name}, nil } - return nil, fmt.Errorf("NsxtEdgeGateway is not fully initialized. Please initialized before using this method") + return nil, fmt.Errorf("NsxtEdgeGateway is not fully initialized. Please initialize it before using this method") } From 029f076c501e5663c87ec1f151618ac0d83e422f Mon Sep 17 00:00:00 2001 From: Miguel Sama Date: Thu, 9 Jun 2022 12:26:00 +0200 Subject: [PATCH 17/20] Fix issue in docs Signed-off-by: Miguel Sama --- types/v56/nsxt_types.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/v56/nsxt_types.go b/types/v56/nsxt_types.go index 99674e17e..2a95d08bf 100644 --- a/types/v56/nsxt_types.go +++ b/types/v56/nsxt_types.go @@ -1248,7 +1248,7 @@ type EntitySecurityTags struct { // RouteAdvertisement lists the subnets that will be advertised so that the Edge Gateway can route out to the // connected external network. type RouteAdvertisement struct { - // Enable if true, means that the subnets will be advertised. The default is true. + // Enable if true, means that the subnets will be advertised. Enable bool `json:"enable"` // Subnets is the list of subnets that will be advertised so that the Edge Gateway can route out to the connected // external network. From 81177ca00c16502446c478a35c1edfb4c797f9bc Mon Sep 17 00:00:00 2001 From: Miguel Sama Date: Tue, 14 Jun 2022 15:05:23 +0200 Subject: [PATCH 18/20] Add withContext methods for update, read and delete Signed-off-by: Miguel Sama --- govcd/nsxt_route_advertisement.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/govcd/nsxt_route_advertisement.go b/govcd/nsxt_route_advertisement.go index 2749db0ef..8e64cdd47 100644 --- a/govcd/nsxt_route_advertisement.go +++ b/govcd/nsxt_route_advertisement.go @@ -48,6 +48,11 @@ func (egw *NsxtEdgeGateway) GetNsxtRouteAdvertisement(useTenantContext bool) (*t return routeAdvertisement, nil } +// GetNsxtRouteAdvertisementWithContext method is the same as GetNsxtRouteAdvertisement but using TenantContext by default +func (egw *NsxtEdgeGateway) GetNsxtRouteAdvertisementWithContext() (*types.RouteAdvertisement, error) { + return egw.GetNsxtRouteAdvertisement(true) +} + // UpdateNsxtRouteAdvertisement updates the list of subnets that will be advertised so that the Edge Gateway can route // out to the connected external network. func (egw *NsxtEdgeGateway) UpdateNsxtRouteAdvertisement(enable bool, subnets []string, useTenantContext bool) (*types.RouteAdvertisement, error) { @@ -91,12 +96,22 @@ func (egw *NsxtEdgeGateway) UpdateNsxtRouteAdvertisement(enable bool, subnets [] return egw.GetNsxtRouteAdvertisement(useTenantContext) } +// UpdateNsxtRouteAdvertisementWithContext method is the same as UpdateNsxtRouteAdvertisementWithContext but using TenantContext by default +func (egw *NsxtEdgeGateway) UpdateNsxtRouteAdvertisementWithContext(enable bool, subnets []string) (*types.RouteAdvertisement, error) { + return egw.UpdateNsxtRouteAdvertisement(enable, subnets, true) +} + // DeleteNsxtRouteAdvertisement deletes the list of subnets that will be advertised. func (egw *NsxtEdgeGateway) DeleteNsxtRouteAdvertisement(useTenantContext bool) error { _, err := egw.UpdateNsxtRouteAdvertisement(false, []string{}, useTenantContext) return err } +// DeleteNsxtRouteAdvertisement method is the same as DeleteNsxtRouteAdvertisement but using TenantContext by default +func (egw *NsxtEdgeGateway) DeleteNsxtRouteAdvertisementWithContext() error { + return egw.DeleteNsxtRouteAdvertisement(true) +} + // checkSanityNsxtEdgeGatewayRouteAdvertisement function performs some checks to *NsxtEdgeGateway parameter and returns error // if something is wrong. It is useful with methods NsxtEdgeGateway.[Get/Update/Delete]NsxtRouteAdvertisement func checkSanityNsxtEdgeGatewayRouteAdvertisement(egw *NsxtEdgeGateway) error { From 69ac3fd259b23a5f8e1a240e0b0ae004b1452924 Mon Sep 17 00:00:00 2001 From: Miguel Sama Date: Tue, 14 Jun 2022 16:18:33 +0200 Subject: [PATCH 19/20] Change method names Signed-off-by: Miguel Sama --- govcd/nsxt_route_advertisement.go | 34 +++++++++++++------------- govcd/nsxt_route_advertisement_test.go | 6 ++--- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/govcd/nsxt_route_advertisement.go b/govcd/nsxt_route_advertisement.go index 8e64cdd47..f3462b28a 100644 --- a/govcd/nsxt_route_advertisement.go +++ b/govcd/nsxt_route_advertisement.go @@ -9,9 +9,9 @@ import ( "github.com/vmware/go-vcloud-director/v2/types/v56" ) -// GetNsxtRouteAdvertisement retrieves the list of subnets that will be advertised so that the Edge Gateway can route +// GetNsxtRouteAdvertisementWithContext retrieves the list of subnets that will be advertised so that the Edge Gateway can route // out to the connected external network. -func (egw *NsxtEdgeGateway) GetNsxtRouteAdvertisement(useTenantContext bool) (*types.RouteAdvertisement, error) { +func (egw *NsxtEdgeGateway) GetNsxtRouteAdvertisementWithContext(useTenantContext bool) (*types.RouteAdvertisement, error) { err := checkSanityNsxtEdgeGatewayRouteAdvertisement(egw) if err != nil { return nil, err @@ -48,14 +48,14 @@ func (egw *NsxtEdgeGateway) GetNsxtRouteAdvertisement(useTenantContext bool) (*t return routeAdvertisement, nil } -// GetNsxtRouteAdvertisementWithContext method is the same as GetNsxtRouteAdvertisement but using TenantContext by default -func (egw *NsxtEdgeGateway) GetNsxtRouteAdvertisementWithContext() (*types.RouteAdvertisement, error) { - return egw.GetNsxtRouteAdvertisement(true) +// GetNsxtRouteAdvertisement method is the same as GetNsxtRouteAdvertisementWithContext but sending TenantContext by default +func (egw *NsxtEdgeGateway) GetNsxtRouteAdvertisement() (*types.RouteAdvertisement, error) { + return egw.GetNsxtRouteAdvertisementWithContext(true) } -// UpdateNsxtRouteAdvertisement updates the list of subnets that will be advertised so that the Edge Gateway can route +// UpdateNsxtRouteAdvertisementWithContext updates the list of subnets that will be advertised so that the Edge Gateway can route // out to the connected external network. -func (egw *NsxtEdgeGateway) UpdateNsxtRouteAdvertisement(enable bool, subnets []string, useTenantContext bool) (*types.RouteAdvertisement, error) { +func (egw *NsxtEdgeGateway) UpdateNsxtRouteAdvertisementWithContext(enable bool, subnets []string, useTenantContext bool) (*types.RouteAdvertisement, error) { err := checkSanityNsxtEdgeGatewayRouteAdvertisement(egw) if err != nil { return nil, err @@ -93,23 +93,23 @@ func (egw *NsxtEdgeGateway) UpdateNsxtRouteAdvertisement(enable bool, subnets [] return nil, err } - return egw.GetNsxtRouteAdvertisement(useTenantContext) + return egw.GetNsxtRouteAdvertisementWithContext(useTenantContext) } -// UpdateNsxtRouteAdvertisementWithContext method is the same as UpdateNsxtRouteAdvertisementWithContext but using TenantContext by default -func (egw *NsxtEdgeGateway) UpdateNsxtRouteAdvertisementWithContext(enable bool, subnets []string) (*types.RouteAdvertisement, error) { - return egw.UpdateNsxtRouteAdvertisement(enable, subnets, true) +// UpdateNsxtRouteAdvertisement method is the same as UpdateNsxtRouteAdvertisementWithContext but sending TenantContext by default +func (egw *NsxtEdgeGateway) UpdateNsxtRouteAdvertisement(enable bool, subnets []string) (*types.RouteAdvertisement, error) { + return egw.UpdateNsxtRouteAdvertisementWithContext(enable, subnets, true) } -// DeleteNsxtRouteAdvertisement deletes the list of subnets that will be advertised. -func (egw *NsxtEdgeGateway) DeleteNsxtRouteAdvertisement(useTenantContext bool) error { - _, err := egw.UpdateNsxtRouteAdvertisement(false, []string{}, useTenantContext) +// DeleteNsxtRouteAdvertisementWithContext deletes the list of subnets that will be advertised. +func (egw *NsxtEdgeGateway) DeleteNsxtRouteAdvertisementWithContext(useTenantContext bool) error { + _, err := egw.UpdateNsxtRouteAdvertisementWithContext(false, []string{}, useTenantContext) return err } -// DeleteNsxtRouteAdvertisement method is the same as DeleteNsxtRouteAdvertisement but using TenantContext by default -func (egw *NsxtEdgeGateway) DeleteNsxtRouteAdvertisementWithContext() error { - return egw.DeleteNsxtRouteAdvertisement(true) +// DeleteNsxtRouteAdvertisement method is the same as DeleteNsxtRouteAdvertisementWithContext but sending TenantContext by default +func (egw *NsxtEdgeGateway) DeleteNsxtRouteAdvertisement() error { + return egw.DeleteNsxtRouteAdvertisementWithContext(true) } // checkSanityNsxtEdgeGatewayRouteAdvertisement function performs some checks to *NsxtEdgeGateway parameter and returns error diff --git a/govcd/nsxt_route_advertisement_test.go b/govcd/nsxt_route_advertisement_test.go index 9bde1a77b..c6cd69240 100644 --- a/govcd/nsxt_route_advertisement_test.go +++ b/govcd/nsxt_route_advertisement_test.go @@ -37,7 +37,7 @@ func (vcd *TestVCD) Test_NsxtEdgeRouteAdvertisement(check *C) { networksToAdvertise := []string{network1, network2} // Sample networks to advertise // Test UpdateNsxtRouteAdvertisement - nsxtEdgeRouteAdvertisement, err := edge.UpdateNsxtRouteAdvertisement(true, networksToAdvertise, true) + nsxtEdgeRouteAdvertisement, err := edge.UpdateNsxtRouteAdvertisement(true, networksToAdvertise) check.Assert(err, IsNil) check.Assert(nsxtEdgeRouteAdvertisement, NotNil) check.Assert(nsxtEdgeRouteAdvertisement.Enable, Equals, true) @@ -46,9 +46,9 @@ func (vcd *TestVCD) Test_NsxtEdgeRouteAdvertisement(check *C) { check.Assert(checkNetworkInSubnetsSlice(network2, networksToAdvertise), IsNil) // Test DeleteNsxtRouteAdvertisement - err = edge.DeleteNsxtRouteAdvertisement(true) + err = edge.DeleteNsxtRouteAdvertisement() check.Assert(err, IsNil) - nsxtEdgeRouteAdvertisement, err = edge.GetNsxtRouteAdvertisement(true) + nsxtEdgeRouteAdvertisement, err = edge.GetNsxtRouteAdvertisement() check.Assert(err, IsNil) check.Assert(nsxtEdgeRouteAdvertisement, NotNil) check.Assert(nsxtEdgeRouteAdvertisement.Enable, Equals, false) From a1b9781d4e05d4e43227bc20f014e5d608f66b09 Mon Sep 17 00:00:00 2001 From: Miguel Sama Date: Tue, 14 Jun 2022 16:38:21 +0200 Subject: [PATCH 20/20] Update changelog Signed-off-by: Miguel Sama --- .changes/v2.16.0/478-features.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changes/v2.16.0/478-features.md b/.changes/v2.16.0/478-features.md index c2cf83e40..f6e7f4901 100644 --- a/.changes/v2.16.0/478-features.md +++ b/.changes/v2.16.0/478-features.md @@ -1 +1 @@ -* Add NSX-T Edge Gateway methods `NsxtEdgeGateway.GetNsxtRouteAdvertisement`, `NsxtEdgeGateway.UpdateNsxtRouteAdvertisement` and `NsxtEdgeGateway.DeleteNsxtRouteAdvertisement` that allows to manage NSX-T route advertisement [GH-478] +* Add NSX-T Edge Gateway methods `NsxtEdgeGateway.GetNsxtRouteAdvertisement`, `NsxtEdgeGateway.GetNsxtRouteAdvertisementWithContext`, `NsxtEdgeGateway.UpdateNsxtRouteAdvertisement`, `NsxtEdgeGateway.UpdateNsxtRouteAdvertisementWithContext`, `NsxtEdgeGateway.DeleteNsxtRouteAdvertisement` and `NsxtEdgeGateway.DeleteNsxtRouteAdvertisementWithContext` that allows to manage NSX-T route advertisement [GH-478]