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

Commit 63522ff

Browse files
authored
Update an Org VDC (#727)
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 <mtaneja@vmware.com>
1 parent 20f995f commit 63522ff

File tree

2 files changed

+121
-3
lines changed

2 files changed

+121
-3
lines changed

pyvcloud/vcd/org.py

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,6 +1593,106 @@ def create_org_vdc(self,
15931593
resource_admin, RelationType.ADD, EntityType.VDCS_PARAMS.value,
15941594
params)
15951595

1596+
def update_org_vdc(self,
1597+
vdc_name,
1598+
description=None,
1599+
allocation_model=None,
1600+
cpu_units=None,
1601+
cpu_allocated=None,
1602+
cpu_limit=None,
1603+
mem_units=None,
1604+
mem_allocated=None,
1605+
mem_limit=None,
1606+
nic_quota=None,
1607+
network_quota=None,
1608+
vm_quota=None,
1609+
resource_guaranteed_memory=None,
1610+
resource_guaranteed_cpu=None,
1611+
vcpu_in_mhz=None,
1612+
is_thin_provision=None,
1613+
is_enabled=None):
1614+
"""Update an Organization VDC in the current organization.
1615+
1616+
:param str vdc_name: name of the org vdc.
1617+
:param str description: new description of the org vdc.
1618+
:param str allocation_model: updated allocation model used
1619+
by the vdc. Accepted values are 'AllocationVApp',
1620+
'AllocationPool' or 'ReservationPool'.
1621+
:param str cpu_units: updated unit for compute capacity allocated
1622+
to the vdc. Accepted values are 'MHz' or 'GHz'.
1623+
:param int cpu_allocated: updated capacity that is committed to be
1624+
available.
1625+
:param int cpu_limit: updated capacity limit relative to the value
1626+
specified for allocation.
1627+
:param str mem_units: updated unit for memory capacity allocated to
1628+
the vdc. Acceptable values are 'MB' or 'GB'.
1629+
:param int mem_allocated: updated memory capacity that is committed
1630+
to be available.
1631+
:param int mem_limit: updated memory capacity limit relative to the
1632+
value specified for allocation.
1633+
:param int nic_quota: updated maximum number of virtual NICs allowed
1634+
in the vdc.
1635+
:param int network_quota: updated maximum number of network objects
1636+
that can be deployed in the vdc.
1637+
:param int vm_quota: updated maximum number of VMs that can be created
1638+
in the vdc.
1639+
:param float resource_guaranteed_memory: updated percentage of
1640+
allocated CPU resources guaranteed to vApps deployed in
1641+
the vdc.
1642+
:param float resource_guaranteed_cpu: updated percentage of allocated
1643+
memory resources guaranteed to vApps deployed in the vdc.
1644+
:param int vcpu_in_mhz: updated clock frequency, in MegaHertz,
1645+
for any virtual CPU that is allocated to a VM.
1646+
:param bool is_thin_provision: True to request thin provisioning.
1647+
:param bool is_enabled: True / False if the vdc is enabled for use
1648+
by the organization users.
1649+
1650+
:return: a task to update the vdc.
1651+
1652+
:rtype: lxml.objectify.ObjectifiedElement
1653+
"""
1654+
vdc = self.get_vdc(vdc_name, is_admin_operation=True)
1655+
if vdc is None:
1656+
raise EntityNotFoundException("{0} is not found".format(vdc_name))
1657+
1658+
if description:
1659+
vdc['Description'] = E.Description(description)
1660+
if allocation_model:
1661+
vdc['AllocationModel'] = E.AllocationModel(allocation_model)
1662+
if cpu_units:
1663+
vdc.ComputeCapacity.Cpu.Units = E.Units(cpu_units)
1664+
if cpu_allocated:
1665+
vdc.ComputeCapacity.Cpu.Allocated = E.Allocated(cpu_allocated)
1666+
if cpu_limit:
1667+
vdc.ComputeCapacity.Cpu.Limit = E.Limit(cpu_limit)
1668+
if mem_units:
1669+
vdc.ComputeCapacity.Memory.Units = E.Units(mem_units)
1670+
if mem_allocated:
1671+
vdc.ComputeCapacity.Memory.Allocated = E.Allocated(mem_allocated)
1672+
if mem_limit:
1673+
vdc.ComputeCapacity.Memory.Limit = E.Limit(mem_limit)
1674+
if nic_quota:
1675+
vdc['NicQuota'] = E.NicQuota(nic_quota)
1676+
if network_quota:
1677+
vdc['NetworkQuota'] = E.NetworkQuota(network_quota)
1678+
if vm_quota:
1679+
vdc['VmQuota'] = E.VmQuota(vm_quota)
1680+
if resource_guaranteed_memory:
1681+
vdc['ResourceGuaranteedCpu'] = E.ResourceGuaranteedCpu(
1682+
resource_guaranteed_cpu)
1683+
if resource_guaranteed_cpu:
1684+
vdc['ResourceGuaranteedMemory'] = E.ResourceGuaranteedMemory(
1685+
resource_guaranteed_memory)
1686+
if vcpu_in_mhz:
1687+
vdc['VCpuInMhz'] = E.VCpuInMhz(vcpu_in_mhz)
1688+
if is_thin_provision:
1689+
vdc['IsThinProvision'] = E.IsThinProvision(is_thin_provision)
1690+
if is_enabled is not None:
1691+
vdc['IsEnabled'] = E.IsEnabled(is_enabled)
1692+
1693+
return self.client.put_resource(
1694+
vdc.get("href"), vdc, EntityType.VDC_ADMIN.value)
1695+
15961696
def get_vdc(self, name, is_admin_operation=False):
15971697
"""Retrieves resource of an org vdc identified by its name.
15981698

system_tests/vdc_tests.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,25 @@ def test_0010_list_vdc(self):
102102
self.assertIn(TestOrgVDC._new_vdc_name, retrieved_vdc_names)
103103
self.assertIn(TestOrgVDC._new_vdc_href, retrieved_vdc_hrefs)
104104

105-
def test_0020_get_vdc(self):
105+
def test_0020_update_vdc(self):
106+
"""
107+
Updates the existing org vdc. Test the method Org.update_org_vdc().
108+
This test passes if the org vdc can be successfully updated
109+
with the given configuration.
110+
"""
111+
org = Environment.get_test_org(TestOrgVDC._client)
112+
update_vdc_task = org.update_org_vdc(TestOrgVDC._new_vdc_name,
113+
description="Test VDC",
114+
resource_guaranteed_memory=0.5,
115+
resource_guaranteed_cpu=0.5)
116+
TestOrgVDC._client.get_task_monitor().wait_for_success(
117+
task=update_vdc_task)
118+
vdc = org.get_vdc(TestOrgVDC._new_vdc_name, is_admin_operation=True)
119+
self.assertEqual("Test VDC", vdc['Description'])
120+
self.assertEqual(0.5, vdc['ResourceGuaranteedCpu'])
121+
self.assertEqual(0.5, vdc['ResourceGuaranteedMemory'])
122+
123+
def test_0021_get_vdc(self):
106124
"""Test the method VDC.get_vdc().
107125
This test passes if the expected vdc can be successfully retrieved by
108126
name.
@@ -112,7 +130,7 @@ def test_0020_get_vdc(self):
112130
self.assertEqual(TestOrgVDC._new_vdc_name, vdc.get('name'))
113131
self.assertEqual(TestOrgVDC._new_vdc_href, vdc.get('href'))
114132

115-
def test_0021_get_vdc_admin_href(self):
133+
def test_0022_get_vdc_admin_href(self):
116134
"""Test the method VDC.get_vdc().
117135
This test passes if the expected vdc admin href.
118136
"""
@@ -121,7 +139,7 @@ def test_0021_get_vdc_admin_href(self):
121139
is_admin_operation=True)
122140
self.assertTrue('/api/admin/' in vdc.get('href'))
123141

124-
def test_0022_get_vdc_non_admin_href(self):
142+
def test_0023_get_vdc_non_admin_href(self):
125143
"""Test the method VDC.get_vdc().
126144
This test passes if the expected vdc non admin href.
127145
"""

0 commit comments

Comments
 (0)