diff --git a/pyvcloud/vcd/org.py b/pyvcloud/vcd/org.py index 0ffa5ccd1..b6702d36e 100644 --- a/pyvcloud/vcd/org.py +++ b/pyvcloud/vcd/org.py @@ -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. diff --git a/system_tests/vdc_tests.py b/system_tests/vdc_tests.py index 269f36c02..bddaaab9c 100644 --- a/system_tests/vdc_tests.py +++ b/system_tests/vdc_tests.py @@ -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. @@ -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. """ @@ -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. """