-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more VM class methods, rename VDC to Region Quota, add more Regio…
…nQuotaStoragePolicy methods, fix NSX (#748) Signed-off-by: abarreiro <[email protected]>
- Loading branch information
1 parent
1db423b
commit 333338d
Showing
21 changed files
with
703 additions
and
471 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,7 +1,8 @@ | ||
* Added types `TmVdc` and `types.TmVdc` for managing Tenant Manager Org VDCs with methods | ||
`VCDClient.CreateTmVdc`, `VCDClient.GetAllTmVdcs`, `VCDClient.GetTmVdcByName`, | ||
`VCDClient.GetTmVdcById`, `VCDClient.GetTmVdcByNameAndOrgId`, `TmVdc.Update`, `TmVdc.Delete` | ||
[GH-720, GH-738] | ||
* Added types `RegionQuota` and `types.TmVdc` for managing Tenant Manager Org VDCs with methods | ||
`VCDClient.CreateRegionQuota`, `VCDClient.GetAllRegionQuotas`, `VCDClient.GetRegionQuotaByName`, | ||
`VCDClient.GetRegionQuotaByNameAndOrgId`, `VCDClient.GetRegionQuotaById`, `RegionQuota.Update`, `RegionQuota.Delete`, | ||
`VCDClient.AssignVmClassesToRegionQuota`, `RegionQuota.AssignVmClasses`, | ||
`VCDClient.GetVmClassesFromRegionQuota` [GH-720, GH-738, GH-748] | ||
* Added types `Zone` and `types.Zone` for reading Region Zones with methods `VCDClient.GetAllZones`, | ||
`VCDClient.GetZoneByName`, `VCDClient.GetZoneById`, `Region.GetAllZones`, `Region.GetZoneByName` | ||
[GH-720] |
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,4 +1,6 @@ | ||
* Added types `TmVdcStoragePolicy`, `types.VirtualDatacenterStoragePolicies` and `types.VirtualDatacenterStoragePolicy` | ||
to manage VDC Storage Policies, with methods `TmVdc.CreateStoragePolicies`, `VCDClient.GetAllTmVdcStoragePolicies`, | ||
`TmVdc.GetAllStoragePolicies`, `VCDClient.GetTmVdcStoragePolicyById`, | ||
`TmVdc.GetStoragePolicyById`, `TmVdc.Update`, `TmVdc.Delete` [GH-734] | ||
* Added types `RegionQuotaStoragePolicy`, `types.VirtualDatacenterStoragePolicies` and `types.VirtualDatacenterStoragePolicy` | ||
to manage VDC Storage Policies, with methods `VCDClient.CreateRegionQuotaStoragePolicies`, `RegionQuota.CreateStoragePolicies`, | ||
`VCDClient.GetAllRegionQuotaStoragePolicies`, `RegionQuota.GetAllStoragePolicies`, | ||
`RegionQuota.GetStoragePolicyByName`, `VCDClient.GetRegionQuotaStoragePolicyById`, | ||
`RegionQuota.GetStoragePolicyById`, `VCDClient.UpdateRegionQuotaStoragePolicy`, `RegionQuotaStoragePolicy.Update`, | ||
`VCDClient.DeleteRegionQuotaStoragePolicy`, `RegionQuotaStoragePolicy.Delete` [GH-734, GH-748] |
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,3 @@ | ||
* Added types `RegionVirtualMachineClass` to read Region VM Classes with methods | ||
`VCDClient.GetAllRegionVirtualMachineClasses`, `VCDClient.GetRegionVirtualMachineClassByNameAndRegionId`, | ||
`VCDClient.GetRegionVirtualMachineClassById` [GH-748] |
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
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,168 @@ | ||
package govcd | ||
|
||
/* | ||
* Copyright 2024 VMware, Inc. All rights reserved. Licensed under the Apache v2 License. | ||
*/ | ||
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
|
||
"github.com/vmware/go-vcloud-director/v3/types/v56" | ||
) | ||
|
||
const labelRegionQuota = "Org Region Quota" | ||
|
||
// RegionQuota defines Region Quota structure in Tenant Manager | ||
type RegionQuota struct { | ||
TmVdc *types.TmVdc | ||
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 (g RegionQuota) wrap(inner *types.TmVdc) *RegionQuota { | ||
g.TmVdc = inner | ||
return &g | ||
} | ||
|
||
// CreateRegionQuota sets up a new Region Quota | ||
func (vcdClient *VCDClient) CreateRegionQuota(config *types.TmVdc) (*RegionQuota, error) { | ||
c := crudConfig{ | ||
entityLabel: labelRegionQuota, | ||
endpoint: types.OpenApiPathVcf + types.OpenApiEndpointTmVdcs, | ||
requiresTm: true, | ||
} | ||
outerType := RegionQuota{vcdClient: vcdClient} | ||
return createOuterEntity(&vcdClient.Client, outerType, c, config) | ||
} | ||
|
||
// GetAllRegionQuotas retrieves all Region Quotas | ||
func (vcdClient *VCDClient) GetAllRegionQuotas(queryParameters url.Values) ([]*RegionQuota, error) { | ||
c := crudConfig{ | ||
entityLabel: labelRegionQuota, | ||
endpoint: types.OpenApiPathVcf + types.OpenApiEndpointTmVdcs, | ||
queryParameters: queryParameters, | ||
requiresTm: true, | ||
} | ||
|
||
outerType := RegionQuota{vcdClient: vcdClient} | ||
return getAllOuterEntities(&vcdClient.Client, outerType, c) | ||
} | ||
|
||
// GetRegionQuotaByName retrieves a Region Quota by a given name | ||
func (vcdClient *VCDClient) GetRegionQuotaByName(name string) (*RegionQuota, error) { | ||
if name == "" { | ||
return nil, fmt.Errorf("%s lookup requires name", labelRegionQuota) | ||
} | ||
|
||
queryParams := url.Values{} | ||
queryParams.Add("filter", fmt.Sprintf("name==%s", name)) | ||
filteredEntities, err := vcdClient.GetAllRegionQuotas(queryParams) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
singleResult, err := oneOrError("name", name, filteredEntities) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return singleResult, nil | ||
} | ||
|
||
// GetRegionQuotaByNameAndOrgId retrieves a Region Quota by Name and Org ID | ||
func (vcdClient *VCDClient) GetRegionQuotaByNameAndOrgId(name, orgId string) (*RegionQuota, error) { | ||
if name == "" { | ||
return nil, fmt.Errorf("%s lookup requires name and Org ID to be present", labelRegionQuota) | ||
} | ||
|
||
queryParams := url.Values{} | ||
queryParams.Add("filter", fmt.Sprintf("org.id==%s;name==%s", orgId, name)) | ||
|
||
filteredEntities, err := vcdClient.GetAllRegionQuotas(queryParams) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
singleResult, err := oneOrError("name", name, filteredEntities) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return singleResult, nil | ||
} | ||
|
||
// GetRegionQuotaById retrieves a Region Quota by a given ID | ||
func (vcdClient *VCDClient) GetRegionQuotaById(id string) (*RegionQuota, error) { | ||
c := crudConfig{ | ||
entityLabel: labelRegionQuota, | ||
endpoint: types.OpenApiPathVcf + types.OpenApiEndpointTmVdcs, | ||
endpointParams: []string{id}, | ||
requiresTm: true, | ||
} | ||
|
||
outerType := RegionQuota{vcdClient: vcdClient} | ||
return getOuterEntity(&vcdClient.Client, outerType, c) | ||
} | ||
|
||
// Update updates the receiver Region Quota | ||
func (o *RegionQuota) Update(tmVdcConfig *types.TmVdc) (*RegionQuota, error) { | ||
c := crudConfig{ | ||
entityLabel: labelRegionQuota, | ||
endpoint: types.OpenApiPathVcf + types.OpenApiEndpointTmVdcs, | ||
endpointParams: []string{o.TmVdc.ID}, | ||
requiresTm: true, | ||
} | ||
outerType := RegionQuota{vcdClient: o.vcdClient} | ||
return updateOuterEntity(&o.vcdClient.Client, outerType, c, tmVdcConfig) | ||
} | ||
|
||
// Delete deletes the receiver Region Quota | ||
func (o *RegionQuota) Delete() error { | ||
c := crudConfig{ | ||
entityLabel: labelRegionQuota, | ||
endpoint: types.OpenApiPathVcf + types.OpenApiEndpointTmVdcs, | ||
endpointParams: []string{o.TmVdc.ID}, | ||
requiresTm: true, | ||
} | ||
return deleteEntityById(&o.vcdClient.Client, c) | ||
} | ||
|
||
// AssignVmClassesToRegionQuota assigns VM Classes to the receiver Region Quota | ||
func (o *VCDClient) AssignVmClassesToRegionQuota(regionQuotaId string, vmClasses *types.RegionVirtualMachineClasses) error { | ||
c := crudConfig{ | ||
entityLabel: labelRegionQuota, | ||
endpoint: types.OpenApiPathVcf + types.OpenApiEndpointTmVdcsVmClasses, | ||
endpointParams: []string{regionQuotaId}, | ||
requiresTm: true, | ||
} | ||
// It's a PUT call with OpenAPI references, so we reuse generic functions for simplicity | ||
_, err := updateInnerEntity[types.RegionVirtualMachineClasses](&o.Client, c, vmClasses) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
// AssignVmClasses assigns VM Classes to the receiver Region Quota | ||
func (o *RegionQuota) AssignVmClasses(vmClasses *types.RegionVirtualMachineClasses) error { | ||
return o.vcdClient.AssignVmClassesToRegionQuota(o.TmVdc.ID, vmClasses) | ||
} | ||
|
||
// GetVmClassesFromRegionQuota returns all VM Classes of the given Region Quota | ||
func (o *VCDClient) GetVmClassesFromRegionQuota(regionQuotaId string) (*types.RegionVirtualMachineClasses, error) { | ||
c := crudConfig{ | ||
entityLabel: labelRegionQuota, | ||
endpoint: types.OpenApiPathVcf + types.OpenApiEndpointTmVdcsVmClasses, | ||
endpointParams: []string{regionQuotaId}, | ||
requiresTm: true, | ||
} | ||
// It's a GET call with OpenAPI references, so we reuse generic functions for simplicity | ||
result, err := getInnerEntity[types.RegionVirtualMachineClasses](&o.Client, c) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return result, nil | ||
} |
Oops, something went wrong.