Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

Commit

Permalink
Update an Org VDC (#727)
Browse files Browse the repository at this point in the history
This commit adds following,
1. a new method `update_org_vdc` to update an org vdc.
2. respective test to validate the method

Signed-off-by: mukultaneja <[email protected]>
  • Loading branch information
mukultaneja committed Dec 7, 2020
1 parent 20f995f commit 63522ff
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 3 deletions.
100 changes: 100 additions & 0 deletions pyvcloud/vcd/org.py
Original file line number Diff line number Diff line change
Expand Up @@ -1593,6 +1593,106 @@ def create_org_vdc(self,
resource_admin, RelationType.ADD, EntityType.VDCS_PARAMS.value,
params)

def update_org_vdc(self,
vdc_name,
description=None,
allocation_model=None,
cpu_units=None,
cpu_allocated=None,
cpu_limit=None,
mem_units=None,
mem_allocated=None,
mem_limit=None,
nic_quota=None,
network_quota=None,
vm_quota=None,
resource_guaranteed_memory=None,
resource_guaranteed_cpu=None,
vcpu_in_mhz=None,
is_thin_provision=None,
is_enabled=None):
"""Update an Organization VDC in the current organization.
:param str vdc_name: name of the org vdc.
:param str description: new description of the org vdc.
:param str allocation_model: updated allocation model used
by the vdc. Accepted values are 'AllocationVApp',
'AllocationPool' or 'ReservationPool'.
:param str cpu_units: updated unit for compute capacity allocated
to the vdc. Accepted values are 'MHz' or 'GHz'.
:param int cpu_allocated: updated capacity that is committed to be
available.
:param int cpu_limit: updated capacity limit relative to the value
specified for allocation.
:param str mem_units: updated unit for memory capacity allocated to
the vdc. Acceptable values are 'MB' or 'GB'.
:param int mem_allocated: updated memory capacity that is committed
to be available.
:param int mem_limit: updated memory capacity limit relative to the
value specified for allocation.
:param int nic_quota: updated maximum number of virtual NICs allowed
in the vdc.
:param int network_quota: updated maximum number of network objects
that can be deployed in the vdc.
:param int vm_quota: updated maximum number of VMs that can be created
in the vdc.
:param float resource_guaranteed_memory: updated percentage of
allocated CPU resources guaranteed to vApps deployed in
the vdc.
:param float resource_guaranteed_cpu: updated percentage of allocated
memory resources guaranteed to vApps deployed in the vdc.
:param int vcpu_in_mhz: updated clock frequency, in MegaHertz,
for any virtual CPU that is allocated to a VM.
:param bool is_thin_provision: True to request thin provisioning.
:param bool is_enabled: True / False if the vdc is enabled for use
by the organization users.
:return: a task to update the vdc.
:rtype: lxml.objectify.ObjectifiedElement
"""
vdc = self.get_vdc(vdc_name, is_admin_operation=True)
if vdc is None:
raise EntityNotFoundException("{0} is not found".format(vdc_name))

if description:
vdc['Description'] = E.Description(description)
if allocation_model:
vdc['AllocationModel'] = E.AllocationModel(allocation_model)
if cpu_units:
vdc.ComputeCapacity.Cpu.Units = E.Units(cpu_units)
if cpu_allocated:
vdc.ComputeCapacity.Cpu.Allocated = E.Allocated(cpu_allocated)
if cpu_limit:
vdc.ComputeCapacity.Cpu.Limit = E.Limit(cpu_limit)
if mem_units:
vdc.ComputeCapacity.Memory.Units = E.Units(mem_units)
if mem_allocated:
vdc.ComputeCapacity.Memory.Allocated = E.Allocated(mem_allocated)
if mem_limit:
vdc.ComputeCapacity.Memory.Limit = E.Limit(mem_limit)
if nic_quota:
vdc['NicQuota'] = E.NicQuota(nic_quota)
if network_quota:
vdc['NetworkQuota'] = E.NetworkQuota(network_quota)
if vm_quota:
vdc['VmQuota'] = E.VmQuota(vm_quota)
if resource_guaranteed_memory:
vdc['ResourceGuaranteedCpu'] = E.ResourceGuaranteedCpu(
resource_guaranteed_cpu)
if resource_guaranteed_cpu:
vdc['ResourceGuaranteedMemory'] = E.ResourceGuaranteedMemory(
resource_guaranteed_memory)
if vcpu_in_mhz:
vdc['VCpuInMhz'] = E.VCpuInMhz(vcpu_in_mhz)
if is_thin_provision:
vdc['IsThinProvision'] = E.IsThinProvision(is_thin_provision)
if is_enabled is not None:
vdc['IsEnabled'] = E.IsEnabled(is_enabled)

return self.client.put_resource(
vdc.get("href"), vdc, EntityType.VDC_ADMIN.value)

def get_vdc(self, name, is_admin_operation=False):
"""Retrieves resource of an org vdc identified by its name.
Expand Down
24 changes: 21 additions & 3 deletions system_tests/vdc_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,25 @@ def test_0010_list_vdc(self):
self.assertIn(TestOrgVDC._new_vdc_name, retrieved_vdc_names)
self.assertIn(TestOrgVDC._new_vdc_href, retrieved_vdc_hrefs)

def test_0020_get_vdc(self):
def test_0020_update_vdc(self):
"""
Updates the existing org vdc. Test the method Org.update_org_vdc().
This test passes if the org vdc can be successfully updated
with the given configuration.
"""
org = Environment.get_test_org(TestOrgVDC._client)
update_vdc_task = org.update_org_vdc(TestOrgVDC._new_vdc_name,
description="Test VDC",
resource_guaranteed_memory=0.5,
resource_guaranteed_cpu=0.5)
TestOrgVDC._client.get_task_monitor().wait_for_success(
task=update_vdc_task)
vdc = org.get_vdc(TestOrgVDC._new_vdc_name, is_admin_operation=True)
self.assertEqual("Test VDC", vdc['Description'])
self.assertEqual(0.5, vdc['ResourceGuaranteedCpu'])
self.assertEqual(0.5, vdc['ResourceGuaranteedMemory'])

def test_0021_get_vdc(self):
"""Test the method VDC.get_vdc().
This test passes if the expected vdc can be successfully retrieved by
name.
Expand All @@ -112,7 +130,7 @@ def test_0020_get_vdc(self):
self.assertEqual(TestOrgVDC._new_vdc_name, vdc.get('name'))
self.assertEqual(TestOrgVDC._new_vdc_href, vdc.get('href'))

def test_0021_get_vdc_admin_href(self):
def test_0022_get_vdc_admin_href(self):
"""Test the method VDC.get_vdc().
This test passes if the expected vdc admin href.
"""
Expand All @@ -121,7 +139,7 @@ def test_0021_get_vdc_admin_href(self):
is_admin_operation=True)
self.assertTrue('/api/admin/' in vdc.get('href'))

def test_0022_get_vdc_non_admin_href(self):
def test_0023_get_vdc_non_admin_href(self):
"""Test the method VDC.get_vdc().
This test passes if the expected vdc non admin href.
"""
Expand Down

0 comments on commit 63522ff

Please sign in to comment.