-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Regions, supervisors and supervisor zones (#718)
- Loading branch information
Showing
13 changed files
with
731 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
* Added `TmOrg` and `types.TmOrg` to structure for OpenAPI management of Organizations with methods | ||
* Added `TmOrg` and `types.TmOrg` structure for OpenAPI management of Organizations with methods | ||
`VCDClient.CreateTmOrg`, `VCDClient.GetAllTmOrgs`, `VCDClient.GetTmOrgByName`, | ||
`VCDClient.GetTmOrgById`, `TmOrg.Update`, `TmOrg.Delete`, `TmOrg.Disable` [GH-716] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
* Added `VCDClient.GetNsxtManagerOpenApiByUrl` method to retrieve configured NSX-T Manager entry | ||
based on URL [GH-718] | ||
* Added `VCDClient.GetVCenterByUrl` method to retrieve configured vCenter server entry based on URL | ||
[GH-718] | ||
* Added `VCenter.RefreshStorageProfiles` to refresh storage profiles available in vCenter server | ||
[GH-718] | ||
* Added `Region` and `types.Region` to structure for OpenAPI management of Regions with methods | ||
`VCDClient.CreateRegion`, `VCDClient.GetAllRegions`, `VCDClient.GetRegionByName`, | ||
`VCDClient.GetRegionById`, `Region.Update`, `Region.Delete` [GH-718] | ||
* Added `Supervisor` and `types.Supervisor` structure for reading available Supervisors | ||
`VCDClient.GetAllSupervisors`, `VCDClient.GetSupervisorById`, `VCDClient.GetSupervisorByName`, | ||
`VCDClient.GetSupervisorByNameAndVcenterId`, `Vcenter.GetAllSupervisors`, | ||
`Vcenter.GetSupervisorByName` [GH-718] | ||
* Added `SupervisorZone` and `types.SupervisorZone` structure for reading available Supervisor Zones | ||
`Supervisor.GetAllSupervisorZones`, `Supervisor.GetSupervisorZoneById`, | ||
`Supervisor.GetSupervisorZoneByName`, `Supervisor.`, `VCDClient.GetAllSupervisors`, | ||
`VCDClient.GetSupervisorById`, `VCDClient.GetSupervisorByName`, `Vcenter.GetAllSupervisors` | ||
[GH-718] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package govcd | ||
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
|
||
"github.com/vmware/go-vcloud-director/v3/types/v56" | ||
) | ||
|
||
const labelRegion = "Region" | ||
|
||
type Region struct { | ||
Region *types.Region | ||
vcdClient *VCDClient | ||
} | ||
|
||
// wrap is a hidden helper that facilitates the usage of a generic CRUD function | ||
// | ||
//lint:ignore U1000 this method is used in generic functions, but annoys staticcheck | ||
func (r Region) wrap(inner *types.Region) *Region { | ||
r.Region = inner | ||
return &r | ||
} | ||
|
||
// CreateRegion creates a new region | ||
func (vcdClient *VCDClient) CreateRegion(config *types.Region) (*Region, error) { | ||
c := crudConfig{ | ||
entityLabel: labelRegion, | ||
endpoint: types.OpenApiPathVcf + types.OpenApiEndpointRegions, | ||
} | ||
outerType := Region{vcdClient: vcdClient} | ||
return createOuterEntity(&vcdClient.Client, outerType, c, config) | ||
} | ||
|
||
// GetAllRegions retrieves all Regions with an optional query filter | ||
func (vcdClient *VCDClient) GetAllRegions(queryParameters url.Values) ([]*Region, error) { | ||
c := crudConfig{ | ||
entityLabel: labelRegion, | ||
endpoint: types.OpenApiPathVcf + types.OpenApiEndpointRegions, | ||
queryParameters: queryParameters, | ||
} | ||
|
||
outerType := Region{vcdClient: vcdClient} | ||
return getAllOuterEntities(&vcdClient.Client, outerType, c) | ||
} | ||
|
||
// GetRegionByName retrieves a region by name | ||
func (vcdClient *VCDClient) GetRegionByName(name string) (*Region, error) { | ||
if name == "" { | ||
return nil, fmt.Errorf("%s lookup requires name", labelRegion) | ||
} | ||
|
||
queryParams := url.Values{} | ||
queryParams.Add("filter", "name=="+name) | ||
|
||
filteredEntities, err := vcdClient.GetAllRegions(queryParams) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
singleEntity, err := oneOrError("name", name, filteredEntities) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return vcdClient.GetRegionById(singleEntity.Region.ID) | ||
} | ||
|
||
// GetRegionById retrieves a region by ID | ||
func (vcdClient *VCDClient) GetRegionById(id string) (*Region, error) { | ||
c := crudConfig{ | ||
entityLabel: labelRegion, | ||
endpoint: types.OpenApiPathVcf + types.OpenApiEndpointRegions, | ||
endpointParams: []string{id}, | ||
} | ||
|
||
outerType := Region{vcdClient: vcdClient} | ||
return getOuterEntity(&vcdClient.Client, outerType, c) | ||
} | ||
|
||
// Update Region with new configuration | ||
func (r *Region) Update(RegionConfig *types.Region) (*Region, error) { | ||
c := crudConfig{ | ||
entityLabel: labelRegion, | ||
endpoint: types.OpenApiPathVcf + types.OpenApiEndpointRegions, | ||
endpointParams: []string{r.Region.ID}, | ||
} | ||
outerType := Region{vcdClient: r.vcdClient} | ||
return updateOuterEntity(&r.vcdClient.Client, outerType, c, RegionConfig) | ||
} | ||
|
||
// Delete Region | ||
func (r *Region) Delete() error { | ||
c := crudConfig{ | ||
entityLabel: labelRegion, | ||
endpoint: types.OpenApiPathVcf + types.OpenApiEndpointRegions, | ||
endpointParams: []string{r.Region.ID}, | ||
} | ||
return deleteEntityById(&r.vcdClient.Client, c) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
//go:build tm || functional || ALL | ||
|
||
/* | ||
* Copyright 2024 VMware, Inc. All rights reserved. Licensed under the Apache v2 License. | ||
*/ | ||
|
||
package govcd | ||
|
||
import ( | ||
"net/url" | ||
|
||
"github.com/vmware/go-vcloud-director/v3/types/v56" | ||
. "gopkg.in/check.v1" | ||
) | ||
|
||
func (vcd *TestVCD) Test_TmRegion(check *C) { | ||
skipNonTm(vcd, check) | ||
sysadminOnly(vcd, check) | ||
|
||
vc, vcCreated, nsxtManager, nsxtManagerCreated := getOrCreateVcAndNsxtManager(vcd, check) | ||
supervisor, err := vc.GetSupervisorByName(vcd.config.Tm.VcenterSupervisor) | ||
check.Assert(err, IsNil) | ||
|
||
r := &types.Region{ | ||
Name: check.TestName(), | ||
NsxManager: &types.OpenApiReference{ | ||
ID: nsxtManager.NsxtManagerOpenApi.ID, | ||
}, | ||
Supervisors: []types.OpenApiReference{ | ||
{ | ||
ID: supervisor.Supervisor.SupervisorID, | ||
Name: supervisor.Supervisor.Name, | ||
}, | ||
}, | ||
StoragePolicies: []string{vcd.config.Tm.VcenterStorageProfile}, | ||
IsEnabled: true, | ||
} | ||
|
||
createdRegion, err := vcd.client.CreateRegion(r) | ||
check.Assert(err, IsNil) | ||
check.Assert(createdRegion.Region, NotNil) | ||
AddToCleanupListOpenApi(createdRegion.Region.ID, check.TestName(), types.OpenApiPathVcf+types.OpenApiEndpointRegions+createdRegion.Region.ID) | ||
|
||
check.Assert(createdRegion.Region.Status, Equals, "READY") // Region is operational | ||
|
||
// Get By Name | ||
byName, err := vcd.client.GetRegionByName(r.Name) | ||
check.Assert(err, IsNil) | ||
check.Assert(byName, NotNil) | ||
|
||
// Get By ID | ||
byId, err := vcd.client.GetRegionById(createdRegion.Region.ID) | ||
check.Assert(err, IsNil) | ||
check.Assert(byId, NotNil) | ||
|
||
check.Assert(byName.Region, DeepEquals, byId.Region) | ||
|
||
// Get All | ||
allRegions, err := vcd.client.GetAllRegions(nil) | ||
check.Assert(err, IsNil) | ||
check.Assert(allRegions, NotNil) | ||
check.Assert(len(allRegions) > 0, Equals, true) | ||
|
||
// TODO: TM: No Update so far | ||
// Update | ||
// createdRegion.Region.IsEnabled = false | ||
// updated, err := createdRegion.Update(createdRegion.Region) | ||
// check.Assert(err, IsNil) | ||
// check.Assert(updated, NotNil) | ||
|
||
// Delete | ||
err = createdRegion.Delete() | ||
check.Assert(err, IsNil) | ||
|
||
notFoundByName, err := vcd.client.GetRegionByName(createdRegion.Region.Name) | ||
check.Assert(ContainsNotFound(err), Equals, true) | ||
check.Assert(notFoundByName, IsNil) | ||
|
||
// Cleanup | ||
if vcCreated { | ||
err = vc.Disable() | ||
check.Assert(err, IsNil) | ||
err = vc.Delete() | ||
check.Assert(err, IsNil) | ||
} | ||
|
||
if nsxtManagerCreated { | ||
err = nsxtManager.Delete() | ||
check.Assert(err, IsNil) | ||
} | ||
} | ||
|
||
// getOrCreateVcAndNsxtManager will check configuration file and create vCenter and NSX-T Manager if | ||
// stated in the 'createVcenter' and 'createNsxtManager' properties and they are not present in TM. | ||
// Otherwise it just retrieves them | ||
func getOrCreateVcAndNsxtManager(vcd *TestVCD, check *C) (*VCenter, bool, *NsxtManagerOpenApi, bool) { | ||
vCenterCreated := false | ||
nsxtManagerCreated := false | ||
vc, err := vcd.client.GetVCenterByUrl(vcd.config.Tm.VcenterUrl) | ||
if ContainsNotFound(err) && !vcd.config.Tm.CreateVcenter { | ||
check.Skip("vCenter is not configured and configuration is not allowed in config file") | ||
} | ||
if ContainsNotFound(err) { | ||
vcCfg := &types.VSphereVirtualCenter{ | ||
Name: check.TestName() + "-vc", | ||
Username: vcd.config.Tm.VcenterUsername, | ||
Password: vcd.config.Tm.VcenterPassword, | ||
Url: vcd.config.Tm.VcenterUrl, | ||
IsEnabled: true, | ||
} | ||
// Certificate must be trusted before adding vCenter | ||
url, err := url.Parse(vcCfg.Url) | ||
check.Assert(err, IsNil) | ||
trustedCert, err := vcd.client.AutoTrustCertificate(url) | ||
check.Assert(err, IsNil) | ||
if trustedCert != nil { | ||
AddToCleanupListOpenApi(trustedCert.TrustedCertificate.ID, check.TestName()+"trusted-cert", types.OpenApiPathVersion1_0_0+types.OpenApiEndpointTrustedCertificates+trustedCert.TrustedCertificate.ID) | ||
} | ||
|
||
vc, err = vcd.client.CreateVcenter(vcCfg) | ||
check.Assert(err, IsNil) | ||
check.Assert(vc, NotNil) | ||
PrependToCleanupList(vcCfg.Name, "OpenApiEntityVcenter", check.TestName(), types.OpenApiPathVersion1_0_0+types.OpenApiEndpointVirtualCenters+vc.VSphereVCenter.VcId) | ||
|
||
vCenterCreated = true | ||
// Refresh connected vCenter to be sure that all artifacts are loaded | ||
printVerbose("# Refreshing vCenter %s\n", vc.VSphereVCenter.Url) | ||
err = vc.Refresh() | ||
check.Assert(err, IsNil) | ||
|
||
printVerbose("# Refreshing Storage Profiles in vCenter %s\n", vc.VSphereVCenter.Url) | ||
err = vc.RefreshStorageProfiles() | ||
check.Assert(err, IsNil) | ||
} | ||
|
||
nsxtManager, err := vcd.client.GetNsxtManagerOpenApiByUrl(vcd.config.Tm.NsxtManagerUrl) | ||
if ContainsNotFound(err) && !vcd.config.Tm.CreateNsxtManager { | ||
check.Skip("NSX-T Manager is not configured and configuration is not allowed in config file") | ||
} | ||
if ContainsNotFound(err) { | ||
nsxtCfg := &types.NsxtManagerOpenApi{ | ||
Name: check.TestName(), | ||
Username: vcd.config.Tm.NsxtManagerUsername, | ||
Password: vcd.config.Tm.NsxtManagerPassword, | ||
Url: vcd.config.Tm.NsxtManagerUrl, | ||
} | ||
// Certificate must be trusted before adding NSX-T Manager | ||
url, err := url.Parse(nsxtCfg.Url) | ||
check.Assert(err, IsNil) | ||
trustedCert, err := vcd.client.AutoTrustCertificate(url) | ||
check.Assert(err, IsNil) | ||
if trustedCert != nil { | ||
AddToCleanupListOpenApi(trustedCert.TrustedCertificate.ID, check.TestName()+"trusted-cert", types.OpenApiPathVersion1_0_0+types.OpenApiEndpointTrustedCertificates+trustedCert.TrustedCertificate.ID) | ||
} | ||
nsxtManager, err = vcd.client.CreateNsxtManagerOpenApi(nsxtCfg) | ||
check.Assert(err, IsNil) | ||
check.Assert(nsxtManager, NotNil) | ||
PrependToCleanupListOpenApi(nsxtManager.NsxtManagerOpenApi.ID, check.TestName(), types.OpenApiPathVcf+types.OpenApiEndpointNsxManagers+nsxtManager.NsxtManagerOpenApi.ID) | ||
nsxtManagerCreated = true | ||
} | ||
|
||
return vc, vCenterCreated, nsxtManager, nsxtManagerCreated | ||
} |
Oops, something went wrong.