Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add VM Group and Logical VM Group support to facilitate VM Placement Policy creation; Update Compute Policies to v2.0.0 #504

Merged
merged 52 commits into from
Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
ea64aca
Init
Aug 25, 2022
b4a34a2
Remove OpenAPI endpoint
Aug 25, 2022
3eb87b1
Add Provider VDC types
Aug 25, 2022
a20f246
Finish provider functions
Aug 25, 2022
532b8f5
Fixes
Aug 26, 2022
e9d2fb3
fmt
Aug 26, 2022
d7cf451
Fix
Aug 26, 2022
dbee8c5
Complete pvdc
Aug 26, 2022
1d315aa
Fix bug with capacity
Aug 26, 2022
f8e46fa
Revert openapi endpoint removal
Aug 29, 2022
3a8b73b
Changelog
Aug 29, 2022
537f89e
Changelog
Aug 29, 2022
960437d
Fix test tags
Aug 29, 2022
56b6b59
Merge branch 'main' of https://github.com/adambarreiro/go-vcloud-dire…
Aug 29, 2022
1982f98
Make constructors private
Aug 29, 2022
e8dd6c8
Added omitempty to Total in ProviderVdcCapacity
Aug 29, 2022
364b278
Remove Vdcs from struct
Aug 29, 2022
54d8de6
Add VM Logical Groups support
Aug 30, 2022
62fe361
Add changelog
Aug 30, 2022
a0c2de0
Fix tests
Aug 31, 2022
c254016
Merge branch 'main' of https://github.com/adambarreiro/go-vcloud-dire…
Aug 31, 2022
1c23890
Merge branch 'main' of https://github.com/adambarreiro/go-vcloud-dire…
Sep 1, 2022
5dea389
Update changelog
Sep 1, 2022
8874400
Fix bug in Provider VDC funcs
Sep 1, 2022
6fbb497
Refactor VM group implementation
Sep 1, 2022
48172ee
#
Sep 1, 2022
7759318
#
Sep 1, 2022
77a849f
#
Sep 1, 2022
e4dce2c
#
Sep 1, 2022
f87ac43
#
Sep 1, 2022
8dd3ad0
Address typo
Sep 2, 2022
ce2c9c5
Address typo
Sep 2, 2022
964bcbb
Upgrade ComputePolicies endpoints to v2.0.0
Sep 2, 2022
eb2865a
Changelog
Sep 2, 2022
f920ab9
Changelog
Sep 2, 2022
ac02aaf
fmt
Sep 5, 2022
2a32cbb
Address comments
Sep 6, 2022
0ecfb3d
Changed to pointer and non-omitempty field
Sep 6, 2022
1914a6d
Config sample
Sep 6, 2022
d78862c
Fix resourcepool parameter
Sep 6, 2022
7edd9b1
Address suggestion
Sep 6, 2022
75323f0
Address suggestion
Sep 6, 2022
20ad037
fmt
Sep 6, 2022
f8e808f
Amend placementPolicyVmGroup config
Sep 8, 2022
f580cae
Amend placementPolicyVmGroup config
Sep 8, 2022
8409888
Amend placementPolicyVmGroup config
Sep 8, 2022
316e37e
Fix cleanup error
Sep 12, 2022
ea7ecb2
Fix problems with tests
Sep 12, 2022
8122bc8
Add constant
Sep 12, 2022
6e27d54
Remove confusing comment
Sep 12, 2022
462b21c
Merge branch 'main' of https://github.com/adambarreiro/go-vcloud-dire…
Sep 21, 2022
68117f5
Add Deprecated note to VdcComputePolicy
Sep 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .changes/v2.17.0/502-improvements.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
* Updated VDC Compute Policies retrieval methods `AdminVdc.GetAllAssignedVdcComputePolicies` and `Org.GetAllVdcComputePolicies`
from OpenAPI v1.0.0 to v2.0.0, this version supports more filtering options like `isVgpuPolicy`[GH-502]
* Created new VDC Compute Policies CRUD methods using OpenAPI v2.0.0:
`VCDClient.GetVdcComputePolicyV2ById`, `VCDClient.GetAllVdcComputePoliciesV2`, `VCDClient.CreateVdcComputePolicyV2`,
`VdcComputePolicyV2.Update`, `VdcComputePolicyV2.Delete` and `AdminVdc.GetAllAssignedVdcComputePoliciesV2`.
This version supports more filtering options like `isVgpuPolicy` [GH-502], [GH-504]
1 change: 1 addition & 0 deletions .changes/v2.17.0/504-bug-fixes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Changed `VdcComputePolicy.Description` to a non-omitempty pointer, to be able to send null values to VCD to set empty descriptions. [GH-504]
3 changes: 3 additions & 0 deletions .changes/v2.17.0/504-deprecations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* Deprecated OpenAPI v1.0.0 VDC Compute Policies CRUD methods in favor of v2.0.0 ones:
`Client.GetVdcComputePolicyById`, `Client.GetAllVdcComputePolicies`, `Client.CreateVdcComputePolicy`
`VdcComputePolicy.Update`, `VdcComputePolicy.Delete` and `AdminVdc.GetAllAssignedVdcComputePolicies` [GH-504]
2 changes: 2 additions & 0 deletions .changes/v2.17.0/504-features.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Added new methods `VCDClient.GetVmGroupById`, `VCDClient.GetVmGroupByNamedVmGroupIdAndProviderVdcUrn` and `VCDClient.GetVmGroupByNameAndProviderVdcUrn` to retrieve VM Groups. These are useful to create VM Placement Policies [GH-504]
* Added new methods `VCDClient.GetLogicalVmGroupById`, `VCDClient.CreateLogicalVmGroup` and `LogicalVmGroup.Delete` to manage Logical VM Groups. These are useful to create VM Placement Policies [GH-504]
23 changes: 19 additions & 4 deletions govcd/api_vcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,10 @@ type TestConfig struct {
NetworkPool string `yaml:"network_pool"`
} `yaml:"provider_vdc"`
NsxtProviderVdc struct {
Name string `yaml:"name"`
StorageProfile string `yaml:"storage_profile"`
NetworkPool string `yaml:"network_pool"`
Name string `yaml:"name"`
StorageProfile string `yaml:"storage_profile"`
NetworkPool string `yaml:"network_pool"`
PlacementPolicyVmGroup string `yaml:"placementPolicyVmGroup,omitempty"`
} `yaml:"nsxt_provider_vdc"`
Catalog struct {
Name string `yaml:"name,omitempty"`
Expand Down Expand Up @@ -1531,7 +1532,7 @@ func (vcd *TestVCD) removeLeftoverEntities(entity CleanupEntity) {
return

case "vdcComputePolicy":
policy, err := vcd.client.Client.GetVdcComputePolicyById(entity.Name)
policy, err := vcd.client.GetVdcComputePolicyV2ById(entity.Name)
if policy == nil || err != nil {
vcd.infoCleanup(notFoundMsg, "vdcComputePolicy", entity.Name)
return
Expand All @@ -1544,6 +1545,20 @@ func (vcd *TestVCD) removeLeftoverEntities(entity CleanupEntity) {
}
return

case "logicalVmGroup":
logicalVmGroup, err := vcd.client.GetLogicalVmGroupById(entity.Name)
if logicalVmGroup == nil || err != nil {
vcd.infoCleanup(notFoundMsg, "logicalVmGroup", entity.Name)
return
}
err = logicalVmGroup.Delete()
if err == nil {
vcd.infoCleanup(removedMsg, entity.EntityType, entity.Name, entity.CreatedBy)
} else {
vcd.infoCleanup(notDeletedMsg, entity.EntityType, entity.Name, err)
}
return

default:
// If we reach this point, we are trying to clean up an entity that
// we aren't prepared for yet.
Expand Down
1 change: 1 addition & 0 deletions govcd/openapi_endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ var endpointMinApiVersions = map[string]string{
types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointVdcGroupsDfwDefaultPolicies: "35.0", // VCD 10.2+
types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointSecurityTags: "36.0", // VCD 10.3+
types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointNsxtRouteAdvertisement: "34.0", // VCD 10.1+
types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointLogicalVmGroups: "35.0", // VCD 10.2+

// NSX-T ALB (Advanced/AVI Load Balancer) support was introduced in 10.2
types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointAlbController: "35.0", // VCD 10.2+
Expand Down
6 changes: 6 additions & 0 deletions govcd/provider_vdc.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ func (vcdClient *VCDClient) GetProviderVdcExtendedById(providerVdcId string) (*P
// On failure, returns a nil pointer and an error
func (vcdClient *VCDClient) GetProviderVdcByName(providerVdcName string) (*ProviderVdc, error) {
providerVdc, err := getProviderVdcByName(vcdClient, providerVdcName, false)
if err != nil {
return nil, err
}
return providerVdc.(*ProviderVdc), err
}

Expand All @@ -96,6 +99,9 @@ func (vcdClient *VCDClient) GetProviderVdcByName(providerVdcName string) (*Provi
// On failure, returns a nil pointer and an error
func (vcdClient *VCDClient) GetProviderVdcExtendedByName(providerVdcName string) (*ProviderVdcExtended, error) {
providerVdcExtended, err := getProviderVdcByName(vcdClient, providerVdcName, true)
if err != nil {
return nil, err
}
return providerVdcExtended.(*ProviderVdcExtended), err
}

Expand Down
70 changes: 65 additions & 5 deletions govcd/provider_vdc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,26 @@ func (vcd *TestVCD) Test_GetProviderVdc(check *C) {
// Common asserts
for _, providerVdc := range providerVdcs {
check.Assert(providerVdc.ProviderVdc.Name, Equals, vcd.config.VCD.NsxtProviderVdc.Name)
check.Assert(providerVdc.ProviderVdc.StorageProfiles.ProviderVdcStorageProfile[0].Name, Equals, vcd.config.VCD.NsxtProviderVdc.StorageProfile)
foundStorageProfile := false
for _, storageProfile := range providerVdc.ProviderVdc.StorageProfiles.ProviderVdcStorageProfile {
if storageProfile.Name == vcd.config.VCD.NsxtProviderVdc.StorageProfile {
foundStorageProfile = true
break
}
}
check.Assert(foundStorageProfile, Equals, true)
check.Assert(*providerVdc.ProviderVdc.IsEnabled, Equals, true)
check.Assert(providerVdc.ProviderVdc.ComputeCapacity, NotNil)
check.Assert(providerVdc.ProviderVdc.Status, Equals, 1)
check.Assert(len(providerVdc.ProviderVdc.NetworkPoolReferences.NetworkPoolReference), Equals, 1)
check.Assert(providerVdc.ProviderVdc.NetworkPoolReferences.NetworkPoolReference[0].Name, Equals, vcd.config.VCD.NsxtProviderVdc.NetworkPool)
foundNetworkPool := false
for _, networkPool := range providerVdc.ProviderVdc.NetworkPoolReferences.NetworkPoolReference {
if networkPool.Name == vcd.config.VCD.NsxtProviderVdc.NetworkPool {
foundNetworkPool = true
break
}
}
check.Assert(foundNetworkPool, Equals, true)
check.Assert(providerVdc.ProviderVdc.Link, NotNil)
}
}
Expand All @@ -62,12 +76,26 @@ func (vcd *TestVCD) Test_GetProviderVdcExtended(check *C) {
for _, providerVdcExtended := range providerVdcsExtended {
// Basic PVDC asserts
check.Assert(providerVdcExtended.VMWProviderVdc.Name, Equals, vcd.config.VCD.NsxtProviderVdc.Name)
check.Assert(providerVdcExtended.VMWProviderVdc.StorageProfiles.ProviderVdcStorageProfile[0].Name, Equals, vcd.config.VCD.NsxtProviderVdc.StorageProfile)
foundStorageProfile := false
for _, storageProfile := range providerVdcExtended.VMWProviderVdc.StorageProfiles.ProviderVdcStorageProfile {
if storageProfile.Name == vcd.config.VCD.NsxtProviderVdc.StorageProfile {
foundStorageProfile = true
break
}
}
check.Assert(foundStorageProfile, Equals, true)
check.Assert(*providerVdcExtended.VMWProviderVdc.IsEnabled, Equals, true)
check.Assert(providerVdcExtended.VMWProviderVdc.ComputeCapacity, NotNil)
check.Assert(providerVdcExtended.VMWProviderVdc.Status, Equals, 1)
check.Assert(len(providerVdcExtended.VMWProviderVdc.NetworkPoolReferences.NetworkPoolReference), Equals, 1)
check.Assert(providerVdcExtended.VMWProviderVdc.NetworkPoolReferences.NetworkPoolReference[0].Name, Equals, vcd.config.VCD.NsxtProviderVdc.NetworkPool)
foundNetworkPool := false
for _, networkPool := range providerVdcExtended.VMWProviderVdc.NetworkPoolReferences.NetworkPoolReference {
if networkPool.Name == vcd.config.VCD.NsxtProviderVdc.NetworkPool {
foundNetworkPool = true
break
}
}
check.Assert(foundNetworkPool, Equals, true)
check.Assert(providerVdcExtended.VMWProviderVdc.Link, NotNil)
// Extended PVDC asserts
check.Assert(providerVdcExtended.VMWProviderVdc.ComputeProviderScope, Equals, "vc1")
Expand All @@ -81,6 +109,31 @@ func (vcd *TestVCD) Test_GetProviderVdcExtended(check *C) {
}
}

func (vcd *TestVCD) Test_GetNonExistentProviderVdc(check *C) {
if vcd.skipAdminTests {
check.Skip(fmt.Sprintf(TestRequiresSysAdminPrivileges, check.TestName()))
}

providerVdcExtended, err := vcd.client.GetProviderVdcExtendedByName("non-existent-pvdc")
check.Assert(providerVdcExtended, IsNil)
check.Assert(err, NotNil)
providerVdcExtended, err = vcd.client.GetProviderVdcExtendedById("non-existent-pvdc")
check.Assert(providerVdcExtended, IsNil)
check.Assert(err, NotNil)
providerVdcExtended, err = vcd.client.GetProviderVdcExtendedByHref("non-existent-pvdc")
check.Assert(providerVdcExtended, IsNil)
check.Assert(err, NotNil)
providerVdc, err := vcd.client.GetProviderVdcByName("non-existent-pvdc")
check.Assert(providerVdc, IsNil)
check.Assert(err, NotNil)
providerVdc, err = vcd.client.GetProviderVdcById("non-existent-pvdc")
check.Assert(providerVdc, IsNil)
check.Assert(err, NotNil)
providerVdc, err = vcd.client.GetProviderVdcByHref("non-existent-pvdc")
check.Assert(providerVdc, IsNil)
check.Assert(err, NotNil)
}

func (vcd *TestVCD) Test_GetProviderVdcConvertFromExtendedToNormal(check *C) {
if vcd.skipAdminTests {
check.Skip(fmt.Sprintf(TestRequiresSysAdminPrivileges, check.TestName()))
Expand All @@ -91,7 +144,14 @@ func (vcd *TestVCD) Test_GetProviderVdcConvertFromExtendedToNormal(check *C) {
providerVdc, err := providerVdcExtended.ToProviderVdc()
check.Assert(err, IsNil)
check.Assert(providerVdc.ProviderVdc.Name, Equals, vcd.config.VCD.NsxtProviderVdc.Name)
check.Assert(providerVdc.ProviderVdc.StorageProfiles.ProviderVdcStorageProfile[0].Name, Equals, vcd.config.VCD.NsxtProviderVdc.StorageProfile)
foundStorageProfile := false
for _, storageProfile := range providerVdc.ProviderVdc.StorageProfiles.ProviderVdcStorageProfile {
if storageProfile.Name == vcd.config.VCD.NsxtProviderVdc.StorageProfile {
foundStorageProfile = true
break
}
}
check.Assert(foundStorageProfile, Equals, true)
check.Assert(*providerVdc.ProviderVdc.IsEnabled, Equals, true)
check.Assert(providerVdc.ProviderVdc.Status, Equals, 1)
check.Assert(len(providerVdc.ProviderVdc.NetworkPoolReferences.NetworkPoolReference), Equals, 1)
Expand Down
3 changes: 3 additions & 0 deletions govcd/sample_govcd_test_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ vcd:
name: nsxTPvdc1
storage_profile: "*"
network_pool: "NSX-T Overlay 1"
# A VM Group that needs to exist in the backing vSphere. This VM Group can be used
# to create VM Placement Policies.
placementPolicyVmGroup: testVmGroup
nsxt:
# NSX-T manager name to be used as defined in VCD
manager: nsxManager1
Expand Down
2 changes: 1 addition & 1 deletion govcd/vapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1507,7 +1507,7 @@ func (vcd *TestVCD) Test_AddNewVMWithComputeCapacity(check *C) {
client: vcd.org.client,
VdcComputePolicy: &types.VdcComputePolicy{
Name: check.TestName() + "_empty",
Description: "Empty policy created by test",
Description: takeStringPointer("Empty policy created by test"),
},
}

Expand Down
58 changes: 17 additions & 41 deletions govcd/vdccomputepolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,39 @@ package govcd

import (
"fmt"
"net/http"
"net/url"

"github.com/vmware/go-vcloud-director/v2/types/v56"
"github.com/vmware/go-vcloud-director/v2/util"
)

// In UI called VM sizing policy. In API VDC compute policy
// VdcComputePolicy defines a VDC Compute Policy, which can be a VM Sizing Policy, a VM Placement Policy or a vGPU Policy.
// Deprecated: Use VdcComputePolicyV2 instead
type VdcComputePolicy struct {
VdcComputePolicy *types.VdcComputePolicy
Href string
client *Client
}

// GetVdcComputePolicyById retrieves VDC compute policy by given ID
// Deprecated: Use VCDClient.GetVdcComputePolicyV2ById instead
func (client *Client) GetVdcComputePolicyById(id string) (*VdcComputePolicy, error) {
return getVdcComputePolicyById(client, id)
}

// GetVdcComputePolicyById retrieves VDC compute policy by given ID
// Deprecated: use client.GetVdcComputePolicyById
// Deprecated: use VCDClient.GetVdcComputePolicyV2ById
func (org *AdminOrg) GetVdcComputePolicyById(id string) (*VdcComputePolicy, error) {
return getVdcComputePolicyById(org.client, id)
}

// GetVdcComputePolicyById retrieves VDC compute policy by given ID
// Deprecated: use client.GetVdcComputePolicyById
// Deprecated: use VCDClient.GetVdcComputePolicyV2ById
func (org *Org) GetVdcComputePolicyById(id string) (*VdcComputePolicy, error) {
return getVdcComputePolicyById(org.client, id)
}

// getVdcComputePolicyById retrieves VDC compute policy by given ID
// Deprecated: Use getVdcComputePolicyV2ById instead
func getVdcComputePolicyById(client *Client, id string) (*VdcComputePolicy, error) {
endpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointVdcComputePolicies
minimumApiVersion, err := client.checkOpenApiEndpointCompatibility(endpoint)
Expand Down Expand Up @@ -71,28 +72,30 @@ func getVdcComputePolicyById(client *Client, id string) (*VdcComputePolicy, erro

// GetAllVdcComputePolicies retrieves all VDC compute policies using OpenAPI endpoint. Query parameters can be supplied to perform additional
// filtering
// Deprecated: use VCDClient.GetAllVdcComputePoliciesV2
func (client *Client) GetAllVdcComputePolicies(queryParameters url.Values) ([]*VdcComputePolicy, error) {
return getAllVdcComputePolicies(client, queryParameters)
}

// GetAllVdcComputePolicies retrieves all VDC compute policies using OpenAPI endpoint. Query parameters can be supplied to perform additional
// filtering
// Deprecated: use client.GetAllVdcComputePolicies
// Deprecated: use VCDClient.GetAllVdcComputePoliciesV2
func (org *AdminOrg) GetAllVdcComputePolicies(queryParameters url.Values) ([]*VdcComputePolicy, error) {
return getAllVdcComputePolicies(org.client, queryParameters)
}

// GetAllVdcComputePolicies retrieves all VDC compute policies using OpenAPI endpoint. Query parameters can be supplied to perform additional
// filtering
// Deprecated: use client.GetAllVdcComputePolicies
// Deprecated: use VCDClient.GetAllVdcComputePoliciesV2
func (org *Org) GetAllVdcComputePolicies(queryParameters url.Values) ([]*VdcComputePolicy, error) {
return getAllVdcComputePolicies(org.client, queryParameters)
}

// getAllVdcComputePolicies retrieves all VDC compute policies using OpenAPI endpoint. Query parameters can be supplied to perform additional
// filtering
// Deprecated: use getAllVdcComputePoliciesV2
func getAllVdcComputePolicies(client *Client, queryParameters url.Values) ([]*VdcComputePolicy, error) {
endpoint := types.OpenApiPathVersion2_0_0 + types.OpenApiEndpointVdcComputePolicies
endpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointVdcComputePolicies
minimumApiVersion, err := client.checkOpenApiEndpointCompatibility(endpoint)
if err != nil {
return nil, err
Expand Down Expand Up @@ -123,12 +126,13 @@ func getAllVdcComputePolicies(client *Client, queryParameters url.Values) ([]*Vd
}

// CreateVdcComputePolicy creates a new VDC Compute Policy using OpenAPI endpoint
// Deprecated: use client.CreateVdcComputePolicy
// Deprecated: use VCDClient.CreateVdcComputePolicyV2
func (org *AdminOrg) CreateVdcComputePolicy(newVdcComputePolicy *types.VdcComputePolicy) (*VdcComputePolicy, error) {
return org.client.CreateVdcComputePolicy(newVdcComputePolicy)
}

// CreateVdcComputePolicy creates a new VDC Compute Policy using OpenAPI endpoint
// Deprecated: use VCDClient.CreateVdcComputePolicyV2
func (client *Client) CreateVdcComputePolicy(newVdcComputePolicy *types.VdcComputePolicy) (*VdcComputePolicy, error) {
endpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointVdcComputePolicies
minimumApiVersion, err := client.checkOpenApiEndpointCompatibility(endpoint)
Expand All @@ -155,6 +159,7 @@ func (client *Client) CreateVdcComputePolicy(newVdcComputePolicy *types.VdcCompu
}

// Update existing VDC compute policy
// Deprecated: use VdcComputePolicyV2.Update
func (vdcComputePolicy *VdcComputePolicy) Update() (*VdcComputePolicy, error) {
endpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointVdcComputePolicies
minimumApiVersion, err := vdcComputePolicy.client.checkOpenApiEndpointCompatibility(endpoint)
Expand Down Expand Up @@ -185,6 +190,7 @@ func (vdcComputePolicy *VdcComputePolicy) Update() (*VdcComputePolicy, error) {
}

// Delete deletes VDC compute policy
// Deprecated: use VdcComputePolicyV2.Delete
func (vdcComputePolicy *VdcComputePolicy) Delete() error {
endpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointVdcComputePolicies
minimumApiVersion, err := vdcComputePolicy.client.checkOpenApiEndpointCompatibility(endpoint)
Expand Down Expand Up @@ -212,8 +218,9 @@ func (vdcComputePolicy *VdcComputePolicy) Delete() error {

// GetAllAssignedVdcComputePolicies retrieves all VDC assigned compute policies using OpenAPI endpoint. Query parameters can be supplied to perform additional
// filtering
// Deprecated: use AdminVdc.GetAllAssignedVdcComputePoliciesV2
func (vdc *AdminVdc) GetAllAssignedVdcComputePolicies(queryParameters url.Values) ([]*VdcComputePolicy, error) {
endpoint := types.OpenApiPathVersion2_0_0 + types.OpenApiEndpointVdcAssignedComputePolicies
endpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointVdcAssignedComputePolicies
minimumApiVersion, err := vdc.client.checkOpenApiEndpointCompatibility(endpoint)
if err != nil {
return nil, err
Expand Down Expand Up @@ -242,34 +249,3 @@ func (vdc *AdminVdc) GetAllAssignedVdcComputePolicies(queryParameters url.Values

return wrappedVdcComputePolicies, nil
}

// SetAssignedComputePolicies assign(set) compute policies.
func (vdc *AdminVdc) SetAssignedComputePolicies(computePolicyReferences types.VdcComputePolicyReferences) (*types.VdcComputePolicyReferences, error) {
util.Logger.Printf("[TRACE] Set Compute Policies started")

if !vdc.client.IsSysAdmin {
return nil, fmt.Errorf("functionality requires System Administrator privileges")
}

adminVdcPolicyHREF, err := url.ParseRequestURI(vdc.AdminVdc.HREF)
if err != nil {
return nil, fmt.Errorf("error parsing VDC URL: %s", err)
}

vdcId, err := GetUuidFromHref(vdc.AdminVdc.HREF, true)
if err != nil {
return nil, fmt.Errorf("unable to get vdc ID from HREF: %s", err)
}
adminVdcPolicyHREF.Path = "/api/admin/vdc/" + vdcId + "/computePolicies"

returnedVdcComputePolicies := &types.VdcComputePolicyReferences{}
computePolicyReferences.Xmlns = types.XMLNamespaceVCloud

_, err = vdc.client.ExecuteRequest(adminVdcPolicyHREF.String(), http.MethodPut,
types.MimeVdcComputePolicyReferences, "error setting compute policies for VDC: %s", computePolicyReferences, returnedVdcComputePolicies)
if err != nil {
return nil, err
}

return returnedVdcComputePolicies, nil
}
Loading