From 68f81d8f861a5371434d648ac0a29519078f589e Mon Sep 17 00:00:00 2001 From: Dainius Serplis Date: Mon, 6 Sep 2021 13:15:50 +0300 Subject: [PATCH 1/6] Add NSX-T ALB provider configuration support Signed-off-by: Dainius Serplis --- .changes/v2.13.0/xxx-features.md | 14 ++ go.mod | 1 + govcd/api_vcd_test.go | 25 +- govcd/nsxt_alb_clouds.go | 194 +++++++++++++++ govcd/nsxt_alb_clouds_test.go | 119 +++++++++ govcd/nsxt_alb_controllers.go | 233 ++++++++++++++++++ govcd/nsxt_alb_controllers_test.go | 107 ++++++++ govcd/nsxt_alb_importable_clouds.go | 116 +++++++++ govcd/nsxt_alb_importable_clouds_test.go | 38 +++ ...xt_alb_importable_service_engine_groups.go | 107 ++++++++ ...b_importable_service_engine_groups_test.go | 31 +++ govcd/nsxt_alb_service_engine_groups.go | 201 +++++++++++++++ govcd/nsxt_alb_service_engine_groups_test.go | 74 ++++++ govcd/openapi_endpoints.go | 9 +- types/v56/constants.go | 13 + types/v56/nsxt_types.go | 112 +++++++++ 16 files changed, 1391 insertions(+), 3 deletions(-) create mode 100644 .changes/v2.13.0/xxx-features.md create mode 100644 govcd/nsxt_alb_clouds.go create mode 100644 govcd/nsxt_alb_clouds_test.go create mode 100644 govcd/nsxt_alb_controllers.go create mode 100644 govcd/nsxt_alb_controllers_test.go create mode 100644 govcd/nsxt_alb_importable_clouds.go create mode 100644 govcd/nsxt_alb_importable_clouds_test.go create mode 100644 govcd/nsxt_alb_importable_service_engine_groups.go create mode 100644 govcd/nsxt_alb_importable_service_engine_groups_test.go create mode 100644 govcd/nsxt_alb_service_engine_groups.go create mode 100644 govcd/nsxt_alb_service_engine_groups_test.go diff --git a/.changes/v2.13.0/xxx-features.md b/.changes/v2.13.0/xxx-features.md new file mode 100644 index 000000000..deef6af24 --- /dev/null +++ b/.changes/v2.13.0/xxx-features.md @@ -0,0 +1,14 @@ +* Added types `NsxtAlbController` and `types.NsxtAlbController` for handling NSX-T ALB Controllers with corresponding + functions `GetAllAlbControllers`, `GetAlbControllerByName`, `GetAlbControllerById`, `GetAlbControllerByUrl`, + `CreateNsxtAlbController`, `Update`, `Delete` [GH-xxx] +* Added types `NsxtAlbCloud` and `types.NsxtAlbCloud` for handling NSX-T ALB Clouds with corresponding functions + `GetAllAlbClouds`, `GetAlbCloudByName`, `GetAlbCloudById`, `CreateAlbCloud`, `Delete` [GH-xxx] +* Added type `NsxtAlbImportableCloud` and `types.NsxtAlbImportableCloud` for listing NSX-T ALB Importable Clouds with + corresponding functions `GetAllAlbImportableClouds`, `GetAlbImportableCloudByName`, `GetAlbImportableCloudById` + [GH-xxx] +* Added types `NsxtAlbServiceEngineGroup` and `types.NsxtAlbServiceEngineGroup` for handling NSX-T ALB Service Engine + Groups with corresponding functions `GetAllNsxtAlbServiceEngineGroups`, `GetAlbServiceEngineGroupByName`, + `GetAlbServiceEngineGroupById`, `CreateNsxtAlbServiceEngineGroup`, `Update`, `Delete` [GH-xxx] +* Added types `NsxtAlbImportableServiceEngineGroups` and `types.NsxtAlbImportableServiceEngineGroups` for listing NSX-T + ALB Importable Service Engine Groups with corresponding functions `GetAllAlbImportableServiceEngineGroups`, + `GetAlbImportableServiceEngineGroupByName`, `GetAlbImportableServiceEngineGroupById` [GH-xxx] diff --git a/go.mod b/go.mod index 749933f69..e036ea991 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.13 require ( github.com/araddon/dateparse v0.0.0-20190622164848-0fb0a474d195 + github.com/davecgh/go-spew v1.1.0 // indirect github.com/hashicorp/go-version v1.2.0 github.com/kr/pretty v0.2.1 github.com/peterhellberg/link v1.1.0 diff --git a/govcd/api_vcd_test.go b/govcd/api_vcd_test.go index 56a2d8a2a..937c072b1 100644 --- a/govcd/api_vcd_test.go +++ b/govcd/api_vcd_test.go @@ -1,5 +1,5 @@ -//go:build api || openapi || functional || catalog || vapp || gateway || network || org || query || extnetwork || task || vm || vdc || system || disk || lb || lbAppRule || lbAppProfile || lbServerPool || lbServiceMonitor || lbVirtualServer || user || search || nsxv || nsxt || auth || affinity || role || ALL -// +build api openapi functional catalog vapp gateway network org query extnetwork task vm vdc system disk lb lbAppRule lbAppProfile lbServerPool lbServiceMonitor lbVirtualServer user search nsxv nsxt auth affinity role ALL +//go:build api || openapi || functional || catalog || vapp || gateway || network || org || query || extnetwork || task || vm || vdc || system || disk || lb || lbAppRule || lbAppProfile || lbServerPool || lbServiceMonitor || lbVirtualServer || user || search || nsxv || nsxt || auth || affinity || role || alb || ALL +// +build api openapi functional catalog vapp gateway network org query extnetwork task vm vdc system disk lb lbAppRule lbAppProfile lbServerPool lbServiceMonitor lbVirtualServer user search nsxv nsxt auth affinity role alb ALL /* * Copyright 2021 VMware, Inc. All rights reserved. Licensed under the Apache v2 License. @@ -171,6 +171,10 @@ type TestConfig struct { ExternalNetwork string `yaml:"externalNetwork"` EdgeGateway string `yaml:"edgeGateway"` NsxtImportSegment string `yaml:"nsxtImportSegment"` + + NsxtAlbControllerUrl string `yaml:"nsxtAlbControllerUrl"` + NsxtAlbControllerUser string `yaml:"nsxtAlbControllerUser"` + NsxtAlbControllerPassword string `yaml:"nsxtAlbControllerPassword"` } `yaml:"nsxt"` } `yaml:"vcd"` Logging struct { @@ -1836,6 +1840,23 @@ func skipNoNsxtConfiguration(vcd *TestVCD, check *C) { } } +func skipNoNsxtAlbConfiguration(vcd *TestVCD, check *C) { + skipNoNsxtConfiguration(vcd, check) + generalMessage := "Missing NSX-T ALB config: " + + if vcd.config.VCD.Nsxt.NsxtAlbControllerUrl == "" { + check.Skip(generalMessage + "No NSX-T ALB Controller URL specified in configuration") + } + + if vcd.config.VCD.Nsxt.NsxtAlbControllerUser == "" { + check.Skip(generalMessage + "No NSX-T ALB Controller Name specified in configuration") + } + + if vcd.config.VCD.Nsxt.NsxtAlbControllerPassword == "" { + check.Skip(generalMessage + "No NSX-T ALB Controller Password specified in configuration") + } +} + // skipOpenApiEndpointTest is a helper to skip tests for particular unsupported OpenAPI endpoints func skipOpenApiEndpointTest(vcd *TestVCD, check *C, endpoint string) { minimumRequiredApiVersion := endpointMinApiVersions[endpoint] diff --git a/govcd/nsxt_alb_clouds.go b/govcd/nsxt_alb_clouds.go new file mode 100644 index 000000000..a7720f3e2 --- /dev/null +++ b/govcd/nsxt_alb_clouds.go @@ -0,0 +1,194 @@ +/* + * Copyright 2021 VMware, Inc. All rights reserved. Licensed under the Apache v2 License. + */ + +package govcd + +import ( + "errors" + "fmt" + "net/url" + + "github.com/vmware/go-vcloud-director/v2/types/v56" +) + +// NsxtAlbCloud allows users to use the virtual infrastructure provided by NSX Advanced Load Balancer, register your +// NSX-T Cloud instances with VMware Cloud Director. An NSX-T Cloud is a service provider-level construct that consists +// of an NSX-T Manager and an NSX-T Data Center transport zone. NSX-T Manager provides a system view and is the +// management component of NSX-T Data Center. An NSX-T Data Center transport zone dictates which hosts and virtual +// machines can participate in the use of a particular network. If there are multiple transport zones managed by the +// same NSX-T Manager, then a separate NSX-T Cloud encapsulates each pair of NSX-T Manager and NSX-T Data Center +// transport zone instances. An NSX-T Cloud has a one-to-one relationship with a network pool backed by an NSX-T Data +// Center transport zone. +type NsxtAlbCloud struct { + NsxtAlbCloud *types.NsxtAlbCloud + vcdClient *VCDClient +} + +// GetAllAlbClouds returns all configured NSX-T ALB Clouds +func (vcdClient *VCDClient) GetAllAlbClouds(queryParameters url.Values) ([]*NsxtAlbCloud, error) { + client := vcdClient.Client + if !client.IsSysAdmin { + return nil, errors.New("handling NSX-T ALB Clouds require System user") + } + + endpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointAlbCloud + apiVersion, err := client.checkOpenApiEndpointCompatibility(endpoint) + if err != nil { + return nil, err + } + + urlRef, err := client.OpenApiBuildEndpoint(endpoint) + if err != nil { + return nil, err + } + + typeResponses := []*types.NsxtAlbCloud{{}} + err = client.OpenApiGetAllItems(apiVersion, urlRef, queryParameters, &typeResponses, nil) + if err != nil { + return nil, err + } + + // Wrap all typeResponses into NsxtAlbCloud types with client + wrappedResponses := make([]*NsxtAlbCloud, len(typeResponses)) + for sliceIndex := range typeResponses { + wrappedResponses[sliceIndex] = &NsxtAlbCloud{ + NsxtAlbCloud: typeResponses[sliceIndex], + vcdClient: vcdClient, + } + } + + return wrappedResponses, nil +} + +// GetAlbCloudByName returns NSX-T ALB Cloud by name +func (vcdClient *VCDClient) GetAlbCloudByName(name string) (*NsxtAlbCloud, error) { + queryParameters := copyOrNewUrlValues(nil) + queryParameters.Add("filter", "name=="+name) + + albClouds, err := vcdClient.GetAllAlbClouds(queryParameters) + if err != nil { + return nil, fmt.Errorf("error reading NSX-T ALB Cloud with Name '%s': %s", name, err) + } + + if len(albClouds) == 0 { + return nil, fmt.Errorf("%s could not find NSX-T ALB Cloud with Name '%s'", ErrorEntityNotFound, name) + } + + if len(albClouds) > 1 { + return nil, fmt.Errorf("found more than 1 NSX-T ALB Cloud with Name '%s'", name) + } + + return albClouds[0], nil +} + +// GetAlbCloudById returns NSX-T ALB Cloud by ID +// +// Note. This function uses server side filtering instead of directly querying endpoint with specified ID. Such ID does +// not exist. +func (vcdClient *VCDClient) GetAlbCloudById(id string) (*NsxtAlbCloud, error) { + + queryParameters := copyOrNewUrlValues(nil) + queryParameters.Add("filter", "id=="+id) + + albCloud, err := vcdClient.GetAllAlbClouds(queryParameters) + if err != nil { + return nil, fmt.Errorf("error reading NSX-T ALB Cloud with ID '%s': %s", id, err) + } + + if len(albCloud) == 0 { + return nil, fmt.Errorf("%s could not find NSX-T ALB Cloud by Name '%s'", ErrorEntityNotFound, id) + } + + return albCloud[0], nil +} + +// CreateAlbCloud creates NSX-T ALB Cloud +func (vcdClient *VCDClient) CreateAlbCloud(albCloudConfig *types.NsxtAlbCloud) (*NsxtAlbCloud, error) { + client := vcdClient.Client + if !client.IsSysAdmin { + return nil, errors.New("handling NSX-T ALB Clouds require System user") + } + + endpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointAlbCloud + minimumApiVersion, err := client.checkOpenApiEndpointCompatibility(endpoint) + if err != nil { + return nil, err + } + + urlRef, err := client.OpenApiBuildEndpoint(endpoint) + if err != nil { + return nil, err + } + + returnObject := &NsxtAlbCloud{ + NsxtAlbCloud: &types.NsxtAlbCloud{}, + vcdClient: vcdClient, + } + + err = client.OpenApiPostItem(minimumApiVersion, urlRef, nil, albCloudConfig, returnObject.NsxtAlbCloud, nil) + if err != nil { + return nil, fmt.Errorf("error creating NSX-T ALB Cloud: %s", err) + } + + return returnObject, nil +} + +// Update is not supported up to at least VCD 10.3 therefore this function remains commented +// +// Update updates existing NSX-T ALB Cloud with new supplied albCloudConfig configuration +//func (nsxtAlbCloud *NsxtAlbCloud) Update(albCloudConfig *types.NsxtAlbCloud) (*NsxtAlbCloud, error) { +// client := nsxtAlbCloud.vcdClient.Client +// endpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointAlbCloud +// minimumApiVersion, err := client.checkOpenApiEndpointCompatibility(endpoint) +// if err != nil { +// return nil, err +// } +// +// if albCloudConfig.ID == "" { +// return nil, fmt.Errorf("cannot update NSX-T ALB Cloud without ID") +// } +// +// urlRef, err := client.OpenApiBuildEndpoint(endpoint, albCloudConfig.ID) +// if err != nil { +// return nil, err +// } +// +// responseAlbCloud := &NsxtAlbCloud{ +// NsxtAlbCloud: &types.NsxtAlbCloud{}, +// vcdClient: nsxtAlbCloud.vcdClient, +// } +// +// err = client.OpenApiPutItem(minimumApiVersion, urlRef, nil, albCloudConfig, responseAlbCloud.NsxtAlbCloud, nil) +// if err != nil { +// return nil, fmt.Errorf("error updating NSX-T ALB Cloud: %s", err) +// } +// +// return responseAlbCloud, nil +//} + +// Delete removes NSX-T ALB Cloud configuration +func (nsxtAlbCloud *NsxtAlbCloud) Delete() error { + client := nsxtAlbCloud.vcdClient.Client + endpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointAlbCloud + minimumApiVersion, err := client.checkOpenApiEndpointCompatibility(endpoint) + if err != nil { + return err + } + + if nsxtAlbCloud.NsxtAlbCloud.ID == "" { + return fmt.Errorf("cannot delete NSX-T ALB Cloud without ID") + } + + urlRef, err := client.OpenApiBuildEndpoint(endpoint, nsxtAlbCloud.NsxtAlbCloud.ID) + if err != nil { + return err + } + + err = client.OpenApiDeleteItem(minimumApiVersion, urlRef, nil, nil) + if err != nil { + return fmt.Errorf("error deleting NSX-T ALB Cloud: %s", err) + } + + return nil +} diff --git a/govcd/nsxt_alb_clouds_test.go b/govcd/nsxt_alb_clouds_test.go new file mode 100644 index 000000000..4a15dd965 --- /dev/null +++ b/govcd/nsxt_alb_clouds_test.go @@ -0,0 +1,119 @@ +//go:build alb || functional || ALL +// +build alb functional ALL + +package govcd + +import ( + "fmt" + "net/url" + + "github.com/vmware/go-vcloud-director/v2/types/v56" + + . "gopkg.in/check.v1" +) + +func (vcd *TestVCD) Test_AlbClouds(check *C) { + if vcd.skipAdminTests { + check.Skip(fmt.Sprintf(TestRequiresSysAdminPrivileges, check.TestName())) + } + skipNoNsxtAlbConfiguration(vcd, check) + + albController := spawnAlbController(vcd, check) + check.Assert(albController, NotNil) + + importableClouds, err := albController.GetAllAlbImportableClouds(nil) + check.Assert(err, IsNil) + check.Assert(len(importableClouds) > 0, Equals, true) + + albCloudConfig := &types.NsxtAlbCloud{ + Name: check.TestName(), + Description: "alb-cloud-description", + LoadBalancerCloudBacking: types.NsxtAlbCloudBacking{ + BackingId: importableClouds[0].NsxtAlbImportableCloud.ID, + BackingType: types.NsxtAlbCloudBackingTypeNsxtAlb, + LoadBalancerControllerRef: types.OpenApiReference{ + ID: albController.NsxtAlbController.ID, + }, + }, + NetworkPoolRef: &types.OpenApiReference{ + ID: importableClouds[0].NsxtAlbImportableCloud.NetworkPoolRef.ID, + }, + } + + createdAlbCloud, err := vcd.client.CreateAlbCloud(albCloudConfig) + check.Assert(err, IsNil) + openApiEndpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointAlbCloud + createdAlbCloud.NsxtAlbCloud.ID + AddToCleanupListOpenApi(createdAlbCloud.NsxtAlbCloud.Name, check.TestName(), openApiEndpoint) + + // Get all clouds and ensure the needed on is found + allClouds, err := vcd.client.GetAllAlbClouds(nil) + check.Assert(err, IsNil) + var foundCreatedCloud bool + for cloudIndex := range allClouds { + if allClouds[cloudIndex].NsxtAlbCloud.ID == createdAlbCloud.NsxtAlbCloud.ID { + foundCreatedCloud = true + break + } + } + check.Assert(foundCreatedCloud, Equals, true) + + // Filter lookup by name + filter := url.Values{} + filter.Add("filter", "name=="+createdAlbCloud.NsxtAlbCloud.Name) + allCloudsFiltered, err := vcd.client.GetAllAlbClouds(filter) + check.Assert(err, IsNil) + check.Assert(len(allCloudsFiltered), Equals, 1) + check.Assert(allCloudsFiltered[0].NsxtAlbCloud.ID, Equals, createdAlbCloud.NsxtAlbCloud.ID) + + // Get by Name + albCloudByName, err := vcd.client.GetAlbCloudByName(createdAlbCloud.NsxtAlbCloud.Name) + check.Assert(err, IsNil) + check.Assert(albCloudByName.NsxtAlbCloud.Name, Equals, createdAlbCloud.NsxtAlbCloud.Name) + + // Get by ID + albCloudById, err := vcd.client.GetAlbCloudById(createdAlbCloud.NsxtAlbCloud.ID) + check.Assert(err, IsNil) + check.Assert(albCloudById.NsxtAlbCloud.Name, Equals, createdAlbCloud.NsxtAlbCloud.Name) + + // Cleanup + err = createdAlbCloud.Delete() + check.Assert(err, IsNil) + + _, err = vcd.client.GetAlbCloudByName(createdAlbCloud.NsxtAlbCloud.Name) + check.Assert(ContainsNotFound(err), Equals, true) + + err = albController.Delete() + check.Assert(err, IsNil) +} + +func spawnAlbControllerAndCloud(vcd *TestVCD, check *C) (*NsxtAlbController, *NsxtAlbCloud) { + albController := spawnAlbController(vcd, check) + check.Assert(albController, NotNil) + + importableClouds, err := albController.GetAllAlbImportableClouds(nil) + check.Assert(err, IsNil) + check.Assert(len(importableClouds) > 0, Equals, true) + + albCloudConfig := &types.NsxtAlbCloud{ + Name: check.TestName(), + Description: "alb-cloud-description", + LoadBalancerCloudBacking: types.NsxtAlbCloudBacking{ + BackingId: importableClouds[0].NsxtAlbImportableCloud.ID, + BackingType: types.NsxtAlbCloudBackingTypeNsxtAlb, + LoadBalancerControllerRef: types.OpenApiReference{ + ID: albController.NsxtAlbController.ID, + }, + }, + NetworkPoolRef: &types.OpenApiReference{ + ID: importableClouds[0].NsxtAlbImportableCloud.NetworkPoolRef.ID, + }, + } + + createdAlbCloud, err := vcd.client.CreateAlbCloud(albCloudConfig) + check.Assert(err, IsNil) + + openApiEndpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointAlbCloud + createdAlbCloud.NsxtAlbCloud.ID + AddToCleanupListOpenApi(createdAlbCloud.NsxtAlbCloud.Name, check.TestName(), openApiEndpoint) + + return albController, createdAlbCloud +} diff --git a/govcd/nsxt_alb_controllers.go b/govcd/nsxt_alb_controllers.go new file mode 100644 index 000000000..5c35c65ad --- /dev/null +++ b/govcd/nsxt_alb_controllers.go @@ -0,0 +1,233 @@ +/* + * Copyright 2021 VMware, Inc. All rights reserved. Licensed under the Apache v2 License. + */ + +package govcd + +import ( + "errors" + "fmt" + "net/url" + + "github.com/vmware/go-vcloud-director/v2/types/v56" +) + +// NsxtAlbController helps to integrate VMware Cloud Director with NSX-T Advanced Load Balancer deployment. +// Controller instances are registered with VMware Cloud Director instance. Controller instances serve as a central +// control plane for the load-balancing services provided by NSX-T Advanced Load Balancer. +type NsxtAlbController struct { + NsxtAlbController *types.NsxtAlbController + vcdClient *VCDClient +} + +// GetAllAlbControllers returns all configured NSX-T ALB Controllers +func (vcdClient *VCDClient) GetAllAlbControllers(queryParameters url.Values) ([]*NsxtAlbController, error) { + client := vcdClient.Client + if !client.IsSysAdmin { + return nil, errors.New("reading NSX-T ALB Controllers require System user") + } + + endpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointAlbController + apiVersion, err := client.checkOpenApiEndpointCompatibility(endpoint) + if err != nil { + return nil, err + } + + urlRef, err := client.OpenApiBuildEndpoint(endpoint) + if err != nil { + return nil, err + } + + typeResponses := []*types.NsxtAlbController{{}} + err = client.OpenApiGetAllItems(apiVersion, urlRef, queryParameters, &typeResponses, nil) + if err != nil { + return nil, err + } + + // Wrap all typeResponses into NsxtAlbController types with client + wrappedResponses := make([]*NsxtAlbController, len(typeResponses)) + for sliceIndex := range typeResponses { + wrappedResponses[sliceIndex] = &NsxtAlbController{ + NsxtAlbController: typeResponses[sliceIndex], + vcdClient: vcdClient, + } + } + + return wrappedResponses, nil +} + +// GetAlbControllerByName returns NSX-T ALB Controller by Name +func (vcdClient *VCDClient) GetAlbControllerByName(name string) (*NsxtAlbController, error) { + + queryParameters := copyOrNewUrlValues(nil) + queryParameters.Add("filter", "name=="+name) + + controllers, err := vcdClient.GetAllAlbControllers(queryParameters) + if err != nil { + return nil, fmt.Errorf("error reading ALB Controller with Name '%s': %s", name, err) + } + + if len(controllers) == 0 { + return nil, fmt.Errorf("%s: could not find ALB Controller with Name '%s'", ErrorEntityNotFound, name) + } + + if len(controllers) > 1 { + return nil, fmt.Errorf("found more than 1 ALB Controller with Name '%s'", name) + } + + return controllers[0], nil +} + +// GetAlbControllerById returns NSX-T ALB Controller by ID +func (vcdClient *VCDClient) GetAlbControllerById(id string) (*NsxtAlbController, error) { + client := vcdClient.Client + if !client.IsSysAdmin { + return nil, errors.New("reading NSX-T ALB Controllers require System user") + } + + if id == "" { + return nil, fmt.Errorf("ID is required to lookup NSX-T ALB Controller by ID") + } + + endpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointAlbController + apiVersion, err := client.checkOpenApiEndpointCompatibility(endpoint) + if err != nil { + return nil, err + } + + urlRef, err := client.OpenApiBuildEndpoint(endpoint, id) + if err != nil { + return nil, err + } + + typeResponse := &types.NsxtAlbController{} + err = client.OpenApiGetItem(apiVersion, urlRef, nil, &typeResponse, nil) + if err != nil { + return nil, err + } + + wrappedResponse := &NsxtAlbController{ + NsxtAlbController: typeResponse, + vcdClient: nil, + } + + return wrappedResponse, nil +} + +// GetAlbControllerByUrl returns configured ALB Controller by URL +// +// Note. Filtering is performed on client side. +func (vcdClient *VCDClient) GetAlbControllerByUrl(url string) (*NsxtAlbController, error) { + // Ideally this function could filter on VCD side, but API does not support filtering on URL + + controllers, err := vcdClient.GetAllAlbControllers(nil) + if err != nil { + return nil, fmt.Errorf("error reading ALB Controller with Url '%s': %s", url, err) + } + + // Search for controllers + filteredControllers := make([]*NsxtAlbController, 0) + for _, controller := range controllers { + if controller.NsxtAlbController.Url == url { + filteredControllers = append(filteredControllers, controller) + } + } + + if len(filteredControllers) == 0 { + return nil, fmt.Errorf("%s could not find ALB Controller by Url '%s'", ErrorEntityNotFound, url) + } + + if len(filteredControllers) > 1 { + return nil, fmt.Errorf("found more than 1 ALB Controller by Url '%s'", url) + } + + return filteredControllers[0], nil +} + +// CreateNsxtAlbController creates controller with supplied albControllerConfig configuration +func (vcdClient *VCDClient) CreateNsxtAlbController(albControllerConfig *types.NsxtAlbController) (*NsxtAlbController, error) { + client := vcdClient.Client + if !client.IsSysAdmin { + return nil, errors.New("handling NSX-T ALB Controllers require System user") + } + + endpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointAlbController + minimumApiVersion, err := client.checkOpenApiEndpointCompatibility(endpoint) + if err != nil { + return nil, err + } + + urlRef, err := client.OpenApiBuildEndpoint(endpoint) + if err != nil { + return nil, err + } + + returnObject := &NsxtAlbController{ + NsxtAlbController: &types.NsxtAlbController{}, + vcdClient: vcdClient, + } + + err = client.OpenApiPostItem(minimumApiVersion, urlRef, nil, albControllerConfig, returnObject.NsxtAlbController, nil) + if err != nil { + return nil, fmt.Errorf("error creating NSX-T ALB Controller: %s", err) + } + + return returnObject, nil +} + +// Update updates existing NSX-T ALB Controller with new supplied albControllerConfig configuration +func (nsxtAlbController *NsxtAlbController) Update(albControllerConfig *types.NsxtAlbController) (*NsxtAlbController, error) { + client := nsxtAlbController.vcdClient.Client + endpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointAlbController + minimumApiVersion, err := client.checkOpenApiEndpointCompatibility(endpoint) + if err != nil { + return nil, err + } + + if albControllerConfig.ID == "" { + return nil, fmt.Errorf("cannot update NSX-T ALB Controller without ID") + } + + urlRef, err := client.OpenApiBuildEndpoint(endpoint, albControllerConfig.ID) + if err != nil { + return nil, err + } + + responseAlbController := &NsxtAlbController{ + NsxtAlbController: &types.NsxtAlbController{}, + vcdClient: nsxtAlbController.vcdClient, + } + + err = client.OpenApiPutItem(minimumApiVersion, urlRef, nil, albControllerConfig, responseAlbController.NsxtAlbController, nil) + if err != nil { + return nil, fmt.Errorf("error updating NSX-T ALB Controller: %s", err) + } + + return responseAlbController, nil +} + +// Delete deletes existing NSX-T ALB Controller +func (nsxtAlbController *NsxtAlbController) Delete() error { + client := nsxtAlbController.vcdClient.Client + endpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointAlbController + minimumApiVersion, err := client.checkOpenApiEndpointCompatibility(endpoint) + if err != nil { + return err + } + + if nsxtAlbController.NsxtAlbController.ID == "" { + return fmt.Errorf("cannot delete NSX-T ALB Controller without ID") + } + + urlRef, err := client.OpenApiBuildEndpoint(endpoint, nsxtAlbController.NsxtAlbController.ID) + if err != nil { + return err + } + + err = client.OpenApiDeleteItem(minimumApiVersion, urlRef, nil, nil) + if err != nil { + return fmt.Errorf("error deleting NSX-T ALB Controller: %s", err) + } + + return nil +} diff --git a/govcd/nsxt_alb_controllers_test.go b/govcd/nsxt_alb_controllers_test.go new file mode 100644 index 000000000..fc6eaed07 --- /dev/null +++ b/govcd/nsxt_alb_controllers_test.go @@ -0,0 +1,107 @@ +//go:build alb || functional || ALL +// +build alb functional ALL + +package govcd + +import ( + "fmt" + "net/url" + + "github.com/vmware/go-vcloud-director/v2/types/v56" + + . "gopkg.in/check.v1" +) + +// Test_NsxtAlbController tests out NSX-T ALB Controller capabilities +func (vcd *TestVCD) Test_NsxtAlbController(check *C) { + if vcd.skipAdminTests { + check.Skip(fmt.Sprintf(TestRequiresSysAdminPrivileges, check.TestName())) + } + skipNoNsxtAlbConfiguration(vcd, check) + + newController := spawnAlbController(vcd, check) + + // Get by Url + controllerByUrl, err := vcd.client.GetAlbControllerByUrl(newController.NsxtAlbController.Url) + check.Assert(err, IsNil) + + // Get by Name + controllerByName, err := vcd.client.GetAlbControllerByName(controllerByUrl.NsxtAlbController.Name) + check.Assert(err, IsNil) + check.Assert(controllerByName.NsxtAlbController.ID, Equals, controllerByUrl.NsxtAlbController.ID) + + // Get by ID + controllerById, err := vcd.client.GetAlbControllerById(controllerByUrl.NsxtAlbController.ID) + check.Assert(err, IsNil) + check.Assert(controllerById.NsxtAlbController.ID, Equals, controllerByName.NsxtAlbController.ID) + + // Get all Controllers and expect to find at least the known one + allControllers, err := vcd.client.GetAllAlbControllers(nil) + check.Assert(err, IsNil) + check.Assert(len(allControllers) > 0, Equals, true) + var foundController bool + for controllerIndex := range allControllers { + if allControllers[controllerIndex].NsxtAlbController.ID == controllerByUrl.NsxtAlbController.ID { + foundController = true + } + } + check.Assert(foundController, Equals, true) + + // Check filtering for GetAllAlbControllers works + filter := url.Values{} + filter.Add("filter", "name=="+controllerByUrl.NsxtAlbController.Name) + filteredControllers, err := vcd.client.GetAllAlbControllers(nil) + check.Assert(err, IsNil) + check.Assert(len(filteredControllers), Equals, 1) + check.Assert(filteredControllers[0].NsxtAlbController.ID, Equals, controllerByUrl.NsxtAlbController.ID) + + // Test update of ALB controller + updateControllerDef := &types.NsxtAlbController{ + ID: controllerByUrl.NsxtAlbController.ID, + Name: controllerByUrl.NsxtAlbController.Name + "-update", + Description: "Description set", + Url: vcd.config.VCD.Nsxt.NsxtAlbControllerUrl, + Username: vcd.config.VCD.Nsxt.NsxtAlbControllerUser, + Password: vcd.config.VCD.Nsxt.NsxtAlbControllerPassword, + LicenseType: "BASIC", + } + updatedController, err := controllerByUrl.Update(updateControllerDef) + check.Assert(err, IsNil) + check.Assert(updatedController.NsxtAlbController.Name, Equals, updateControllerDef.Name) + check.Assert(updatedController.NsxtAlbController.Description, Equals, updateControllerDef.Description) + check.Assert(updatedController.NsxtAlbController.Url, Equals, updateControllerDef.Url) + check.Assert(updatedController.NsxtAlbController.Username, Equals, updateControllerDef.Username) + check.Assert(updatedController.NsxtAlbController.LicenseType, Equals, updateControllerDef.LicenseType) + + // Revert settings to original ones + _, err = controllerByUrl.Update(controllerByUrl.NsxtAlbController) + check.Assert(err, IsNil) + + // Remove and make sure it is not found + err = updatedController.Delete() + check.Assert(err, IsNil) + + // Try to find controller and expect an + _, err = vcd.client.GetAlbControllerByName(controllerByUrl.NsxtAlbController.Name) + check.Assert(ContainsNotFound(err), Equals, true) +} + +func spawnAlbController(vcd *TestVCD, check *C) *NsxtAlbController { + newControllerDef := &types.NsxtAlbController{ + Name: "aviController1", + Url: vcd.config.VCD.Nsxt.NsxtAlbControllerUrl, + Username: vcd.config.VCD.Nsxt.NsxtAlbControllerUser, + Password: vcd.config.VCD.Nsxt.NsxtAlbControllerPassword, + LicenseType: "ENTERPRISE", + } + + newController, err := vcd.client.CreateNsxtAlbController(newControllerDef) + check.Assert(err, IsNil) + check.Assert(newController.NsxtAlbController.ID, Not(Equals), "") + + // The ALB Controller was not present during this test run therefore it is going to be cleaned up in the end of tests + openApiEndpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointAlbController + newController.NsxtAlbController.ID + AddToCleanupListOpenApi(newController.NsxtAlbController.Name, check.TestName(), openApiEndpoint) + + return newController +} diff --git a/govcd/nsxt_alb_importable_clouds.go b/govcd/nsxt_alb_importable_clouds.go new file mode 100644 index 000000000..7117150f3 --- /dev/null +++ b/govcd/nsxt_alb_importable_clouds.go @@ -0,0 +1,116 @@ +/* + * Copyright 2021 VMware, Inc. All rights reserved. Licensed under the Apache v2 License. + */ + +package govcd + +import ( + "errors" + "fmt" + "net/url" + + "github.com/vmware/go-vcloud-director/v2/types/v56" +) + +// NsxtAlbImportableCloud allows user to list importable NSX-T ALB Clouds. Each importable cloud can only be imported +// once. It has a flag AlreadyImported which hints if it is already consumed or not. +type NsxtAlbImportableCloud struct { + NsxtAlbImportableCloud *types.NsxtAlbImportableCloud + vcdClient *VCDClient +} + +// GetAllAlbImportableClouds returns importable NSX-T ALB Clouds. +// ID of parentAlbControllerUrn is mandatory +func (vcdClient *VCDClient) GetAllAlbImportableClouds(parentAlbControllerUrn string, queryParameters url.Values) ([]*NsxtAlbImportableCloud, error) { + client := vcdClient.Client + if parentAlbControllerUrn == "" { + return nil, fmt.Errorf("parentAlbControllerUrn is required") + } + if !client.IsSysAdmin { + return nil, errors.New("handling NSX-T ALB Importable Clouds require System user") + } + + endpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointAlbImportableClouds + apiVersion, err := client.checkOpenApiEndpointCompatibility(endpoint) + if err != nil { + return nil, err + } + + urlRef, err := client.OpenApiBuildEndpoint(endpoint) + if err != nil { + return nil, err + } + + queryParams := copyOrNewUrlValues(queryParameters) + queryParams = queryParameterFilterAnd(fmt.Sprintf("_context==%s", parentAlbControllerUrn), queryParams) + typeResponses := []*types.NsxtAlbImportableCloud{{}} + err = client.OpenApiGetAllItems(apiVersion, urlRef, queryParams, &typeResponses, nil) + if err != nil { + return nil, err + } + + wrappedResponses := make([]*NsxtAlbImportableCloud, len(typeResponses)) + for sliceIndex := range typeResponses { + wrappedResponses[sliceIndex] = &NsxtAlbImportableCloud{ + NsxtAlbImportableCloud: typeResponses[sliceIndex], + vcdClient: vcdClient, + } + } + + return wrappedResponses, nil +} + +// GetAlbImportableCloudByName returns importable NSX-T ALB Clouds. +func (vcdClient *VCDClient) GetAlbImportableCloudByName(parentAlbControllerUrn, name string) (*NsxtAlbImportableCloud, error) { + albImportableClouds, err := vcdClient.GetAllAlbImportableClouds(parentAlbControllerUrn, nil) + if err != nil { + return nil, fmt.Errorf("error finding NSX-T ALB Importable Cloud by Name '%s': %s", name, err) + } + + // Filtering by ID is not supported therefore it must be filtered on client side + var foundResult bool + var foundAlbImportableCloud *NsxtAlbImportableCloud + for i, value := range albImportableClouds { + if albImportableClouds[i].NsxtAlbImportableCloud.DisplayName == name { + foundResult = true + foundAlbImportableCloud = value + break + } + } + + if !foundResult { + return nil, fmt.Errorf("%s: could not find NSX-T ALB Importable Cloud by Name %s", ErrorEntityNotFound, name) + } + + return foundAlbImportableCloud, nil +} + +// GetAlbImportableCloudById returns importable NSX-T ALB Clouds. +// Note. ID filtering is performed on client side +func (vcdClient *VCDClient) GetAlbImportableCloudById(parentAlbControllerUrn, id string) (*NsxtAlbImportableCloud, error) { + albImportableClouds, err := vcdClient.GetAllAlbImportableClouds(parentAlbControllerUrn, nil) + if err != nil { + return nil, fmt.Errorf("error finding NSX-T ALB Importable Cloud by ID '%s': %s", id, err) + } + + // Filtering by ID is not supported therefore it must be filtered on client side + var foundResult bool + var foundAlbImportableCloud *NsxtAlbImportableCloud + for i, value := range albImportableClouds { + if albImportableClouds[i].NsxtAlbImportableCloud.ID == id { + foundResult = true + foundAlbImportableCloud = value + } + } + + if !foundResult { + return nil, fmt.Errorf("%s: could not find NSX-T ALB Importable Cloud by ID %s", ErrorEntityNotFound, id) + } + + return foundAlbImportableCloud, nil +} + +// GetAllAlbImportableClouds is attached to NsxtAlbController type for a convenient parent/child relationship +func (nsxtAlbController *NsxtAlbController) GetAllAlbImportableClouds(queryParameters url.Values) ([]*NsxtAlbImportableCloud, error) { + return nsxtAlbController.vcdClient.GetAllAlbImportableClouds(nsxtAlbController.NsxtAlbController.ID, queryParameters) +} diff --git a/govcd/nsxt_alb_importable_clouds_test.go b/govcd/nsxt_alb_importable_clouds_test.go new file mode 100644 index 000000000..43e339a4e --- /dev/null +++ b/govcd/nsxt_alb_importable_clouds_test.go @@ -0,0 +1,38 @@ +//go:build alb || functional || ALL +// +build alb functional ALL + +package govcd + +import ( + "fmt" + + . "gopkg.in/check.v1" +) + +// Test_GetAllAlbImportableClouds tests if if there is at least one importable cloud available +func (vcd *TestVCD) Test_GetAllAlbImportableClouds(check *C) { + if vcd.skipAdminTests { + check.Skip(fmt.Sprintf(TestRequiresSysAdminPrivileges, check.TestName())) + } + skipNoNsxtAlbConfiguration(vcd, check) + + albController := spawnAlbController(vcd, check) + + controllers, err := vcd.client.GetAllAlbControllers(nil) + check.Assert(err, IsNil) + check.Assert(len(controllers) > 0, Equals, true) + + // Test client function with explicit ALB Controller ID requirement + clientImportableClouds, err := vcd.client.GetAllAlbImportableClouds(controllers[0].NsxtAlbController.ID, nil) + check.Assert(err, IsNil) + check.Assert(len(clientImportableClouds) > 0, Equals, true) + + // Test function attached directly to NsxtAlbController + controllerImportableClouds, err := controllers[0].GetAllAlbImportableClouds(nil) + check.Assert(err, IsNil) + check.Assert(len(controllerImportableClouds) > 0, Equals, true) + + // Cleanup + err = albController.Delete() + check.Assert(err, IsNil) +} diff --git a/govcd/nsxt_alb_importable_service_engine_groups.go b/govcd/nsxt_alb_importable_service_engine_groups.go new file mode 100644 index 000000000..08cb0d198 --- /dev/null +++ b/govcd/nsxt_alb_importable_service_engine_groups.go @@ -0,0 +1,107 @@ +/* + * Copyright 2021 VMware, Inc. All rights reserved. Licensed under the Apache v2 License. + */ + +package govcd + +import ( + "errors" + "fmt" + "net/url" + + "github.com/vmware/go-vcloud-director/v2/types/v56" +) + +type NsxtAlbImportableServiceEngineGroups struct { + NsxtAlbImportableServiceEngineGroups *types.NsxtAlbImportableServiceEngineGroups + client *Client +} + +func (vcdClient *VCDClient) GetAllAlbImportableServiceEngineGroups(parentAlbCloudUrn string, queryParameters url.Values) ([]*NsxtAlbImportableServiceEngineGroups, error) { + client := vcdClient.Client + if parentAlbCloudUrn == "" { + return nil, fmt.Errorf("parentAlbCloudUrn is required") + } + if !client.IsSysAdmin { + return nil, errors.New("handling NSX-T ALB Importable Service Engine Groups requires System user") + } + + endpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointAlbImportableServiceEngineGroups + apiVersion, err := client.checkOpenApiEndpointCompatibility(endpoint) + if err != nil { + return nil, err + } + + urlRef, err := client.OpenApiBuildEndpoint(endpoint) + if err != nil { + return nil, err + } + + queryParams := copyOrNewUrlValues(queryParameters) + queryParams = queryParameterFilterAnd(fmt.Sprintf("_context==%s", parentAlbCloudUrn), queryParams) + typeResponses := []*types.NsxtAlbImportableServiceEngineGroups{{}} + err = client.OpenApiGetAllItems(apiVersion, urlRef, queryParams, &typeResponses, nil) + if err != nil { + return nil, err + } + + wrappedResponses := make([]*NsxtAlbImportableServiceEngineGroups, len(typeResponses)) + for sliceIndex := range typeResponses { + wrappedResponses[sliceIndex] = &NsxtAlbImportableServiceEngineGroups{ + NsxtAlbImportableServiceEngineGroups: typeResponses[sliceIndex], + client: &client, + } + } + + return wrappedResponses, nil +} + +// GetAlbImportableServiceEngineGroupByName returns importable NSX-T ALB Clouds. +func (vcdClient *VCDClient) GetAlbImportableServiceEngineGroupByName(parentAlbCloudUrn, name string) (*NsxtAlbImportableServiceEngineGroups, error) { + albClouds, err := vcdClient.GetAllAlbImportableServiceEngineGroups(parentAlbCloudUrn, nil) + if err != nil { + return nil, fmt.Errorf("error finding NSX-T ALB Importable Service Engine Group by Name '%s': %s", name, err) + } + + // Filtering by ID is not supported therefore it must be filtered on client side + var foundResult bool + var foundAlbCloud *NsxtAlbImportableServiceEngineGroups + for i, value := range albClouds { + if albClouds[i].NsxtAlbImportableServiceEngineGroups.DisplayName == name { + foundResult = true + foundAlbCloud = value + break + } + } + + if !foundResult { + return nil, fmt.Errorf("%s: could not find NSX-T ALB Importable Service Engine Group by Name %s", ErrorEntityNotFound, name) + } + + return foundAlbCloud, nil +} + +// GetAlbImportableServiceEngineGroupById +// Note. ID filtering is performed on client side +func (vcdClient *VCDClient) GetAlbImportableServiceEngineGroupById(parentAlbCloudUrn, id string) (*NsxtAlbImportableServiceEngineGroups, error) { + albClouds, err := vcdClient.GetAllAlbImportableServiceEngineGroups(parentAlbCloudUrn, nil) + if err != nil { + return nil, fmt.Errorf("error finding NSX-T ALB Importable Service Engine Group by ID '%s': %s", id, err) + } + + // Filtering by ID is not supported therefore it must be filtered on client side + var foundResult bool + var foundImportableSEGroups *NsxtAlbImportableServiceEngineGroups + for i, value := range albClouds { + if albClouds[i].NsxtAlbImportableServiceEngineGroups.ID == id { + foundResult = true + foundImportableSEGroups = value + } + } + + if !foundResult { + return nil, fmt.Errorf("%s: could not find NSX-T ALB Importable Service Engine Group by ID %s", ErrorEntityNotFound, id) + } + + return foundImportableSEGroups, nil +} diff --git a/govcd/nsxt_alb_importable_service_engine_groups_test.go b/govcd/nsxt_alb_importable_service_engine_groups_test.go new file mode 100644 index 000000000..6d6b3689a --- /dev/null +++ b/govcd/nsxt_alb_importable_service_engine_groups_test.go @@ -0,0 +1,31 @@ +//go:build alb || functional || ALL +// +build alb functional ALL + +package govcd + +import ( + "fmt" + + . "gopkg.in/check.v1" +) + +func (vcd *TestVCD) Test_GetAllAlbImportableServiceEngineGroups(check *C) { + if vcd.skipAdminTests { + check.Skip(fmt.Sprintf(TestRequiresSysAdminPrivileges, check.TestName())) + } + albController, createdAlbCloud := spawnAlbControllerAndCloud(vcd, check) + + importableSeGroups, err := vcd.client.GetAllAlbImportableServiceEngineGroups(createdAlbCloud.NsxtAlbCloud.ID, nil) + check.Assert(err, IsNil) + check.Assert(len(importableSeGroups) > 0, Equals, true) + check.Assert(importableSeGroups[0].NsxtAlbImportableServiceEngineGroups.ID != "", Equals, true) + check.Assert(importableSeGroups[0].NsxtAlbImportableServiceEngineGroups.DisplayName != "", Equals, true) + check.Assert(importableSeGroups[0].NsxtAlbImportableServiceEngineGroups.HaMode != "", Equals, true) + + // Cleanup + err = createdAlbCloud.Delete() + check.Assert(err, IsNil) + + err = albController.Delete() + check.Assert(err, IsNil) +} diff --git a/govcd/nsxt_alb_service_engine_groups.go b/govcd/nsxt_alb_service_engine_groups.go new file mode 100644 index 000000000..63e69f6ce --- /dev/null +++ b/govcd/nsxt_alb_service_engine_groups.go @@ -0,0 +1,201 @@ +/* + * Copyright 2021 VMware, Inc. All rights reserved. Licensed under the Apache v2 License. + */ + +package govcd + +import ( + "errors" + "fmt" + "net/url" + + "github.com/vmware/go-vcloud-director/v2/types/v56" +) + +// NsxtAlbServiceEngineGroup allows users to provide virtual service management capabilities to your tenants, import +// service engine groups to your VMware Cloud Director deployment. +// A service engine group is an isolation domain that also defines shared service engine properties, such as size, +// network access, and failover. Resources in a service engine group can be used for different virtual services, +// depending on your tenant needs. These resources cannot be shared between different service engine groups. +type NsxtAlbServiceEngineGroup struct { + NsxtAlbServiceEngineGroup *types.NsxtAlbServiceEngineGroup + vcdClient *VCDClient +} + +// GetAllNsxtAlbServiceEngineGroups retrieves NSX-T ALB Service Engines with possible filters +func (vcdClient *VCDClient) GetAllNsxtAlbServiceEngineGroups(context string, queryParameters url.Values) ([]*NsxtAlbServiceEngineGroup, error) { + client := vcdClient.Client + + if !client.IsSysAdmin { + return nil, errors.New("handling NSX-T ALB Service Engine Groups require System user") + } + + endpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointAlbServiceEngineGroups + apiVersion, err := client.checkOpenApiEndpointCompatibility(endpoint) + if err != nil { + return nil, err + } + + urlRef, err := client.OpenApiBuildEndpoint(endpoint) + if err != nil { + return nil, err + } + + queryParams := copyOrNewUrlValues(queryParameters) + if context != "" { + queryParams = queryParameterFilterAnd(fmt.Sprintf("_context==%s", context), queryParams) + } + typeResponses := []*types.NsxtAlbServiceEngineGroup{{}} + + err = client.OpenApiGetAllItems(apiVersion, urlRef, queryParams, &typeResponses, nil) + if err != nil { + return nil, err + } + + wrappedResponses := make([]*NsxtAlbServiceEngineGroup, len(typeResponses)) + for sliceIndex := range typeResponses { + wrappedResponses[sliceIndex] = &NsxtAlbServiceEngineGroup{ + NsxtAlbServiceEngineGroup: typeResponses[sliceIndex], + vcdClient: vcdClient, + } + } + + return wrappedResponses, nil +} + +// GetAlbServiceEngineGroupByName returns NSX-T ALB Service Engine by Name +func (vcdClient *VCDClient) GetAlbServiceEngineGroupByName(context, name string) (*NsxtAlbServiceEngineGroup, error) { + albClouds, err := vcdClient.GetAllNsxtAlbServiceEngineGroups(context, nil) + if err != nil { + return nil, fmt.Errorf("error finding NSX-T ALB Service Engine Group by Name '%s': %s", name, err) + } + + // Filtering by ID is not supported therefore it must be filtered on client side + var foundResult bool + var foundAlbCloud *NsxtAlbServiceEngineGroup + for i, value := range albClouds { + if albClouds[i].NsxtAlbServiceEngineGroup.Name == name { + foundResult = true + foundAlbCloud = value + break + } + } + + if !foundResult { + return nil, fmt.Errorf("%s: could not find NSX-T ALB Service Engine Group by Name %s", ErrorEntityNotFound, name) + } + + return foundAlbCloud, nil +} + +// GetAlbServiceEngineGroupById returns importable NSX-T ALB Clouds. +// Note. ID filtering is performed on client side +func (vcdClient *VCDClient) GetAlbServiceEngineGroupById(context, id string) (*NsxtAlbServiceEngineGroup, error) { + albClouds, err := vcdClient.GetAllNsxtAlbServiceEngineGroups(context, nil) + if err != nil { + return nil, fmt.Errorf("error finding Alb Cloud by ID '%s': %s", id, err) + } + + // Filtering by ID is not supported therefore it must be filtered on client side + var foundResult bool + var foundAlbCloud *NsxtAlbServiceEngineGroup + for i, value := range albClouds { + if albClouds[i].NsxtAlbServiceEngineGroup.ID == id { + foundResult = true + foundAlbCloud = value + } + } + + if !foundResult { + return nil, fmt.Errorf("%s: could not find NSX-T ALB Service Engine Group by ID %s", ErrorEntityNotFound, id) + } + + return foundAlbCloud, nil +} + +func (vcdClient *VCDClient) CreateNsxtAlbServiceEngineGroup(albServiceEngineGroup *types.NsxtAlbServiceEngineGroup) (*NsxtAlbServiceEngineGroup, error) { + client := vcdClient.Client + if !client.IsSysAdmin { + return nil, errors.New("handling NSX-T ALB Service Engine Groups require System user") + } + + endpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointAlbServiceEngineGroups + minimumApiVersion, err := client.checkOpenApiEndpointCompatibility(endpoint) + if err != nil { + return nil, err + } + + urlRef, err := client.OpenApiBuildEndpoint(endpoint) + if err != nil { + return nil, err + } + + returnObject := &NsxtAlbServiceEngineGroup{ + NsxtAlbServiceEngineGroup: &types.NsxtAlbServiceEngineGroup{}, + vcdClient: vcdClient, + } + + err = client.OpenApiPostItem(minimumApiVersion, urlRef, nil, albServiceEngineGroup, returnObject.NsxtAlbServiceEngineGroup, nil) + if err != nil { + return nil, fmt.Errorf("error creating NSX-T ALB Service Engine Group: %s", err) + } + + return returnObject, nil +} + +// +//// Update updates existing ALB Controller with new supplied albControllerConfig configuration +func (nsxtAlbServiceEngineGroup *NsxtAlbServiceEngineGroup) Update(albSEGroupConfig *types.NsxtAlbServiceEngineGroup) (*NsxtAlbServiceEngineGroup, error) { + client := nsxtAlbServiceEngineGroup.vcdClient.Client + endpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointAlbServiceEngineGroups + minimumApiVersion, err := client.checkOpenApiEndpointCompatibility(endpoint) + if err != nil { + return nil, err + } + + if albSEGroupConfig.ID == "" { + return nil, fmt.Errorf("cannot update NSX-T ALB Service Engine Group without ID") + } + + urlRef, err := client.OpenApiBuildEndpoint(endpoint, albSEGroupConfig.ID) + if err != nil { + return nil, err + } + + responseAlbController := &NsxtAlbServiceEngineGroup{ + NsxtAlbServiceEngineGroup: &types.NsxtAlbServiceEngineGroup{}, + vcdClient: nsxtAlbServiceEngineGroup.vcdClient, + } + + err = client.OpenApiPutItem(minimumApiVersion, urlRef, nil, albSEGroupConfig, responseAlbController.NsxtAlbServiceEngineGroup, nil) + if err != nil { + return nil, fmt.Errorf("error updating NSX-T ALB Service Engine Group: %s", err) + } + + return responseAlbController, nil +} + +func (nsxtAlbServiceEngineGroup *NsxtAlbServiceEngineGroup) Delete() error { + client := nsxtAlbServiceEngineGroup.vcdClient.Client + endpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointAlbServiceEngineGroups + minimumApiVersion, err := client.checkOpenApiEndpointCompatibility(endpoint) + if err != nil { + return err + } + + if nsxtAlbServiceEngineGroup.NsxtAlbServiceEngineGroup.ID == "" { + return fmt.Errorf("cannot delete NSX-T ALB Service Engine Group without ID") + } + + urlRef, err := client.OpenApiBuildEndpoint(endpoint, nsxtAlbServiceEngineGroup.NsxtAlbServiceEngineGroup.ID) + if err != nil { + return err + } + + err = client.OpenApiDeleteItem(minimumApiVersion, urlRef, nil, nil) + if err != nil { + return fmt.Errorf("error deleting NSX-T ALB Service Engine Group: %s", err) + } + + return nil +} diff --git a/govcd/nsxt_alb_service_engine_groups_test.go b/govcd/nsxt_alb_service_engine_groups_test.go new file mode 100644 index 000000000..f707faecd --- /dev/null +++ b/govcd/nsxt_alb_service_engine_groups_test.go @@ -0,0 +1,74 @@ +//go:build alb || functional || ALL +// +build alb functional ALL + +package govcd + +import ( + "fmt" + + "github.com/vmware/go-vcloud-director/v2/types/v56" + . "gopkg.in/check.v1" +) + +func (vcd *TestVCD) Test_GetAllAlbServiceEngineGroups(check *C) { + if vcd.skipAdminTests { + check.Skip(fmt.Sprintf(TestRequiresSysAdminPrivileges, check.TestName())) + } + + controller, createdAlbCloud := spawnAlbControllerAndCloud(vcd, check) + + importableSeGroups, err := vcd.client.GetAllAlbImportableServiceEngineGroups(createdAlbCloud.NsxtAlbCloud.ID, nil) + check.Assert(err, IsNil) + check.Assert(len(importableSeGroups) > 0, Equals, true) + + albSeGroup := &types.NsxtAlbServiceEngineGroup{ + Name: check.TestName() + "SE-group", + Description: "Service Engine Group created by " + check.TestName(), + ReservationType: "DEDICATED", + ServiceEngineGroupBacking: types.ServiceEngineGroupBacking{ + BackingId: importableSeGroups[0].NsxtAlbImportableServiceEngineGroups.ID, + LoadBalancerCloudRef: &types.OpenApiReference{ + ID: createdAlbCloud.NsxtAlbCloud.ID, + }, + }, + } + + createdSeGroup, err := vcd.client.CreateNsxtAlbServiceEngineGroup(albSeGroup) + check.Assert(err, IsNil) + + check.Assert(createdSeGroup.NsxtAlbServiceEngineGroup.ID != "", Equals, true) + check.Assert(createdSeGroup.NsxtAlbServiceEngineGroup.Name, Equals, albSeGroup.Name) + check.Assert(createdSeGroup.NsxtAlbServiceEngineGroup.Description, Equals, albSeGroup.Description) + check.Assert(createdSeGroup.NsxtAlbServiceEngineGroup.ReservationType, Equals, albSeGroup.ReservationType) + + openApiEndpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointAlbServiceEngineGroups + createdSeGroup.NsxtAlbServiceEngineGroup.ID + AddToCleanupListOpenApi(createdSeGroup.NsxtAlbServiceEngineGroup.Name, check.TestName(), openApiEndpoint) + + // Find by Name + seGroupByName, err := vcd.client.GetAlbServiceEngineGroupByName("", createdSeGroup.NsxtAlbServiceEngineGroup.Name) + check.Assert(err, IsNil) + + // Find by ID + seGroupById, err := vcd.client.GetAlbServiceEngineGroupById("", createdSeGroup.NsxtAlbServiceEngineGroup.ID) + check.Assert(err, IsNil) + + check.Assert(seGroupByName.NsxtAlbServiceEngineGroup.ID, Equals, createdSeGroup.NsxtAlbServiceEngineGroup.ID) + check.Assert(seGroupById.NsxtAlbServiceEngineGroup.ID, Equals, createdSeGroup.NsxtAlbServiceEngineGroup.ID) + + // Test update + createdSeGroup.NsxtAlbServiceEngineGroup.Name = createdSeGroup.NsxtAlbServiceEngineGroup.Name + "updated" + updatedSeGroup, err := createdSeGroup.Update(createdSeGroup.NsxtAlbServiceEngineGroup) + check.Assert(err, IsNil) + + check.Assert(updatedSeGroup.NsxtAlbServiceEngineGroup, DeepEquals, createdSeGroup.NsxtAlbServiceEngineGroup) + + // Cleanup + err = createdSeGroup.Delete() + check.Assert(err, IsNil) + + err = createdAlbCloud.Delete() + check.Assert(err, IsNil) + + err = controller.Delete() + check.Assert(err, IsNil) +} diff --git a/govcd/openapi_endpoints.go b/govcd/openapi_endpoints.go index 4f89dc966..e1e62beb3 100644 --- a/govcd/openapi_endpoints.go +++ b/govcd/openapi_endpoints.go @@ -43,10 +43,17 @@ var endpointMinApiVersions = map[string]string{ types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointIpSecVpnTunnel: "34.0", // VCD 10.1+ types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointIpSecVpnTunnelConnectionProperties: "34.0", // VCD 10.1+ types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointIpSecVpnTunnelStatus: "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+ + types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointAlbImportableClouds: "35.0", // VCD 10.2+ + types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointAlbImportableServiceEngineGroups: "35.0", // VCD 10.2+ + types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointAlbCloud: "35.0", // VCD 10.2+ + types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointAlbServiceEngineGroups: "35.0", // VCD 10.2+ } // elevateNsxtNatRuleApiVersion helps to elevate API version to consume newer NSX-T NAT Rule features -// API V35.2+ support new fields FirewallMatch and Priority +// API V35.2+ supports new fields FirewallMatch and Priority // API V36.0+ supports new RuleType - REFLEXIVE // endpointElevatedApiVersions endpoint elevated API versions diff --git a/types/v56/constants.go b/types/v56/constants.go index 8fcb7830a..576956230 100644 --- a/types/v56/constants.go +++ b/types/v56/constants.go @@ -358,6 +358,14 @@ const ( OpenApiEndpointIpSecVpnTunnel = "edgeGateways/%s/ipsec/tunnels/" OpenApiEndpointIpSecVpnTunnelConnectionProperties = "edgeGateways/%s/ipsec/tunnels/%s/connectionProperties" OpenApiEndpointIpSecVpnTunnelStatus = "edgeGateways/%s/ipsec/tunnels/%s/status" + + // NSX-T ALB related endpoints + OpenApiEndpointAlbController = "loadBalancer/controllers/" + // OpenApiEndpointAlbImportableClouds endpoint requires a filter _context==urn:vcloud:loadBalancerController:aa23ef66-ba32-48b2-892f-7acdffe4587e + OpenApiEndpointAlbImportableClouds = "nsxAlbResources/importableClouds/" + OpenApiEndpointAlbImportableServiceEngineGroups = "nsxAlbResources/importableServiceEngineGroups" + OpenApiEndpointAlbCloud = "loadBalancer/clouds/" + OpenApiEndpointAlbServiceEngineGroups = "loadBalancer/serviceEngineGroups/" ) // Header keys to run operations in tenant context @@ -443,3 +451,8 @@ const ( // VcloudUndefinedKey is the bundles key automatically added to new role related objects VcloudUndefinedKey = "com.vmware.vcloud.undefined.key" ) + +const ( + // NsxtAlbCloudBackingTypeNsxtAlb is a backing type for NSX-T ALB used in types.NsxtAlbCloudBacking + NsxtAlbCloudBackingTypeNsxtAlb = "NSXALB_NSXT" +) diff --git a/types/v56/nsxt_types.go b/types/v56/nsxt_types.go index 1446aaa8c..009ac41c3 100644 --- a/types/v56/nsxt_types.go +++ b/types/v56/nsxt_types.go @@ -677,3 +677,115 @@ type NsxtIpSecVpnTunnelProfileDpdConfiguration struct { // minimum is 3 seconds and the maximum is 60 seconds. ProbeInterval int `json:"probeInterval"` } + +// NsxtAlbController helps to integrate VMware Cloud Director with NSX-T Advanced Load Balancer deployment. +// Controller instances are registered with VMware Cloud Director instance. Controller instances serve as a central +// control plane for the load-balancing services provided by NSX-T Advanced Load Balancer. +type NsxtAlbController struct { + // ID holds URN for load balancer controller (e.g. urn:vcloud:loadBalancerController:aa23ef66-ba32-48b2-892f-7acdffe4587e) + ID string `json:"id,omitempty"` + // Name as shown in VCD + Name string `json:"name"` + // Description as shown in VCD + Description string `json:"description,omitempty"` + // Url of ALB controller + Url string `json:"url"` + // Username of user + Username string `json:"username"` + // Password (will not be returned on read) + Password string `json:"password,omitempty"` + // LicenseType By enabling this feature, the provider acknowledges that they have independently licensed the + // enterprise version of the NSX AVI LB. + // Possible options: 'BASIC', 'ENTERPRISE' + LicenseType string `json:"licenseType,omitempty"` + // Version of ALB (e.g. 20.1.3). Read-only + Version string `json:"version,omitempty"` +} + +// NsxtAlbImportableCloud allows user to list importable NSX-T ALB Clouds. Each importable cloud can only be imported +// once. It has a flag AlreadyImported which hints if it is already consumed or not. +type NsxtAlbImportableCloud struct { + // ID (e.g. 'cloud-43726181-f73e-41f2-bf1d-8a9609502586') + ID string `json:"id"` + + DisplayName string `json:"displayName"` + // AlreadyImported shows if this ALB Cloud is already imported + AlreadyImported bool `json:"alreadyImported"` + + // NetworkPoolRef contains a reference to NSX-T network pool + NetworkPoolRef OpenApiReference `json:"networkPoolRef"` + + // TransportZoneName contains transport zone name + TransportZoneName string `json:"transportZoneName"` +} + +// NsxtAlbCloud allows users to use the virtual infrastructure provided by NSX Advanced Load Balancer, register your +// NSX-T Cloud instances with VMware Cloud Director. An NSX-T Cloud is a service provider-level construct that consists +// of an NSX-T Manager and an NSX-T Data Center transport zone. NSX-T Manager provides a system view and is the +// management component of NSX-T Data Center. An NSX-T Data Center transport zone dictates which hosts and virtual +// machines can participate in the use of a particular network. If there are multiple transport zones managed by the +// same NSX-T Manager, then a separate NSX-T Cloud encapsulates each pair of NSX-T Manager and NSX-T Data Center +// transport zone instances. An NSX-T Cloud has a one-to-one relationship with a network pool backed by an NSX-T Data +// Center transport zone. +type NsxtAlbCloud struct { + // ID (e.g. 'urn:vcloud:loadBalancerCloud:947ea2ba-e448-4249-91f7-1432b3d2fcbf') + ID string `json:"id,omitempty"` + Status string `json:"status,omitempty"` + // Name of NSX-T ALB Cloud + Name string `json:"name"` + // Description of NSX-T ALB Cloud + Description string `json:"description,omitempty"` + // LoadBalancerCloudBacking uniquely identifies a Load Balancer Cloud configured within a Load Balancer Controller. At + // the present, VCD only supports NSX-T Clouds configured within an NSX-ALB Controller deployment. + LoadBalancerCloudBacking NsxtAlbCloudBacking `json:"loadBalancerCloudBacking"` + // NetworkPoolRef for the Network Pool associated with this Cloud + NetworkPoolRef *OpenApiReference `json:"networkPoolRef"` + // HealthStatus contains status of the Load Balancer Cloud. Possible values are: + // UP - The cloud is healthy and ready to enable Load Balancer for an Edge Gateway. + // DOWN - The cloud is in a failure state. Enabling Load balancer on an Edge Gateway may not be possible. + // RUNNING - The cloud is currently processing. An example is if it's enabling a Load Balancer for an Edge Gateway. + // UNAVAILABLE - The cloud is unavailable. + // UNKNOWN - The cloud state is unknown. + HealthStatus string `json:"healthStatus,omitempty"` + // DetailedHealthMessage contains detailed message on the health of the Cloud. + DetailedHealthMessage string `json:"detailedHealthMessage,omitempty"` +} + +// NsxtAlbCloudBacking is embedded into NsxtAlbCloud +type NsxtAlbCloudBacking struct { + // BackingId is the ID of NsxtAlbImportableCloud + BackingId string `json:"backingId"` + // BackingType contains type of ALB (The only supported now is 'NSXALB_NSXT') + BackingType string `json:"backingType,omitempty"` + // LoadBalancerControllerRef contains reference to NSX-T ALB Controller + LoadBalancerControllerRef OpenApiReference `json:"loadBalancerControllerRef"` +} + +type NsxtAlbServiceEngineGroup struct { + Status string `json:"status,omitempty"` + ID string `json:"id,omitempty"` + Name string `json:"name"` + Description string `json:"description"` + ServiceEngineGroupBacking ServiceEngineGroupBacking `json:"serviceEngineGroupBacking"` + HaMode string `json:"haMode,omitempty"` + ReservationType string `json:"reservationType"` + MaxVirtualServices int `json:"maxVirtualServices,omitempty"` + NumDeployedVirtualServices int `json:"numDeployedVirtualServices,omitempty"` + ReservedVirtualServices int `json:"reservedVirtualServices,omitempty"` + OverAllocated bool `json:"overAllocated,omitempty"` +} + +type ServiceEngineGroupBacking struct { + BackingId string `json:"backingId"` + BackingType string `json:"backingType,omitempty"` + LoadBalancerCloudRef *OpenApiReference `json:"loadBalancerCloudRef"` +} + +type NsxtAlbImportableServiceEngineGroups struct { + // ID (e.g. 'serviceenginegroup-b633f16f-2733-4bf5-b552-3a6c4949caa4') + ID string `json:"id"` + // DisplayName is the name of + DisplayName string `json:"displayName"` + // HaMode (e.g. 'ELASTIC_N_PLUS_M_BUFFER') + HaMode string `json:"haMode"` +} From 3cf20db38e2a55141dcc14d31c786e7875dad3ff Mon Sep 17 00:00:00 2001 From: Dainius Serplis Date: Mon, 6 Sep 2021 15:41:37 +0300 Subject: [PATCH 2/6] Review cleanups and improvements Signed-off-by: Dainius Serplis --- .../{xxx-features.md => 398-features.md} | 10 +- go.mod | 1 - govcd/api_vcd_test.go | 5 + govcd/nsxt_alb_clouds.go | 6 +- govcd/nsxt_alb_clouds_test.go | 13 +- govcd/nsxt_alb_controllers.go | 2 - govcd/nsxt_alb_controllers_test.go | 4 +- govcd/nsxt_alb_importable_clouds.go | 11 +- govcd/nsxt_alb_importable_clouds_test.go | 16 +-- ...xt_alb_importable_service_engine_groups.go | 96 ++++++++++++++- ...b_importable_service_engine_groups_test.go | 19 +++ govcd/nsxt_alb_service_engine_groups.go | 116 +++++++++++++----- govcd/nsxt_alb_service_engine_groups_test.go | 8 +- govcd/openapi.go | 2 +- types/v56/nsxt_types.go | 47 +++++-- 15 files changed, 279 insertions(+), 77 deletions(-) rename .changes/v2.13.0/{xxx-features.md => 398-features.md} (87%) diff --git a/.changes/v2.13.0/xxx-features.md b/.changes/v2.13.0/398-features.md similarity index 87% rename from .changes/v2.13.0/xxx-features.md rename to .changes/v2.13.0/398-features.md index deef6af24..a64271d79 100644 --- a/.changes/v2.13.0/xxx-features.md +++ b/.changes/v2.13.0/398-features.md @@ -1,14 +1,14 @@ * Added types `NsxtAlbController` and `types.NsxtAlbController` for handling NSX-T ALB Controllers with corresponding functions `GetAllAlbControllers`, `GetAlbControllerByName`, `GetAlbControllerById`, `GetAlbControllerByUrl`, - `CreateNsxtAlbController`, `Update`, `Delete` [GH-xxx] + `CreateNsxtAlbController`, `Update`, `Delete` [GH-398] * Added types `NsxtAlbCloud` and `types.NsxtAlbCloud` for handling NSX-T ALB Clouds with corresponding functions - `GetAllAlbClouds`, `GetAlbCloudByName`, `GetAlbCloudById`, `CreateAlbCloud`, `Delete` [GH-xxx] + `GetAllAlbClouds`, `GetAlbCloudByName`, `GetAlbCloudById`, `CreateAlbCloud`, `Delete` [GH-398] * Added type `NsxtAlbImportableCloud` and `types.NsxtAlbImportableCloud` for listing NSX-T ALB Importable Clouds with corresponding functions `GetAllAlbImportableClouds`, `GetAlbImportableCloudByName`, `GetAlbImportableCloudById` - [GH-xxx] + [GH-398] * Added types `NsxtAlbServiceEngineGroup` and `types.NsxtAlbServiceEngineGroup` for handling NSX-T ALB Service Engine Groups with corresponding functions `GetAllNsxtAlbServiceEngineGroups`, `GetAlbServiceEngineGroupByName`, - `GetAlbServiceEngineGroupById`, `CreateNsxtAlbServiceEngineGroup`, `Update`, `Delete` [GH-xxx] + `GetAlbServiceEngineGroupById`, `CreateNsxtAlbServiceEngineGroup`, `Update`, `Delete`, `Sync` [GH-398] * Added types `NsxtAlbImportableServiceEngineGroups` and `types.NsxtAlbImportableServiceEngineGroups` for listing NSX-T ALB Importable Service Engine Groups with corresponding functions `GetAllAlbImportableServiceEngineGroups`, - `GetAlbImportableServiceEngineGroupByName`, `GetAlbImportableServiceEngineGroupById` [GH-xxx] + `GetAlbImportableServiceEngineGroupByName`, `GetAlbImportableServiceEngineGroupById` [GH-398] diff --git a/go.mod b/go.mod index e036ea991..749933f69 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,6 @@ go 1.13 require ( github.com/araddon/dateparse v0.0.0-20190622164848-0fb0a474d195 - github.com/davecgh/go-spew v1.1.0 // indirect github.com/hashicorp/go-version v1.2.0 github.com/kr/pretty v0.2.1 github.com/peterhellberg/link v1.1.0 diff --git a/govcd/api_vcd_test.go b/govcd/api_vcd_test.go index 937c072b1..e2ec332b3 100644 --- a/govcd/api_vcd_test.go +++ b/govcd/api_vcd_test.go @@ -175,6 +175,7 @@ type TestConfig struct { NsxtAlbControllerUrl string `yaml:"nsxtAlbControllerUrl"` NsxtAlbControllerUser string `yaml:"nsxtAlbControllerUser"` NsxtAlbControllerPassword string `yaml:"nsxtAlbControllerPassword"` + NsxtAlbImportableCloud string `yaml:"nsxtAlbImportableCloud"` } `yaml:"nsxt"` } `yaml:"vcd"` Logging struct { @@ -1855,6 +1856,10 @@ func skipNoNsxtAlbConfiguration(vcd *TestVCD, check *C) { if vcd.config.VCD.Nsxt.NsxtAlbControllerPassword == "" { check.Skip(generalMessage + "No NSX-T ALB Controller Password specified in configuration") } + + if vcd.config.VCD.Nsxt.NsxtAlbImportableCloud == "" { + check.Skip(generalMessage + "No NSX-T ALB Controller Importable Cloud Name") + } } // skipOpenApiEndpointTest is a helper to skip tests for particular unsupported OpenAPI endpoints diff --git a/govcd/nsxt_alb_clouds.go b/govcd/nsxt_alb_clouds.go index a7720f3e2..0d5c4dbbf 100644 --- a/govcd/nsxt_alb_clouds.go +++ b/govcd/nsxt_alb_clouds.go @@ -84,8 +84,8 @@ func (vcdClient *VCDClient) GetAlbCloudByName(name string) (*NsxtAlbCloud, error // GetAlbCloudById returns NSX-T ALB Cloud by ID // -// Note. This function uses server side filtering instead of directly querying endpoint with specified ID. Such ID does -// not exist. +// Note. This function uses server side filtering instead of directly querying endpoint with specified ID because such +// endpoint does not exist func (vcdClient *VCDClient) GetAlbCloudById(id string) (*NsxtAlbCloud, error) { queryParameters := copyOrNewUrlValues(nil) @@ -97,7 +97,7 @@ func (vcdClient *VCDClient) GetAlbCloudById(id string) (*NsxtAlbCloud, error) { } if len(albCloud) == 0 { - return nil, fmt.Errorf("%s could not find NSX-T ALB Cloud by Name '%s'", ErrorEntityNotFound, id) + return nil, fmt.Errorf("%s could not find NSX-T ALB Cloud by ID '%s'", ErrorEntityNotFound, id) } return albCloud[0], nil diff --git a/govcd/nsxt_alb_clouds_test.go b/govcd/nsxt_alb_clouds_test.go index 4a15dd965..4e522aef3 100644 --- a/govcd/nsxt_alb_clouds_test.go +++ b/govcd/nsxt_alb_clouds_test.go @@ -21,22 +21,21 @@ func (vcd *TestVCD) Test_AlbClouds(check *C) { albController := spawnAlbController(vcd, check) check.Assert(albController, NotNil) - importableClouds, err := albController.GetAllAlbImportableClouds(nil) + importableCloud, err := albController.GetAlbImportableCloudByName(vcd.config.VCD.Nsxt.NsxtAlbImportableCloud) check.Assert(err, IsNil) - check.Assert(len(importableClouds) > 0, Equals, true) albCloudConfig := &types.NsxtAlbCloud{ Name: check.TestName(), Description: "alb-cloud-description", LoadBalancerCloudBacking: types.NsxtAlbCloudBacking{ - BackingId: importableClouds[0].NsxtAlbImportableCloud.ID, + BackingId: importableCloud.NsxtAlbImportableCloud.ID, BackingType: types.NsxtAlbCloudBackingTypeNsxtAlb, LoadBalancerControllerRef: types.OpenApiReference{ ID: albController.NsxtAlbController.ID, }, }, NetworkPoolRef: &types.OpenApiReference{ - ID: importableClouds[0].NsxtAlbImportableCloud.NetworkPoolRef.ID, + ID: importableCloud.NsxtAlbImportableCloud.NetworkPoolRef.ID, }, } @@ -45,7 +44,7 @@ func (vcd *TestVCD) Test_AlbClouds(check *C) { openApiEndpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointAlbCloud + createdAlbCloud.NsxtAlbCloud.ID AddToCleanupListOpenApi(createdAlbCloud.NsxtAlbCloud.Name, check.TestName(), openApiEndpoint) - // Get all clouds and ensure the needed on is found + // Get all clouds and ensure the needed one is found allClouds, err := vcd.client.GetAllAlbClouds(nil) check.Assert(err, IsNil) var foundCreatedCloud bool @@ -86,7 +85,11 @@ func (vcd *TestVCD) Test_AlbClouds(check *C) { check.Assert(err, IsNil) } +// spawnAlbControllerAndCloud is a helper function to spawn NSX-T ALB Controller and Cloud +// It automatically adds these artefacts to clean up list func spawnAlbControllerAndCloud(vcd *TestVCD, check *C) (*NsxtAlbController, *NsxtAlbCloud) { + skipNoNsxtAlbConfiguration(vcd, check) + albController := spawnAlbController(vcd, check) check.Assert(albController, NotNil) diff --git a/govcd/nsxt_alb_controllers.go b/govcd/nsxt_alb_controllers.go index 5c35c65ad..45f9ea847 100644 --- a/govcd/nsxt_alb_controllers.go +++ b/govcd/nsxt_alb_controllers.go @@ -58,7 +58,6 @@ func (vcdClient *VCDClient) GetAllAlbControllers(queryParameters url.Values) ([] // GetAlbControllerByName returns NSX-T ALB Controller by Name func (vcdClient *VCDClient) GetAlbControllerByName(name string) (*NsxtAlbController, error) { - queryParameters := copyOrNewUrlValues(nil) queryParameters.Add("filter", "name=="+name) @@ -119,7 +118,6 @@ func (vcdClient *VCDClient) GetAlbControllerById(id string) (*NsxtAlbController, // Note. Filtering is performed on client side. func (vcdClient *VCDClient) GetAlbControllerByUrl(url string) (*NsxtAlbController, error) { // Ideally this function could filter on VCD side, but API does not support filtering on URL - controllers, err := vcdClient.GetAllAlbControllers(nil) if err != nil { return nil, fmt.Errorf("error reading ALB Controller with Url '%s': %s", url, err) diff --git a/govcd/nsxt_alb_controllers_test.go b/govcd/nsxt_alb_controllers_test.go index fc6eaed07..9fa57fa8a 100644 --- a/govcd/nsxt_alb_controllers_test.go +++ b/govcd/nsxt_alb_controllers_test.go @@ -86,7 +86,10 @@ func (vcd *TestVCD) Test_NsxtAlbController(check *C) { check.Assert(ContainsNotFound(err), Equals, true) } +// spawnAlbController is a helper function to spawn NSX-T ALB Controller instance from defined config func spawnAlbController(vcd *TestVCD, check *C) *NsxtAlbController { + skipNoNsxtAlbConfiguration(vcd, check) + newControllerDef := &types.NsxtAlbController{ Name: "aviController1", Url: vcd.config.VCD.Nsxt.NsxtAlbControllerUrl, @@ -99,7 +102,6 @@ func spawnAlbController(vcd *TestVCD, check *C) *NsxtAlbController { check.Assert(err, IsNil) check.Assert(newController.NsxtAlbController.ID, Not(Equals), "") - // The ALB Controller was not present during this test run therefore it is going to be cleaned up in the end of tests openApiEndpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointAlbController + newController.NsxtAlbController.ID AddToCleanupListOpenApi(newController.NsxtAlbController.Name, check.TestName(), openApiEndpoint) diff --git a/govcd/nsxt_alb_importable_clouds.go b/govcd/nsxt_alb_importable_clouds.go index 7117150f3..817326199 100644 --- a/govcd/nsxt_alb_importable_clouds.go +++ b/govcd/nsxt_alb_importable_clouds.go @@ -20,11 +20,11 @@ type NsxtAlbImportableCloud struct { } // GetAllAlbImportableClouds returns importable NSX-T ALB Clouds. -// ID of parentAlbControllerUrn is mandatory +// ID (URN format) of parent ALB Controller is mandatory func (vcdClient *VCDClient) GetAllAlbImportableClouds(parentAlbControllerUrn string, queryParameters url.Values) ([]*NsxtAlbImportableCloud, error) { client := vcdClient.Client if parentAlbControllerUrn == "" { - return nil, fmt.Errorf("parentAlbControllerUrn is required") + return nil, fmt.Errorf("parent ALB Controller ID is required") } if !client.IsSysAdmin { return nil, errors.New("handling NSX-T ALB Importable Clouds require System user") @@ -67,7 +67,7 @@ func (vcdClient *VCDClient) GetAlbImportableCloudByName(parentAlbControllerUrn, return nil, fmt.Errorf("error finding NSX-T ALB Importable Cloud by Name '%s': %s", name, err) } - // Filtering by ID is not supported therefore it must be filtered on client side + // Filtering by Name is not supported therefore it must be filtered on client side var foundResult bool var foundAlbImportableCloud *NsxtAlbImportableCloud for i, value := range albImportableClouds { @@ -114,3 +114,8 @@ func (vcdClient *VCDClient) GetAlbImportableCloudById(parentAlbControllerUrn, id func (nsxtAlbController *NsxtAlbController) GetAllAlbImportableClouds(queryParameters url.Values) ([]*NsxtAlbImportableCloud, error) { return nsxtAlbController.vcdClient.GetAllAlbImportableClouds(nsxtAlbController.NsxtAlbController.ID, queryParameters) } + +// GetAlbImportableCloudByName is attached to NsxtAlbController type for a convenient parent/child relationship +func (nsxtAlbController *NsxtAlbController) GetAlbImportableCloudByName(name string) (*NsxtAlbImportableCloud, error) { + return nsxtAlbController.vcdClient.GetAlbImportableCloudByName(nsxtAlbController.NsxtAlbController.ID, name) +} diff --git a/govcd/nsxt_alb_importable_clouds_test.go b/govcd/nsxt_alb_importable_clouds_test.go index 43e339a4e..ee1afe7db 100644 --- a/govcd/nsxt_alb_importable_clouds_test.go +++ b/govcd/nsxt_alb_importable_clouds_test.go @@ -9,7 +9,6 @@ import ( . "gopkg.in/check.v1" ) -// Test_GetAllAlbImportableClouds tests if if there is at least one importable cloud available func (vcd *TestVCD) Test_GetAllAlbImportableClouds(check *C) { if vcd.skipAdminTests { check.Skip(fmt.Sprintf(TestRequiresSysAdminPrivileges, check.TestName())) @@ -18,20 +17,21 @@ func (vcd *TestVCD) Test_GetAllAlbImportableClouds(check *C) { albController := spawnAlbController(vcd, check) - controllers, err := vcd.client.GetAllAlbControllers(nil) - check.Assert(err, IsNil) - check.Assert(len(controllers) > 0, Equals, true) - // Test client function with explicit ALB Controller ID requirement - clientImportableClouds, err := vcd.client.GetAllAlbImportableClouds(controllers[0].NsxtAlbController.ID, nil) + clientImportableClouds, err := vcd.client.GetAllAlbImportableClouds(albController.NsxtAlbController.ID, nil) check.Assert(err, IsNil) check.Assert(len(clientImportableClouds) > 0, Equals, true) - // Test function attached directly to NsxtAlbController - controllerImportableClouds, err := controllers[0].GetAllAlbImportableClouds(nil) + // Test functions attached directly to NsxtAlbController + controllerImportableClouds, err := albController.GetAllAlbImportableClouds(nil) check.Assert(err, IsNil) check.Assert(len(controllerImportableClouds) > 0, Equals, true) + controllerImportableCloudByName, err := albController.GetAlbImportableCloudByName(vcd.config.VCD.Nsxt.NsxtAlbImportableCloud) + check.Assert(err, IsNil) + check.Assert(controllerImportableCloudByName, NotNil) + check.Assert(controllerImportableCloudByName.NsxtAlbImportableCloud.ID, Equals, controllerImportableClouds[0].NsxtAlbImportableCloud.ID) + // Cleanup err = albController.Delete() check.Assert(err, IsNil) diff --git a/govcd/nsxt_alb_importable_service_engine_groups.go b/govcd/nsxt_alb_importable_service_engine_groups.go index 08cb0d198..3e8ed6213 100644 --- a/govcd/nsxt_alb_importable_service_engine_groups.go +++ b/govcd/nsxt_alb_importable_service_engine_groups.go @@ -12,11 +12,13 @@ import ( "github.com/vmware/go-vcloud-director/v2/types/v56" ) +// NsxtAlbImportableServiceEngineGroups provides capability to list all Importable Service Engine Groups available in ALB Controller type NsxtAlbImportableServiceEngineGroups struct { NsxtAlbImportableServiceEngineGroups *types.NsxtAlbImportableServiceEngineGroups - client *Client + vcdClient *VCDClient } +// GetAllAlbImportableServiceEngineGroups lists all Importable Service Engine Groups available in ALB Controller func (vcdClient *VCDClient) GetAllAlbImportableServiceEngineGroups(parentAlbCloudUrn string, queryParameters url.Values) ([]*NsxtAlbImportableServiceEngineGroups, error) { client := vcdClient.Client if parentAlbCloudUrn == "" { @@ -49,7 +51,7 @@ func (vcdClient *VCDClient) GetAllAlbImportableServiceEngineGroups(parentAlbClou for sliceIndex := range typeResponses { wrappedResponses[sliceIndex] = &NsxtAlbImportableServiceEngineGroups{ NsxtAlbImportableServiceEngineGroups: typeResponses[sliceIndex], - client: &client, + vcdClient: vcdClient, } } @@ -105,3 +107,93 @@ func (vcdClient *VCDClient) GetAlbImportableServiceEngineGroupById(parentAlbClou return foundImportableSEGroups, nil } + +// GetAllAlbImportableServiceEngineGroups lists all Importable Service Engine Groups available in ALB Controller +func (nsxtAlbCloud *NsxtAlbCloud) GetAllAlbImportableServiceEngineGroups(parentAlbCloudUrn string, queryParameters url.Values) ([]*NsxtAlbImportableServiceEngineGroups, error) { + client := nsxtAlbCloud.vcdClient.Client + if parentAlbCloudUrn == "" { + return nil, fmt.Errorf("parentAlbCloudUrn is required") + } + if !client.IsSysAdmin { + return nil, errors.New("handling NSX-T ALB Importable Service Engine Groups requires System user") + } + + endpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointAlbImportableServiceEngineGroups + apiVersion, err := client.checkOpenApiEndpointCompatibility(endpoint) + if err != nil { + return nil, err + } + + urlRef, err := client.OpenApiBuildEndpoint(endpoint) + if err != nil { + return nil, err + } + + queryParams := copyOrNewUrlValues(queryParameters) + queryParams = queryParameterFilterAnd(fmt.Sprintf("_context==%s", parentAlbCloudUrn), queryParams) + typeResponses := []*types.NsxtAlbImportableServiceEngineGroups{{}} + err = client.OpenApiGetAllItems(apiVersion, urlRef, queryParams, &typeResponses, nil) + if err != nil { + return nil, err + } + + wrappedResponses := make([]*NsxtAlbImportableServiceEngineGroups, len(typeResponses)) + for sliceIndex := range typeResponses { + wrappedResponses[sliceIndex] = &NsxtAlbImportableServiceEngineGroups{ + NsxtAlbImportableServiceEngineGroups: typeResponses[sliceIndex], + vcdClient: nsxtAlbCloud.vcdClient, + } + } + + return wrappedResponses, nil +} + +// GetAlbImportableServiceEngineGroupByName returns importable NSX-T ALB Clouds. +func (nsxtAlbCloud *NsxtAlbCloud) GetAlbImportableServiceEngineGroupByName(parentAlbCloudUrn, name string) (*NsxtAlbImportableServiceEngineGroups, error) { + albClouds, err := nsxtAlbCloud.vcdClient.GetAllAlbImportableServiceEngineGroups(parentAlbCloudUrn, nil) + if err != nil { + return nil, fmt.Errorf("error finding NSX-T ALB Importable Service Engine Group by Name '%s': %s", name, err) + } + + // Filtering by ID is not supported therefore it must be filtered on client side + var foundResult bool + var foundAlbCloud *NsxtAlbImportableServiceEngineGroups + for i, value := range albClouds { + if albClouds[i].NsxtAlbImportableServiceEngineGroups.DisplayName == name { + foundResult = true + foundAlbCloud = value + break + } + } + + if !foundResult { + return nil, fmt.Errorf("%s: could not find NSX-T ALB Importable Service Engine Group by Name %s", ErrorEntityNotFound, name) + } + + return foundAlbCloud, nil +} + +// GetAlbImportableServiceEngineGroupById +// Note. ID filtering is performed on client side +func (nsxtAlbCloud *NsxtAlbCloud) GetAlbImportableServiceEngineGroupById(parentAlbCloudUrn, id string) (*NsxtAlbImportableServiceEngineGroups, error) { + albClouds, err := nsxtAlbCloud.vcdClient.GetAllAlbImportableServiceEngineGroups(parentAlbCloudUrn, nil) + if err != nil { + return nil, fmt.Errorf("error finding NSX-T ALB Importable Service Engine Group by ID '%s': %s", id, err) + } + + // Filtering by ID is not supported therefore it must be filtered on client side + var foundResult bool + var foundImportableSEGroups *NsxtAlbImportableServiceEngineGroups + for i, value := range albClouds { + if albClouds[i].NsxtAlbImportableServiceEngineGroups.ID == id { + foundResult = true + foundImportableSEGroups = value + } + } + + if !foundResult { + return nil, fmt.Errorf("%s: could not find NSX-T ALB Importable Service Engine Group by ID %s", ErrorEntityNotFound, id) + } + + return foundImportableSEGroups, nil +} diff --git a/govcd/nsxt_alb_importable_service_engine_groups_test.go b/govcd/nsxt_alb_importable_service_engine_groups_test.go index 6d6b3689a..33258013e 100644 --- a/govcd/nsxt_alb_importable_service_engine_groups_test.go +++ b/govcd/nsxt_alb_importable_service_engine_groups_test.go @@ -22,6 +22,25 @@ func (vcd *TestVCD) Test_GetAllAlbImportableServiceEngineGroups(check *C) { check.Assert(importableSeGroups[0].NsxtAlbImportableServiceEngineGroups.DisplayName != "", Equals, true) check.Assert(importableSeGroups[0].NsxtAlbImportableServiceEngineGroups.HaMode != "", Equals, true) + // Get By Name + impSeGrpByName, err := vcd.client.GetAlbImportableServiceEngineGroupByName(createdAlbCloud.NsxtAlbCloud.ID, importableSeGroups[0].NsxtAlbImportableServiceEngineGroups.DisplayName) + check.Assert(err, IsNil) + // Get By ID + impSeGrpById, err := vcd.client.GetAlbImportableServiceEngineGroupById(createdAlbCloud.NsxtAlbCloud.ID, importableSeGroups[0].NsxtAlbImportableServiceEngineGroups.ID) + check.Assert(err, IsNil) + + // Get By Name on parent Cloud + cldImpSeGrpByName, err := createdAlbCloud.GetAlbImportableServiceEngineGroupByName(createdAlbCloud.NsxtAlbCloud.ID, importableSeGroups[0].NsxtAlbImportableServiceEngineGroups.DisplayName) + check.Assert(err, IsNil) + // Get By ID on parent Cloud + cldImpSeGrpById, err := createdAlbCloud.GetAlbImportableServiceEngineGroupById(createdAlbCloud.NsxtAlbCloud.ID, importableSeGroups[0].NsxtAlbImportableServiceEngineGroups.ID) + check.Assert(err, IsNil) + + check.Assert(impSeGrpByName.NsxtAlbImportableServiceEngineGroups, DeepEquals, importableSeGroups[0].NsxtAlbImportableServiceEngineGroups) + check.Assert(impSeGrpByName.NsxtAlbImportableServiceEngineGroups, DeepEquals, impSeGrpById.NsxtAlbImportableServiceEngineGroups) + check.Assert(impSeGrpByName.NsxtAlbImportableServiceEngineGroups, DeepEquals, cldImpSeGrpByName.NsxtAlbImportableServiceEngineGroups) + check.Assert(impSeGrpByName.NsxtAlbImportableServiceEngineGroups, DeepEquals, cldImpSeGrpById.NsxtAlbImportableServiceEngineGroups) + // Cleanup err = createdAlbCloud.Delete() check.Assert(err, IsNil) diff --git a/govcd/nsxt_alb_service_engine_groups.go b/govcd/nsxt_alb_service_engine_groups.go index 63e69f6ce..ed8bc1428 100644 --- a/govcd/nsxt_alb_service_engine_groups.go +++ b/govcd/nsxt_alb_service_engine_groups.go @@ -22,8 +22,15 @@ type NsxtAlbServiceEngineGroup struct { vcdClient *VCDClient } -// GetAllNsxtAlbServiceEngineGroups retrieves NSX-T ALB Service Engines with possible filters -func (vcdClient *VCDClient) GetAllNsxtAlbServiceEngineGroups(context string, queryParameters url.Values) ([]*NsxtAlbServiceEngineGroup, error) { +// GetAllAlbServiceEngineGroups retrieves NSX-T ALB Service Engines with possible filters +// +// Context is not mandatory for this resource. Supported contexts are: +// * Gateway ID (_context==gatewayId) - returns all Load Balancer Service Engine Groups that are accessible to the +// gateway. +// * Assignable Gateway ID (_context=gatewayId;_context==assignable) returns all Load Balancer Service Engine Groups +// that are assignable to the gateway. This filters out any Load Balancer Service Engine groups that are already +// assigned to the gateway or assigned to another gateway if the reservation type is 'DEDICATED’. +func (vcdClient *VCDClient) GetAllAlbServiceEngineGroups(context string, queryParameters url.Values) ([]*NsxtAlbServiceEngineGroup, error) { client := vcdClient.Client if !client.IsSysAdmin { @@ -65,52 +72,60 @@ func (vcdClient *VCDClient) GetAllNsxtAlbServiceEngineGroups(context string, que // GetAlbServiceEngineGroupByName returns NSX-T ALB Service Engine by Name func (vcdClient *VCDClient) GetAlbServiceEngineGroupByName(context, name string) (*NsxtAlbServiceEngineGroup, error) { - albClouds, err := vcdClient.GetAllNsxtAlbServiceEngineGroups(context, nil) + queryParams := copyOrNewUrlValues(nil) + if context != "" { + queryParams = queryParameterFilterAnd(fmt.Sprintf("_context==%s", context), queryParams) + } + queryParams.Add("filter", fmt.Sprintf("name==%s", name)) + + albSeGroups, err := vcdClient.GetAllAlbServiceEngineGroups("", queryParams) if err != nil { - return nil, fmt.Errorf("error finding NSX-T ALB Service Engine Group by Name '%s': %s", name, err) + return nil, fmt.Errorf("error retrieving NSX-T ALB Service Engine Group By Name '%s': %s", name, err) } - // Filtering by ID is not supported therefore it must be filtered on client side - var foundResult bool - var foundAlbCloud *NsxtAlbServiceEngineGroup - for i, value := range albClouds { - if albClouds[i].NsxtAlbServiceEngineGroup.Name == name { - foundResult = true - foundAlbCloud = value - break - } + if len(albSeGroups) == 0 { + return nil, fmt.Errorf("%s", ErrorEntityNotFound) } - if !foundResult { - return nil, fmt.Errorf("%s: could not find NSX-T ALB Service Engine Group by Name %s", ErrorEntityNotFound, name) + if len(albSeGroups) > 1 { + return nil, fmt.Errorf("more than 1 NSX-T ALB Service Engine Group with Name '%s' found", name) } - return foundAlbCloud, nil + return albSeGroups[0], nil } -// GetAlbServiceEngineGroupById returns importable NSX-T ALB Clouds. -// Note. ID filtering is performed on client side -func (vcdClient *VCDClient) GetAlbServiceEngineGroupById(context, id string) (*NsxtAlbServiceEngineGroup, error) { - albClouds, err := vcdClient.GetAllNsxtAlbServiceEngineGroups(context, nil) +// GetAlbServiceEngineGroupById returns importable NSX-T ALB Cloud by ID +func (vcdClient *VCDClient) GetAlbServiceEngineGroupById(id string) (*NsxtAlbServiceEngineGroup, error) { + client := vcdClient.Client + + if !client.IsSysAdmin { + return nil, errors.New("handling NSX-T ALB Service Engine Groups require System user") + } + + endpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointAlbServiceEngineGroups + apiVersion, err := client.checkOpenApiEndpointCompatibility(endpoint) if err != nil { - return nil, fmt.Errorf("error finding Alb Cloud by ID '%s': %s", id, err) + return nil, err } - // Filtering by ID is not supported therefore it must be filtered on client side - var foundResult bool - var foundAlbCloud *NsxtAlbServiceEngineGroup - for i, value := range albClouds { - if albClouds[i].NsxtAlbServiceEngineGroup.ID == id { - foundResult = true - foundAlbCloud = value - } + urlRef, err := client.OpenApiBuildEndpoint(endpoint, id) + if err != nil { + return nil, err } - if !foundResult { - return nil, fmt.Errorf("%s: could not find NSX-T ALB Service Engine Group by ID %s", ErrorEntityNotFound, id) + typeResponse := &types.NsxtAlbServiceEngineGroup{} + + err = client.OpenApiGetItem(apiVersion, urlRef, nil, &typeResponse, nil) + if err != nil { + return nil, err + } + + wrappedResponse := &NsxtAlbServiceEngineGroup{ + NsxtAlbServiceEngineGroup: typeResponse, + vcdClient: vcdClient, } - return foundAlbCloud, nil + return wrappedResponse, nil } func (vcdClient *VCDClient) CreateNsxtAlbServiceEngineGroup(albServiceEngineGroup *types.NsxtAlbServiceEngineGroup) (*NsxtAlbServiceEngineGroup, error) { @@ -143,8 +158,7 @@ func (vcdClient *VCDClient) CreateNsxtAlbServiceEngineGroup(albServiceEngineGrou return returnObject, nil } -// -//// Update updates existing ALB Controller with new supplied albControllerConfig configuration +// Update updates existing ALB Controller with new supplied albControllerConfig configuration func (nsxtAlbServiceEngineGroup *NsxtAlbServiceEngineGroup) Update(albSEGroupConfig *types.NsxtAlbServiceEngineGroup) (*NsxtAlbServiceEngineGroup, error) { client := nsxtAlbServiceEngineGroup.vcdClient.Client endpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointAlbServiceEngineGroups @@ -175,6 +189,7 @@ func (nsxtAlbServiceEngineGroup *NsxtAlbServiceEngineGroup) Update(albSEGroupCon return responseAlbController, nil } +// Delete deletes NSX-T ALB Service Engine Group configuration func (nsxtAlbServiceEngineGroup *NsxtAlbServiceEngineGroup) Delete() error { client := nsxtAlbServiceEngineGroup.vcdClient.Client endpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointAlbServiceEngineGroups @@ -199,3 +214,36 @@ func (nsxtAlbServiceEngineGroup *NsxtAlbServiceEngineGroup) Delete() error { return nil } + +// Sync syncs a specified Load Balancer Service Engine Group. Requests the HA mode and the maximum number of supported +// Virtual Services for this Service Engine Group from the Load Balancer, and updates vCD's local record of these +// properties. +func (nsxtAlbServiceEngineGroup *NsxtAlbServiceEngineGroup) Sync() error { + client := nsxtAlbServiceEngineGroup.vcdClient.Client + endpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointAlbServiceEngineGroups + minimumApiVersion, err := client.checkOpenApiEndpointCompatibility(endpoint) + if err != nil { + return err + } + + if nsxtAlbServiceEngineGroup.NsxtAlbServiceEngineGroup.ID == "" { + return fmt.Errorf("cannot sync NSX-T ALB Service Engine Group without ID") + } + + urlRef, err := client.OpenApiBuildEndpoint(endpoint, nsxtAlbServiceEngineGroup.NsxtAlbServiceEngineGroup.ID, "/sync") + if err != nil { + return err + } + + task, err := client.OpenApiPostItemAsync(minimumApiVersion, urlRef, nil, nil) + if err != nil { + return fmt.Errorf("error syncing NSX-T ALB Service Engine Group: %s", err) + } + + err = task.WaitTaskCompletion() + if err != nil { + return fmt.Errorf("sync task for NSX-T ALB Service Engine Group failed: %s", err) + } + + return nil +} diff --git a/govcd/nsxt_alb_service_engine_groups_test.go b/govcd/nsxt_alb_service_engine_groups_test.go index f707faecd..d4eca30e8 100644 --- a/govcd/nsxt_alb_service_engine_groups_test.go +++ b/govcd/nsxt_alb_service_engine_groups_test.go @@ -44,13 +44,19 @@ func (vcd *TestVCD) Test_GetAllAlbServiceEngineGroups(check *C) { openApiEndpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointAlbServiceEngineGroups + createdSeGroup.NsxtAlbServiceEngineGroup.ID AddToCleanupListOpenApi(createdSeGroup.NsxtAlbServiceEngineGroup.Name, check.TestName(), openApiEndpoint) + // Sync + err = createdSeGroup.Sync() + check.Assert(err, IsNil) + // Find by Name seGroupByName, err := vcd.client.GetAlbServiceEngineGroupByName("", createdSeGroup.NsxtAlbServiceEngineGroup.Name) check.Assert(err, IsNil) + check.Assert(seGroupByName, NotNil) // Find by ID - seGroupById, err := vcd.client.GetAlbServiceEngineGroupById("", createdSeGroup.NsxtAlbServiceEngineGroup.ID) + seGroupById, err := vcd.client.GetAlbServiceEngineGroupById(createdSeGroup.NsxtAlbServiceEngineGroup.ID) check.Assert(err, IsNil) + check.Assert(seGroupById, NotNil) check.Assert(seGroupByName.NsxtAlbServiceEngineGroup.ID, Equals, createdSeGroup.NsxtAlbServiceEngineGroup.ID) check.Assert(seGroupById.NsxtAlbServiceEngineGroup.ID, Equals, createdSeGroup.NsxtAlbServiceEngineGroup.ID) diff --git a/govcd/openapi.go b/govcd/openapi.go index fd3157575..7224cb2ba 100644 --- a/govcd/openapi.go +++ b/govcd/openapi.go @@ -494,7 +494,7 @@ func (client *Client) OpenApiDeleteItem(apiVersion string, urlRef *url.URL, para // OpenApiPostItemAsync, OpenApiPostItem, OpenApiPutItemSync, OpenApiPutItemAsync, OpenApiPutItem func (client *Client) openApiPerformPostPut(httpMethod string, apiVersion string, urlRef *url.URL, params url.Values, payload interface{}, additionalHeader map[string]string) (*http.Response, error) { // Marshal payload if we have one - var body *bytes.Buffer + body := new(bytes.Buffer) if payload != nil { marshaledJson, err := json.MarshalIndent(payload, "", " ") if err != nil { diff --git a/types/v56/nsxt_types.go b/types/v56/nsxt_types.go index 009ac41c3..218d0f4a2 100644 --- a/types/v56/nsxt_types.go +++ b/types/v56/nsxt_types.go @@ -761,18 +761,42 @@ type NsxtAlbCloudBacking struct { LoadBalancerControllerRef OpenApiReference `json:"loadBalancerControllerRef"` } +// NsxtAlbServiceEngineGroup allows users to provide virtual service management capabilities to your tenants, import +// service engine groups to your VMware Cloud Director deployment. +// A service engine group is an isolation domain that also defines shared service engine properties, such as size, +// network access, and failover. Resources in a service engine group can be used for different virtual services, +// depending on your tenant needs. These resources cannot be shared between different service engine groups. type NsxtAlbServiceEngineGroup struct { - Status string `json:"status,omitempty"` - ID string `json:"id,omitempty"` - Name string `json:"name"` - Description string `json:"description"` - ServiceEngineGroupBacking ServiceEngineGroupBacking `json:"serviceEngineGroupBacking"` - HaMode string `json:"haMode,omitempty"` - ReservationType string `json:"reservationType"` - MaxVirtualServices int `json:"maxVirtualServices,omitempty"` - NumDeployedVirtualServices int `json:"numDeployedVirtualServices,omitempty"` - ReservedVirtualServices int `json:"reservedVirtualServices,omitempty"` - OverAllocated bool `json:"overAllocated,omitempty"` + // ID of the Service Engine Group + ID string `json:"id,omitempty"` + // Name of the Service Engine Group + Name string `json:"name"` + // Description of the Service Engine Group + Description string `json:"description"` + // ServiceEngineGroupBacking holds backing details that uniquely identifies a Load Balancer Service Engine Group + // configured within a load balancer cloud. + ServiceEngineGroupBacking ServiceEngineGroupBacking `json:"serviceEngineGroupBacking"` + // HaMode defines High Availability Mode for Service Engine Group + // * ELASTIC_N_PLUS_M_BUFFER - Service Engines will scale out to N active nodes with M nodes as buffer. + // * ELASTIC_ACTIVE_ACTIVE - Active-Active with scale out. + // * LEGACY_ACTIVE_STANDBY - Traditional single Active-Standby configuration + HaMode string `json:"haMode,omitempty"` + // ReservationType can be `DEDICATED` or `SHARED` + // * DEDICATED - Dedicated to a single Edge Gateway and can only be assigned to a single Edge Gateway + // * SHARED - Shared between multiple Edge Gateways. Can be assigned to multiple Edge Gateways + ReservationType string `json:"reservationType"` + // MaxVirtualServices holds maximum number of virtual services supported on the Load Balancer Service Engine Group + MaxVirtualServices *int `json:"maxVirtualServices,omitempty"` + // NumDeployedVirtualServices shows number of virtual services currently deployed on the Load Balancer Service Engine + // Group + NumDeployedVirtualServices *int `json:"numDeployedVirtualServices,omitempty"` + // ReservedVirtualServices holds number of virtual services already reserved on the Load Balancer Service Engine Group. + // This value is the sum of the guaranteed virtual services given to Edge Gateways assigned to the Load Balancer + // Service Engine Group. + ReservedVirtualServices *int `json:"reservedVirtualServices,omitempty"` + // OverAllocated indicates whether the maximum number of virtual services supported on the Load Balancer Service + // Engine Group has been surpassed by the current number of reserved virtual services. + OverAllocated *bool `json:"overAllocated,omitempty"` } type ServiceEngineGroupBacking struct { @@ -781,6 +805,7 @@ type ServiceEngineGroupBacking struct { LoadBalancerCloudRef *OpenApiReference `json:"loadBalancerCloudRef"` } +// NsxtAlbImportableServiceEngineGroups is used to get Importable Service Engine Groups type NsxtAlbImportableServiceEngineGroups struct { // ID (e.g. 'serviceenginegroup-b633f16f-2733-4bf5-b552-3a6c4949caa4') ID string `json:"id"` From 50dc2cf56f87721a97d800f6aa998b80120a6b3f Mon Sep 17 00:00:00 2001 From: Dainius Serplis Date: Tue, 7 Sep 2021 22:32:09 +0300 Subject: [PATCH 3/6] Fine tune Signed-off-by: Dainius Serplis --- govcd/nsxt_alb_clouds_test.go | 9 ++++----- govcd/nsxt_alb_controllers.go | 2 +- govcd/nsxt_alb_service_engine_groups.go | 18 ++++++++++++------ 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/govcd/nsxt_alb_clouds_test.go b/govcd/nsxt_alb_clouds_test.go index 4e522aef3..884e41d1b 100644 --- a/govcd/nsxt_alb_clouds_test.go +++ b/govcd/nsxt_alb_clouds_test.go @@ -93,22 +93,21 @@ func spawnAlbControllerAndCloud(vcd *TestVCD, check *C) (*NsxtAlbController, *Ns albController := spawnAlbController(vcd, check) check.Assert(albController, NotNil) - importableClouds, err := albController.GetAllAlbImportableClouds(nil) + importableCloud, err := albController.GetAlbImportableCloudByName(vcd.config.VCD.Nsxt.NsxtAlbImportableCloud) check.Assert(err, IsNil) - check.Assert(len(importableClouds) > 0, Equals, true) albCloudConfig := &types.NsxtAlbCloud{ Name: check.TestName(), Description: "alb-cloud-description", LoadBalancerCloudBacking: types.NsxtAlbCloudBacking{ - BackingId: importableClouds[0].NsxtAlbImportableCloud.ID, - BackingType: types.NsxtAlbCloudBackingTypeNsxtAlb, + BackingId: importableCloud.NsxtAlbImportableCloud.ID, + //BackingType: types.NsxtAlbCloudBackingTypeNsxtAlb, LoadBalancerControllerRef: types.OpenApiReference{ ID: albController.NsxtAlbController.ID, }, }, NetworkPoolRef: &types.OpenApiReference{ - ID: importableClouds[0].NsxtAlbImportableCloud.NetworkPoolRef.ID, + ID: importableCloud.NsxtAlbImportableCloud.NetworkPoolRef.ID, }, } diff --git a/govcd/nsxt_alb_controllers.go b/govcd/nsxt_alb_controllers.go index 45f9ea847..a0e8d5190 100644 --- a/govcd/nsxt_alb_controllers.go +++ b/govcd/nsxt_alb_controllers.go @@ -107,7 +107,7 @@ func (vcdClient *VCDClient) GetAlbControllerById(id string) (*NsxtAlbController, wrappedResponse := &NsxtAlbController{ NsxtAlbController: typeResponse, - vcdClient: nil, + vcdClient: vcdClient, } return wrappedResponse, nil diff --git a/govcd/nsxt_alb_service_engine_groups.go b/govcd/nsxt_alb_service_engine_groups.go index ed8bc1428..9cb03a0ae 100644 --- a/govcd/nsxt_alb_service_engine_groups.go +++ b/govcd/nsxt_alb_service_engine_groups.go @@ -71,10 +71,16 @@ func (vcdClient *VCDClient) GetAllAlbServiceEngineGroups(context string, queryPa } // GetAlbServiceEngineGroupByName returns NSX-T ALB Service Engine by Name -func (vcdClient *VCDClient) GetAlbServiceEngineGroupByName(context, name string) (*NsxtAlbServiceEngineGroup, error) { +// Context is not mandatory for this resource. Supported contexts are: +// * Gateway ID (_context==gatewayId) - returns all Load Balancer Service Engine Groups that are accessible to the +// gateway. +// * Assignable Gateway ID (_context=gatewayId;_context==assignable) returns all Load Balancer Service Engine Groups +// that are assignable to the gateway. This filters out any Load Balancer Service Engine groups that are already +// assigned to the gateway or assigned to another gateway if the reservation type is 'DEDICATED’. +func (vcdClient *VCDClient) GetAlbServiceEngineGroupByName(optionalContext, name string) (*NsxtAlbServiceEngineGroup, error) { queryParams := copyOrNewUrlValues(nil) - if context != "" { - queryParams = queryParameterFilterAnd(fmt.Sprintf("_context==%s", context), queryParams) + if optionalContext != "" { + queryParams = queryParameterFilterAnd(fmt.Sprintf("_context==%s", optionalContext), queryParams) } queryParams.Add("filter", fmt.Sprintf("name==%s", name)) @@ -215,9 +221,9 @@ func (nsxtAlbServiceEngineGroup *NsxtAlbServiceEngineGroup) Delete() error { return nil } -// Sync syncs a specified Load Balancer Service Engine Group. Requests the HA mode and the maximum number of supported -// Virtual Services for this Service Engine Group from the Load Balancer, and updates vCD's local record of these -// properties. +// Sync syncs a specified Load Balancer Service Engine Group. It requests the HA mode and the maximum number of +// supported Virtual Services for this Service Engine Group from the Load Balancer, and updates vCD's local record of +// these properties. func (nsxtAlbServiceEngineGroup *NsxtAlbServiceEngineGroup) Sync() error { client := nsxtAlbServiceEngineGroup.vcdClient.Client endpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointAlbServiceEngineGroups From 5cdd75f10d46ca1d966fdef5c7ca3735219a5c6c Mon Sep 17 00:00:00 2001 From: Dainius Serplis Date: Wed, 8 Sep 2021 14:50:35 +0300 Subject: [PATCH 4/6] Address comments Signed-off-by: Dainius Serplis --- govcd/nsxt_alb_clouds.go | 2 +- govcd/nsxt_alb_importable_clouds.go | 6 +++--- govcd/nsxt_alb_importable_service_engine_groups.go | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/govcd/nsxt_alb_clouds.go b/govcd/nsxt_alb_clouds.go index 0d5c4dbbf..c4b7af7be 100644 --- a/govcd/nsxt_alb_clouds.go +++ b/govcd/nsxt_alb_clouds.go @@ -134,7 +134,7 @@ func (vcdClient *VCDClient) CreateAlbCloud(albCloudConfig *types.NsxtAlbCloud) ( return returnObject, nil } -// Update is not supported up to at least VCD 10.3 therefore this function remains commented +// Update is not supported in VCD 10.3 and older therefore this function remains commented // // Update updates existing NSX-T ALB Cloud with new supplied albCloudConfig configuration //func (nsxtAlbCloud *NsxtAlbCloud) Update(albCloudConfig *types.NsxtAlbCloud) (*NsxtAlbCloud, error) { diff --git a/govcd/nsxt_alb_importable_clouds.go b/govcd/nsxt_alb_importable_clouds.go index 817326199..4c3130181 100644 --- a/govcd/nsxt_alb_importable_clouds.go +++ b/govcd/nsxt_alb_importable_clouds.go @@ -20,7 +20,7 @@ type NsxtAlbImportableCloud struct { } // GetAllAlbImportableClouds returns importable NSX-T ALB Clouds. -// ID (URN format) of parent ALB Controller is mandatory +// parentAlbControllerUrn (ID in URN format of a parent ALB Controller) is mandatory func (vcdClient *VCDClient) GetAllAlbImportableClouds(parentAlbControllerUrn string, queryParameters url.Values) ([]*NsxtAlbImportableCloud, error) { client := vcdClient.Client if parentAlbControllerUrn == "" { @@ -67,7 +67,7 @@ func (vcdClient *VCDClient) GetAlbImportableCloudByName(parentAlbControllerUrn, return nil, fmt.Errorf("error finding NSX-T ALB Importable Cloud by Name '%s': %s", name, err) } - // Filtering by Name is not supported therefore it must be filtered on client side + // Filtering by Name is not supported by API therefore it must be filtered on client side var foundResult bool var foundAlbImportableCloud *NsxtAlbImportableCloud for i, value := range albImportableClouds { @@ -93,7 +93,7 @@ func (vcdClient *VCDClient) GetAlbImportableCloudById(parentAlbControllerUrn, id return nil, fmt.Errorf("error finding NSX-T ALB Importable Cloud by ID '%s': %s", id, err) } - // Filtering by ID is not supported therefore it must be filtered on client side + // Filtering by ID is not supported by API therefore it must be filtered on client side var foundResult bool var foundAlbImportableCloud *NsxtAlbImportableCloud for i, value := range albImportableClouds { diff --git a/govcd/nsxt_alb_importable_service_engine_groups.go b/govcd/nsxt_alb_importable_service_engine_groups.go index 3e8ed6213..9ac6df949 100644 --- a/govcd/nsxt_alb_importable_service_engine_groups.go +++ b/govcd/nsxt_alb_importable_service_engine_groups.go @@ -65,7 +65,7 @@ func (vcdClient *VCDClient) GetAlbImportableServiceEngineGroupByName(parentAlbCl return nil, fmt.Errorf("error finding NSX-T ALB Importable Service Engine Group by Name '%s': %s", name, err) } - // Filtering by ID is not supported therefore it must be filtered on client side + // Filtering by Name is not supported by API therefore it must be filtered on client side var foundResult bool var foundAlbCloud *NsxtAlbImportableServiceEngineGroups for i, value := range albClouds { @@ -91,7 +91,7 @@ func (vcdClient *VCDClient) GetAlbImportableServiceEngineGroupById(parentAlbClou return nil, fmt.Errorf("error finding NSX-T ALB Importable Service Engine Group by ID '%s': %s", id, err) } - // Filtering by ID is not supported therefore it must be filtered on client side + // Filtering by ID is not supported by API therefore it must be filtered on client side var foundResult bool var foundImportableSEGroups *NsxtAlbImportableServiceEngineGroups for i, value := range albClouds { @@ -155,7 +155,7 @@ func (nsxtAlbCloud *NsxtAlbCloud) GetAlbImportableServiceEngineGroupByName(paren return nil, fmt.Errorf("error finding NSX-T ALB Importable Service Engine Group by Name '%s': %s", name, err) } - // Filtering by ID is not supported therefore it must be filtered on client side + // Filtering by ID is not supported by API therefore it must be filtered on client side var foundResult bool var foundAlbCloud *NsxtAlbImportableServiceEngineGroups for i, value := range albClouds { @@ -181,7 +181,7 @@ func (nsxtAlbCloud *NsxtAlbCloud) GetAlbImportableServiceEngineGroupById(parentA return nil, fmt.Errorf("error finding NSX-T ALB Importable Service Engine Group by ID '%s': %s", id, err) } - // Filtering by ID is not supported therefore it must be filtered on client side + // Filtering by ID is not supported by API therefore it must be filtered on client side var foundResult bool var foundImportableSEGroups *NsxtAlbImportableServiceEngineGroups for i, value := range albClouds { From f5b419a1e48bd3fa886e38a68efd7aefbca1ac13 Mon Sep 17 00:00:00 2001 From: Dainius Serplis Date: Wed, 8 Sep 2021 15:05:32 +0300 Subject: [PATCH 5/6] Change name in tests for ALB Controller Signed-off-by: Dainius Serplis --- govcd/nsxt_alb_controllers_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/govcd/nsxt_alb_controllers_test.go b/govcd/nsxt_alb_controllers_test.go index 9fa57fa8a..0dedba5b2 100644 --- a/govcd/nsxt_alb_controllers_test.go +++ b/govcd/nsxt_alb_controllers_test.go @@ -91,7 +91,7 @@ func spawnAlbController(vcd *TestVCD, check *C) *NsxtAlbController { skipNoNsxtAlbConfiguration(vcd, check) newControllerDef := &types.NsxtAlbController{ - Name: "aviController1", + Name: check.TestName(), Url: vcd.config.VCD.Nsxt.NsxtAlbControllerUrl, Username: vcd.config.VCD.Nsxt.NsxtAlbControllerUser, Password: vcd.config.VCD.Nsxt.NsxtAlbControllerPassword, From 0118c390f7446aa2745fc0142ab850b2cd7a62f3 Mon Sep 17 00:00:00 2001 From: Dainius Serplis Date: Thu, 9 Sep 2021 08:43:53 +0300 Subject: [PATCH 6/6] Docs fixes and 'nsxt' tag Signed-off-by: Dainius Serplis --- govcd/nsxt_alb_clouds.go | 10 ++------- govcd/nsxt_alb_clouds_test.go | 4 ++-- govcd/nsxt_alb_controllers.go | 1 + govcd/nsxt_alb_controllers_test.go | 4 ++-- govcd/nsxt_alb_importable_clouds.go | 2 +- govcd/nsxt_alb_importable_clouds_test.go | 4 ++-- ...xt_alb_importable_service_engine_groups.go | 5 ++++- ...b_importable_service_engine_groups_test.go | 4 ++-- govcd/nsxt_alb_service_engine_groups.go | 5 +++-- govcd/nsxt_alb_service_engine_groups_test.go | 4 ++-- types/v56/nsxt_types.go | 21 +++++++++---------- 11 files changed, 31 insertions(+), 33 deletions(-) diff --git a/govcd/nsxt_alb_clouds.go b/govcd/nsxt_alb_clouds.go index c4b7af7be..bd6e8c43e 100644 --- a/govcd/nsxt_alb_clouds.go +++ b/govcd/nsxt_alb_clouds.go @@ -12,14 +12,8 @@ import ( "github.com/vmware/go-vcloud-director/v2/types/v56" ) -// NsxtAlbCloud allows users to use the virtual infrastructure provided by NSX Advanced Load Balancer, register your -// NSX-T Cloud instances with VMware Cloud Director. An NSX-T Cloud is a service provider-level construct that consists -// of an NSX-T Manager and an NSX-T Data Center transport zone. NSX-T Manager provides a system view and is the -// management component of NSX-T Data Center. An NSX-T Data Center transport zone dictates which hosts and virtual -// machines can participate in the use of a particular network. If there are multiple transport zones managed by the -// same NSX-T Manager, then a separate NSX-T Cloud encapsulates each pair of NSX-T Manager and NSX-T Data Center -// transport zone instances. An NSX-T Cloud has a one-to-one relationship with a network pool backed by an NSX-T Data -// Center transport zone. +// NsxtAlbCloud helps to use the virtual infrastructure provided by NSX Advanced Load Balancer, register NSX-T Cloud +// instances with VMware Cloud Director by consuming NsxtAlbImportableCloud. type NsxtAlbCloud struct { NsxtAlbCloud *types.NsxtAlbCloud vcdClient *VCDClient diff --git a/govcd/nsxt_alb_clouds_test.go b/govcd/nsxt_alb_clouds_test.go index 884e41d1b..b18795f87 100644 --- a/govcd/nsxt_alb_clouds_test.go +++ b/govcd/nsxt_alb_clouds_test.go @@ -1,5 +1,5 @@ -//go:build alb || functional || ALL -// +build alb functional ALL +//go:build nsxt || alb || functional || ALL +// +build nsxt alb functional ALL package govcd diff --git a/govcd/nsxt_alb_controllers.go b/govcd/nsxt_alb_controllers.go index a0e8d5190..1cd144c98 100644 --- a/govcd/nsxt_alb_controllers.go +++ b/govcd/nsxt_alb_controllers.go @@ -15,6 +15,7 @@ import ( // NsxtAlbController helps to integrate VMware Cloud Director with NSX-T Advanced Load Balancer deployment. // Controller instances are registered with VMware Cloud Director instance. Controller instances serve as a central // control plane for the load-balancing services provided by NSX-T Advanced Load Balancer. +// To configure an NSX-T ALB one needs to supply AVI Controller endpoint, credentials and license to be used. type NsxtAlbController struct { NsxtAlbController *types.NsxtAlbController vcdClient *VCDClient diff --git a/govcd/nsxt_alb_controllers_test.go b/govcd/nsxt_alb_controllers_test.go index 0dedba5b2..9e59ba154 100644 --- a/govcd/nsxt_alb_controllers_test.go +++ b/govcd/nsxt_alb_controllers_test.go @@ -1,5 +1,5 @@ -//go:build alb || functional || ALL -// +build alb functional ALL +//go:build nsxt || alb || functional || ALL +// +build nsxt alb functional ALL package govcd diff --git a/govcd/nsxt_alb_importable_clouds.go b/govcd/nsxt_alb_importable_clouds.go index 4c3130181..d239526d6 100644 --- a/govcd/nsxt_alb_importable_clouds.go +++ b/govcd/nsxt_alb_importable_clouds.go @@ -13,7 +13,7 @@ import ( ) // NsxtAlbImportableCloud allows user to list importable NSX-T ALB Clouds. Each importable cloud can only be imported -// once. It has a flag AlreadyImported which hints if it is already consumed or not. +// once by using NsxtAlbCloud construct. It has a flag AlreadyImported which hints if it is already consumed or not. type NsxtAlbImportableCloud struct { NsxtAlbImportableCloud *types.NsxtAlbImportableCloud vcdClient *VCDClient diff --git a/govcd/nsxt_alb_importable_clouds_test.go b/govcd/nsxt_alb_importable_clouds_test.go index ee1afe7db..14d402748 100644 --- a/govcd/nsxt_alb_importable_clouds_test.go +++ b/govcd/nsxt_alb_importable_clouds_test.go @@ -1,5 +1,5 @@ -//go:build alb || functional || ALL -// +build alb functional ALL +//go:build nsxt || alb || functional || ALL +// +build nsxt alb functional ALL package govcd diff --git a/govcd/nsxt_alb_importable_service_engine_groups.go b/govcd/nsxt_alb_importable_service_engine_groups.go index 9ac6df949..75e79f7c5 100644 --- a/govcd/nsxt_alb_importable_service_engine_groups.go +++ b/govcd/nsxt_alb_importable_service_engine_groups.go @@ -12,7 +12,10 @@ import ( "github.com/vmware/go-vcloud-director/v2/types/v56" ) -// NsxtAlbImportableServiceEngineGroups provides capability to list all Importable Service Engine Groups available in ALB Controller +// NsxtAlbImportableServiceEngineGroups provides capability to list all Importable Service Engine Groups available in +// ALB Controller so that they can be consumed by NsxtAlbServiceEngineGroup +// +// Note. The API does not return Importable Service Engine Group once it is consumed. type NsxtAlbImportableServiceEngineGroups struct { NsxtAlbImportableServiceEngineGroups *types.NsxtAlbImportableServiceEngineGroups vcdClient *VCDClient diff --git a/govcd/nsxt_alb_importable_service_engine_groups_test.go b/govcd/nsxt_alb_importable_service_engine_groups_test.go index 33258013e..bc24e283b 100644 --- a/govcd/nsxt_alb_importable_service_engine_groups_test.go +++ b/govcd/nsxt_alb_importable_service_engine_groups_test.go @@ -1,5 +1,5 @@ -//go:build alb || functional || ALL -// +build alb functional ALL +//go:build nsxt || alb || functional || ALL +// +build nsxt alb functional ALL package govcd diff --git a/govcd/nsxt_alb_service_engine_groups.go b/govcd/nsxt_alb_service_engine_groups.go index 9cb03a0ae..b0fe9b70b 100644 --- a/govcd/nsxt_alb_service_engine_groups.go +++ b/govcd/nsxt_alb_service_engine_groups.go @@ -12,8 +12,9 @@ import ( "github.com/vmware/go-vcloud-director/v2/types/v56" ) -// NsxtAlbServiceEngineGroup allows users to provide virtual service management capabilities to your tenants, import -// service engine groups to your VMware Cloud Director deployment. +// NsxtAlbServiceEngineGroup provides virtual service management capabilities for tenants. This entity can be created +// by referencing a backing importable service engine group - NsxtAlbImportableServiceEngineGroups. +// // A service engine group is an isolation domain that also defines shared service engine properties, such as size, // network access, and failover. Resources in a service engine group can be used for different virtual services, // depending on your tenant needs. These resources cannot be shared between different service engine groups. diff --git a/govcd/nsxt_alb_service_engine_groups_test.go b/govcd/nsxt_alb_service_engine_groups_test.go index d4eca30e8..cb467102d 100644 --- a/govcd/nsxt_alb_service_engine_groups_test.go +++ b/govcd/nsxt_alb_service_engine_groups_test.go @@ -1,5 +1,5 @@ -//go:build alb || functional || ALL -// +build alb functional ALL +//go:build nsxt || alb || functional || ALL +// +build nsxt alb functional ALL package govcd diff --git a/types/v56/nsxt_types.go b/types/v56/nsxt_types.go index 218d0f4a2..676ba393f 100644 --- a/types/v56/nsxt_types.go +++ b/types/v56/nsxt_types.go @@ -681,6 +681,7 @@ type NsxtIpSecVpnTunnelProfileDpdConfiguration struct { // NsxtAlbController helps to integrate VMware Cloud Director with NSX-T Advanced Load Balancer deployment. // Controller instances are registered with VMware Cloud Director instance. Controller instances serve as a central // control plane for the load-balancing services provided by NSX-T Advanced Load Balancer. +// To configure an NSX-T ALB one needs to supply AVI Controller endpoint, credentials and license to be used. type NsxtAlbController struct { // ID holds URN for load balancer controller (e.g. urn:vcloud:loadBalancerController:aa23ef66-ba32-48b2-892f-7acdffe4587e) ID string `json:"id,omitempty"` @@ -719,14 +720,8 @@ type NsxtAlbImportableCloud struct { TransportZoneName string `json:"transportZoneName"` } -// NsxtAlbCloud allows users to use the virtual infrastructure provided by NSX Advanced Load Balancer, register your -// NSX-T Cloud instances with VMware Cloud Director. An NSX-T Cloud is a service provider-level construct that consists -// of an NSX-T Manager and an NSX-T Data Center transport zone. NSX-T Manager provides a system view and is the -// management component of NSX-T Data Center. An NSX-T Data Center transport zone dictates which hosts and virtual -// machines can participate in the use of a particular network. If there are multiple transport zones managed by the -// same NSX-T Manager, then a separate NSX-T Cloud encapsulates each pair of NSX-T Manager and NSX-T Data Center -// transport zone instances. An NSX-T Cloud has a one-to-one relationship with a network pool backed by an NSX-T Data -// Center transport zone. +// NsxtAlbCloud helps to use the virtual infrastructure provided by NSX Advanced Load Balancer, register NSX-T Cloud +// instances with VMware Cloud Director by consuming NsxtAlbImportableCloud. type NsxtAlbCloud struct { // ID (e.g. 'urn:vcloud:loadBalancerCloud:947ea2ba-e448-4249-91f7-1432b3d2fcbf') ID string `json:"id,omitempty"` @@ -761,8 +756,9 @@ type NsxtAlbCloudBacking struct { LoadBalancerControllerRef OpenApiReference `json:"loadBalancerControllerRef"` } -// NsxtAlbServiceEngineGroup allows users to provide virtual service management capabilities to your tenants, import -// service engine groups to your VMware Cloud Director deployment. +// NsxtAlbServiceEngineGroup provides virtual service management capabilities for tenants. This entity can be created +// by referencing a backing importable service engine group - NsxtAlbImportableServiceEngineGroups. +// // A service engine group is an isolation domain that also defines shared service engine properties, such as size, // network access, and failover. Resources in a service engine group can be used for different virtual services, // depending on your tenant needs. These resources cannot be shared between different service engine groups. @@ -805,7 +801,10 @@ type ServiceEngineGroupBacking struct { LoadBalancerCloudRef *OpenApiReference `json:"loadBalancerCloudRef"` } -// NsxtAlbImportableServiceEngineGroups is used to get Importable Service Engine Groups +// NsxtAlbImportableServiceEngineGroups provides capability to list all Importable Service Engine Groups available in +// ALB Controller so that they can be consumed by NsxtAlbServiceEngineGroup +// +// Note. The API does not return Importable Service Engine Group once it is consumed. type NsxtAlbImportableServiceEngineGroups struct { // ID (e.g. 'serviceenginegroup-b633f16f-2733-4bf5-b552-3a6c4949caa4') ID string `json:"id"`