def info_pvdc(ctx, name): try: restore_session(ctx) client = ctx.obj['client'] sys_admin_resource = client.get_admin() system = System(client, admin_resource=sys_admin_resource) pvdc_reference = system.get_provider_vdc(name) pvdc = PVDC(client, href=pvdc_reference.get('href')) refs = pvdc.get_vdc_references() md = pvdc.get_metadata() result = pvdc_to_dict(pvdc.get_resource(), refs, md) stdout(result, ctx) except Exception as e: stderr(e, ctx)
def create_org_vdc(self, vdc_name, provider_vdc_name, description='', allocation_model='AllocationVApp', cpu_units='MHz', cpu_allocated=0, cpu_limit=0, mem_units='MB', mem_allocated=0, mem_limit=0, nic_quota=0, network_quota=0, vm_quota=0, storage_profiles=[], resource_guaranteed_memory=None, resource_guaranteed_cpu=None, vcpu_in_mhz=None, is_thin_provision=None, network_pool_name=None, uses_fast_provisioning=None, over_commit_allowed=None, vm_discovery_enabled=None, is_enabled=True): """Create Organization VDC in the current Org. :param vdc_name (str): The name of the new org vdc. :param provider_vdc_name (str): The name of an existing provider vdc. :param description (str): The description of the new org vdc. :param allocation_model (str): The allocation model used by this vDC. One of AllocationVApp, AllocationPool or ReservationPool. :param cpu_units (str): The cpu units compute capacity allocated to this vDC. One of MHz or GHz :param cpu_allocated (int): Capacity that is committed to be available. :param cpu_limit (int): Capacity limit relative to the value specified for Allocation. :param mem_units (str): The memory units compute capacity allocated to this vDC. One of MB or GB. :param mem_allocated (int): Memory capacity that is committed to be available. :param mem_limit (int): Memory capacity limit relative to the value specified for Allocation. :param nic_quota (int): Maximum number of virtual NICs allowed in this vDC. Defaults to 0, which specifies an unlimited number. :param network_quota (int): Maximum number of network objects that can be deployed in this vDC. Defaults to 0, which means no networks can be deployed. :param vm_quota (int): The maximum number of VMs that can be created in this vDC. Defaults to 0, which specifies an unlimited number. :param storage_profiles: List of provider vDC storage profiles to add to this vDC. Each item is a dictionary that should include the following elements: name: (string) name of the PVDC storage profile. enabled: (bool) True if the storage profile is enabled for this vDC. units: (string) Units used to define limit. One of MB or GB. limit: (int) Max number of units allocated for this storage profile. default: (bool) True if this is default storage profile for this vDC. :param resource_guaranteed_memory (float): Percentage of allocated CPU resources guaranteed to vApps deployed in this vDC. Value defaults to 1.0 if the element is empty. :param resource_guaranteed_cpu (float): Percentage of allocated memory resources guaranteed to vApps deployed in this vDC. Value defaults to 1.0 if the element is empty. :param vcpu_in_mhz (int): Specifies the clock frequency, in Megahertz, for any virtual CPU that is allocated to a VM. :param is_thin_provision (bool): Boolean to request thin provisioning. :param network_pool_name (str): Reference to a network pool in the Provider vDC. :param uses_fast_provisioning (bool): Boolean to request fast provisioning. :param over_commit_allowed (bool): Set to false to disallow creation of the VDC if the AllocationModel is AllocationPool or ReservationPool and the ComputeCapacity you specified is greater than what the backing Provider VDC can supply. Defaults to true if empty or missing. :param vm_discovery_enabled (bool): True if discovery of vCenter VMs is enabled for resource pools backing this vDC. :param is_enabled (bool): True if this vDC is enabled for use by the organization users. :return: A :class:`lxml.objectify.StringElement` object describing the new VDC. """ if self.resource is None: self.resource = self.client.get_resource(self.href) sys_admin_resource = self.client.get_admin() system = System(self.client, admin_resource=sys_admin_resource) pvdc = system.get_provider_vdc(provider_vdc_name) resource_admin = self.client.get_resource(self.href_admin) params = E.CreateVdcParams(E.Description(description), E.AllocationModel(allocation_model), E.ComputeCapacity( E.Cpu(E.Units(cpu_units), E.Allocated(cpu_allocated), E.Limit(cpu_limit)), E.Memory(E.Units(mem_units), E.Allocated(mem_allocated), E.Limit(mem_limit))), E.NicQuota(nic_quota), E.NetworkQuota(network_quota), E.VmQuota(vm_quota), E.IsEnabled(is_enabled), name=vdc_name) for sp in storage_profiles: pvdc_sp = system.get_provider_vdc_storage_profile(sp['name']) params.append( E.VdcStorageProfile( E.Enabled(sp['enabled']), E.Units(sp['units']), E.Limit(sp['limit']), E.Default(sp['default']), E.ProviderVdcStorageProfile(href=pvdc_sp.get('href')))) if resource_guaranteed_memory is not None: params.append( E.ResourceGuaranteedMemory(resource_guaranteed_memory)) if resource_guaranteed_cpu is not None: params.append(E.ResourceGuaranteedCpu(resource_guaranteed_cpu)) if vcpu_in_mhz is not None: params.append(E.VCpuInMhz(vcpu_in_mhz)) if is_thin_provision is not None: params.append(E.IsThinProvision(is_thin_provision)) if network_pool_name is not None: npr = system.get_network_pool_reference(network_pool_name) href = npr.get('href') params.append( E.NetworkPoolReference(href=href, id=href.split('/')[-1], type=npr.get('type'), name=npr.get('name'))) params.append(pvdc) if uses_fast_provisioning is not None: params.append(E.UsesFastProvisioning(uses_fast_provisioning)) if over_commit_allowed is not None: params.append(E.OverCommitAllowed(over_commit_allowed)) if vm_discovery_enabled is not None: params.append(E.VmDiscoveryEnabled(vm_discovery_enabled)) return self.client.post_linked_resource(resource_admin, RelationType.ADD, EntityType.VDCS_PARAMS.value, params)
def create_org_vdc(self, vdc_name, provider_vdc_name, description='', allocation_model='AllocationVApp', cpu_units='MHz', cpu_allocated=0, cpu_limit=0, mem_units='MB', mem_allocated=0, mem_limit=0, nic_quota=0, network_quota=0, vm_quota=0, storage_profiles=[], resource_guaranteed_memory=None, resource_guaranteed_cpu=None, vcpu_in_mhz=None, is_thin_provision=None, network_pool_name=None, uses_fast_provisioning=None, over_commit_allowed=None, vm_discovery_enabled=None, is_enabled=True): """Create Organization VDC in the current Org. :param vdc_name (str): The name of the new org vdc. :param provider_vdc_name (str): The name of an existing provider vdc. :param description (str): The description of the new org vdc. :param allocation_model (str): The allocation model used by this vDC. One of AllocationVApp, AllocationPool or ReservationPool. :param cpu_units (str): The cpu units compute capacity allocated to this vDC. One of MHz or GHz :param cpu_allocated (int): Capacity that is committed to be available. :param cpu_limit (int): Capacity limit relative to the value specified for Allocation. :param mem_units (str): The memory units compute capacity allocated to this vDC. One of MB or GB. :param mem_allocated (int): Memory capacity that is committed to be available. :param mem_limit (int): Memory capacity limit relative to the value specified for Allocation. :param nic_quota (int): Maximum number of virtual NICs allowed in this vDC. Defaults to 0, which specifies an unlimited number. :param network_quota (int): Maximum number of network objects that can be deployed in this vDC. Defaults to 0, which means no networks can be deployed. :param vm_quota (int): The maximum number of VMs that can be created in this vDC. Defaults to 0, which specifies an unlimited number. :param storage_profiles: List of provider vDC storage profiles to add to this vDC. Each item is a dictionary that should include the following elements: name: (string) name of the PVDC storage profile. enabled: (bool) True if the storage profile is enabled for this vDC. units: (string) Units used to define limit. One of MB or GB. limit: (int) Max number of units allocated for this storage profile. default: (bool) True if this is default storage profile for this vDC. :param resource_guaranteed_memory (float): Percentage of allocated CPU resources guaranteed to vApps deployed in this vDC. Value defaults to 1.0 if the element is empty. :param resource_guaranteed_cpu (float): Percentage of allocated memory resources guaranteed to vApps deployed in this vDC. Value defaults to 1.0 if the element is empty. :param vcpu_in_mhz (int): Specifies the clock frequency, in Megahertz, for any virtual CPU that is allocated to a VM. :param is_thin_provision (bool): Boolean to request thin provisioning. :param network_pool_name (str): Reference to a network pool in the Provider vDC. :param uses_fast_provisioning (bool): Boolean to request fast provisioning. :param over_commit_allowed (bool): Set to false to disallow creation of the VDC if the AllocationModel is AllocationPool or ReservationPool and the ComputeCapacity you specified is greater than what the backing Provider VDC can supply. Defaults to true if empty or missing. :param vm_discovery_enabled (bool): True if discovery of vCenter VMs is enabled for resource pools backing this vDC. :param is_enabled (bool): True if this vDC is enabled for use by the organization users. :return: A :class:`lxml.objectify.StringElement` object describing the new VDC. """ if self.resource is None: self.resource = self.client.get_resource(self.href) sys_admin_resource = self.client.get_admin() system = System(self.client, admin_resource=sys_admin_resource) pvdc = system.get_provider_vdc(provider_vdc_name) resource_admin = self.client.get_resource(self.href_admin) params = E.CreateVdcParams( E.Description(description), E.AllocationModel(allocation_model), E.ComputeCapacity( E.Cpu( E.Units(cpu_units), E.Allocated(cpu_allocated), E.Limit(cpu_limit)), E.Memory( E.Units(mem_units), E.Allocated(mem_allocated), E.Limit(mem_limit))), E.NicQuota(nic_quota), E.NetworkQuota(network_quota), E.VmQuota(vm_quota), E.IsEnabled(is_enabled), name=vdc_name) for sp in storage_profiles: pvdc_sp = system.get_provider_vdc_storage_profile(sp['name']) params.append( E.VdcStorageProfile( E.Enabled(sp['enabled']), E.Units(sp['units']), E.Limit(sp['limit']), E.Default(sp['default']), E.ProviderVdcStorageProfile(href=pvdc_sp.get('href')))) if resource_guaranteed_memory is not None: params.append( E.ResourceGuaranteedMemory(resource_guaranteed_memory)) if resource_guaranteed_cpu is not None: params.append(E.ResourceGuaranteedCpu(resource_guaranteed_cpu)) if vcpu_in_mhz is not None: params.append(E.VCpuInMhz(vcpu_in_mhz)) if is_thin_provision is not None: params.append(E.IsThinProvision(is_thin_provision)) if network_pool_name is not None: npr = system.get_network_pool_reference(network_pool_name) href = npr.get('href') params.append( E.NetworkPoolReference( href=href, id=href.split('/')[-1], type=npr.get('type'), name=npr.get('name'))) params.append(pvdc) if uses_fast_provisioning is not None: params.append(E.UsesFastProvisioning(uses_fast_provisioning)) if over_commit_allowed is not None: params.append(E.OverCommitAllowed(over_commit_allowed)) if vm_discovery_enabled is not None: params.append(E.VmDiscoveryEnabled(vm_discovery_enabled)) return self.client.post_linked_resource( resource_admin, RelationType.ADD, EntityType.VDCS_PARAMS.value, params)