pyvcloud.vcd.vdc module

class pyvcloud.vcd.vdc.VDC(client, name=None, href=None, resource=None)

Bases: object

add_access_settings(access_settings_list=None)

Add access settings to the vdc.

Parameters:access_settings_list (list) –

list of dictionaries, where each dictionary represents a single access setting. The dictionary structure is as follows,

  • type: (str): type of the subject. One of ‘org’ or ‘user’.
  • name: (str): name of the user or org.
  • access_level: (str): access_level of the particular subject.
    Allowed values are ‘ReadOnly’, ‘Change’ or ‘FullControl’.
Returns:an object containing EntityType.CONTROL_ACCESS_PARAMS XML data representing the updated Access Control List of the vdc.
Return type:lxml.objectify.ObjectifiedElement
change_disk_owner(user_href, name=None, disk_id=None)

Change the ownership of an independent disk to a given user.

Parameters:
  • user_href (str) – href of the new owner.
  • name (str) – name of the independent disk.
  • disk_id (str) – id of the disk (required if there are multiple disks with same name).
Raises:

EntityNotFoundException: if the named disk cannot be located.

create_directly_connected_vdc_network(network_name, parent_network_name, description=None, is_shared=None)

Create a new directly connected org vdc network in this vdc.

Parameters:
  • network_name (str) – name of the new network.
  • parent_network_name (str) – name of the external network that the new network will be directly connected to.
  • description (str) – description of the new network.
  • is_shared (bool) – True, if the network is shared with other org vdc(s) in the organization, else False.
Returns:

an object containing EntityType.ORG_VDC_NETWORK XML data which represents an org vdc network.

Return type:

lxml.objectify.ObjectifiedElement

create_disk(name, size, bus_type=None, bus_sub_type=None, description=None, storage_profile_name=None, iops=None)

Request the creation of an independent disk.

Parameters:
  • name (str) – name of the new disk.
  • size (int) – size of the new disk in bytes.
  • bus_type (str) – bus type of the new disk.
  • bus_sub_type (str) – bus subtype of the new disk.
  • description (str) – description of the new disk.
  • storage_profile_name (str) – name of an existing storage profile to be used by the new disk.
  • iops (int) – iops requirement of the new disk.
Returns:

an object containing EntityType.DISK XML data which represents the new disk being created along with the the asynchronous task that is creating the disk.

Return type:

lxml.objectify.ObjectifiedElement

create_isolated_vdc_network(network_name, gateway_ip, netmask, description=None, primary_dns_ip=None, secondary_dns_ip=None, dns_suffix=None, ip_range_start=None, ip_range_end=None, is_dhcp_enabled=None, default_lease_time=None, max_lease_time=None, dhcp_ip_range_start=None, dhcp_ip_range_end=None, is_shared=None)

Create a new isolated org vdc network in this vdc.

Parameters:
  • network_name (str) – name of the new network.
  • gateway_ip (str) – IP address of the gateway of the new network.
  • netmask (str) – network mask.
  • description (str) – description of the new network.
  • primary_dns_ip (str) – IP address of primary DNS server.
  • secondary_dns_ip (str) – IP address of secondary DNS Server.
  • dns_suffix (str) – DNS suffix.
  • ip_range_start (str) – start address of the IP ranges used for static pool allocation in the network.
  • ip_range_end (str) – end address of the IP ranges used for static pool allocation in the network.
  • is_dhcp_enabled (bool) – True, if DHCP service is enabled on the new network.
  • default_lease_time (int) – default lease in seconds for DHCP addresses.
  • max_lease_time (int) – max lease in seconds for DHCP addresses.
  • dhcp_ip_range_start (str) – start address of the IP range used for DHCP addresses.
  • dhcp_ip_range_end (str) – end address of the IP range used for DHCP addresses.
  • is_shared (bool) – True, if the network is shared with other vdc(s) in the organization, else False.
Returns:

an object containing EntityType.ORG_VDC_NETWORK XML data which represents an org vdc network.

Return type:

lxml.objectify.ObjectifiedElement

create_vapp(name, description=None, network=None, fence_mode='bridged', accept_all_eulas=None)

Create a new vApp in this vdc.

Parameters:
  • name (str) – name of the new vApp.
  • description (str) – description of the new vApp.
  • network (str) – name of the org vdc network that the vApp will connect to.
  • fence_mode (str) – network fence mode. Acceptable values are pyvcloud.vcd.client.FenceMode.BRIDGED.value and pyvcloud.vcd.client.FenceMode.NAT_ROUTED.value.
  • accept_all_eulas (bool) – True confirms acceptance of all EULAs for the vApp template.
Returns:

an object containing EntityType.VAPP XML data which represents the new created vApp in the org vdc.

Return type:

lxml.objectify.ObjectifiedElement

delete_direct_orgvdc_network(name, force=False)

Delete a directly connected org vdc network in the current vdc.

Parameters:
  • name (str) – name of the org vdc network we want to delete.
  • force (bool) – if True, will instruct vcd to force delete the network, ignoring whether it is connected to a vm or vapp network or not.
Returns:

an object containing EntityType.TASK XML data which represents the asynchronous task that is deleting the network.

Return type:

lxml.objectify.ObjectifiedElement

Raises:

EntityNotFoundException: if org vdc network with the given name is not found.

delete_disk(name=None, disk_id=None)

Delete an existing independent disk.

Parameters:
  • name (str) – name of the disk to delete.
  • disk_id (str) – id of the disk to delete.
Returns:

an object containing EntityType.TASK XML data which represents the asynchronous task that is deleting the disk.

Return type:

lxml.objectify.ObjectifiedElement

Raises:

EntityNotFoundException: if the named disk cannot be located.

delete_isolated_orgvdc_network(name, force=False)

Delete an isolated org vdc network in the current vdc.

Parameters:
  • name (str) – name of the org vdc network we want to delete.
  • force (bool) – if True, will instruct vcd to force delete the network, ignoring whether it is connected to a vm or vapp network or not.
Returns:

an object containing EntityType.TASK XML data which represents the asynchronous task that is deleting the network.

Return type:

lxml.objectify.ObjectifiedElement

Raises:

EntityNotFoundException: if org vdc network with the given name is not found.

delete_vapp(name, force=False)

Delete a vApp in the current org vdc.

Parameters:name (str) – name of the vApp to be deleted.
Raises:EntityNotFoundException: if the named vApp can not be found.
Raises:MultipleRecordsException: if more than one vApp with the provided name are found.
delete_vdc()

Delete the current org vdc.

Parameters:vdc_name (str) – name of the org vdc to delete.
Returns:an object containing EntityType.TASK XML data which represents the asynchronous task that is deleting the org vdc.
Return type:lxml.objectify.ObjectifiedElement
enable_vdc(enable=True)

Enable current vdc.

Parameters:enable (bool) – True, to enable the vdc. False, to disable the vdc.
Returns:an object containing EntityType.VDC XML data representing the updated org vdc.
Return type:lxml.objectify.ObjectifiedElement
get_access_settings()

Get the access settings of the vdc.

Returns:an object containing EntityType.CONTROL_ACCESS_PARAMS which represents the access control list of the vdc.
Return type:lxml.objectify.ObjectifiedElement
get_direct_orgvdc_network(name)

Retrieve a directly connected org vdc network in the current vdc.

Parameters:name (str) – name of the org vdc network we want to retrieve.
Returns:an object containing EntityType.ORG_VDC_NETWORK XML data which represents an org vdc network.
Return type:lxml.objectify.ObjectifiedElement
Raises:EntityNotFoundException: if org vdc network with the given name is not found.
get_disk(name=None, disk_id=None)

Return information for an independent disk.

Parameters:
  • name (str) – name of the disk.
  • disk_id (str) – id of the disk.
Returns:

an object containing EntityType.DISK XML data which represents the disk.

Return type:

lxml.objectify.ObjectifiedElement

Raises:

InvalidParameterException: if neither name nor the disk_id param is specified.

Raises:

EntityNotFoundException: if the named disk cannot be located.

get_disks()

Request a list of independent disks defined in the vdc.

Returns:a list of objects, where each object is an lxml.objectify.ObjectifiedElement containing EntityType.DISK XML element representing an independent disk. The object also contain information of all the vms to which the independent disk is attached to.
Return type:list
get_isolated_orgvdc_network(name)

Retrieve an isolated org vdc network in the current vdc.

Parameters:name (str) – name of the org vdc network we want to retrieve.
Returns:an object containing EntityType.ORG_VDC_NETWORK XML data which represents an org vdc network.
Return type:lxml.objectify.ObjectifiedElement
Raises:EntityNotFoundException: if org vdc network with the given name is not found.
get_orgvdc_network_admin_href_by_name(orgvdc_network_name)

Fetch the href of an org vdc network in the current vdc.

Returns:org vdc network admin href
Return type:str
Raises:EntityNotFoundException: if the named org vdc network cannot be located.
get_resource()

Fetches the XML representation of the org vdc from vCD.

Will serve cached response if possible.

Returns:object containing EntityType.VDC XML data representing the org vdc.
Return type:lxml.objectify.ObjectifiedElement
get_resource_href(name, entity_type=<EnumValue: EntityType.VAPP [value=application/vnd.vmware.vcloud.vApp+xml]>)

Fetches href of a vApp in the org vdc from vCD.

Parameters:
  • name (str) – name of the vApp.
  • entity_type (pyvcloud.vcd.client.EntityType) – type of entity we want to retrieve. Please note that this function is incapable of returning anything other than vApps at this point.
Returns:

href of the vApp identified by its name.

Return type:

str

Raises:

EntityNotFoundException: if the named vApp can not be found.

Raises:

MultipleRecordsException: if more than one vApp with the provided name are found.

get_storage_profile(profile_name)

Fetch a specific Storage Profile within an org vdc.

Parameters:profile_name (str) – name of the requested storage profile.
Returns:an object containing VdcStorageProfile XML element that represents the requested storage profile.
Return type:lxml.objectify.ObjectifiedElement
get_storage_profiles()

Fetch a list of the Storage Profiles defined in a vdc.

Returns:a list of lxml.objectify.ObjectifiedElement objects, where each object contains VdcStorageProfile XML element representing an existing storage profile.
Return type:list
get_vapp(name)

Fetches XML representation of a vApp in the org vdc from vCD.

Parameters:name (str) – name of the vApp.
Returns:object containing EntityType.VAPP XML data representing the vApp.
Return type:lxml.objectify.ObjectifiedElement
Raises:EntityNotFoundException: if the named vApp can not be found.
Raises:MultipleRecordsException: if more than one vApp with the provided name are found.
instantiate_vapp(name, catalog, template, description=None, network=None, fence_mode='bridged', ip_allocation_mode='dhcp', deploy=True, power_on=True, accept_all_eulas=False, memory=None, cpu=None, disk_size=None, password=None, cust_script=None, vm_name=None, hostname=None, ip_address=None, storage_profile=None, network_adapter_type=None)

Instantiate a vApp from a vApp template in a catalog.

If customization parameters are provided, it will customize the vm and guest OS, taking some assumptions.

A general assumption is made by this method that there is only one vm in the vApp. And the vm has only one NIC.

Parameters:
  • name (str) – name of the new vApp.
  • catalog (str) – name of the catalog.
  • template (str) – name of the vApp template.
  • description (str) – description of the new vApp.
  • network (str) – name of a vdc network. When provided, connects the vm to the network.
  • fence_mode (str) – fence mode. Possible values are pyvcloud.vcd.client.FenceMode.BRIDGED.value and pyvcloud.vcd.client.FenceMode.NAT_ROUTED.value.
  • ip_allocation_mode (str) – ip allocation mode. Acceptable values are pool, dhcp and manual.
  • deploy (bool) – if True deploy the vApp after instantiation.
  • power_on (bool) – if True, power on the vApp after instantiation.
  • accept_all_eulas (bool) – True, confirms acceptance of all EULAs in a vApp template.
  • memory (int) – size of memory of the first vm.
  • cpu (int) – number of cpus in the first vm.
  • disk_size (int) – size of the first disk of the first vm.
  • password (str) – admin password of the guest os on the first vm.
  • cust_script (str) – guest customization to run on the vm.
  • vm_name (str) – when provided, sets the name of the vm.
  • ip_address (str) – when provided, sets the ip_address of the vm.
  • hostname (str) – when provided, sets the hostname of the guest OS.
  • storage_profile (str) –
  • network_adapter_type (str) – One of the values in pyvcloud.vcd.client.NetworkAdapterType.
Returns:

an object containing EntityType.VAPP XML data which represents the new vApp.

Return type:

lxml.objectify.ObjectifiedElement

list_edge_gateways()

Fetch a list of edge gateways defined in a vdc.

Returns:a list of dictionaries, where each dictionary contains the name and href of an edge gateway.
Return type:list
list_orgvdc_direct_networks()

Fetch all directly connected org vdc networks in the current vdc.

Returns:a list of lxml.objectify.ObjectifiedElement objects, where each object contains EntityType.ORG_VDC_NETWORK XML data which represents an org vdc network.
Return type:list
list_orgvdc_isolated_networks()

Fetch all isolated org vdc networks in the current vdc.

Returns:a list of lxml.objectify.ObjectifiedElement objects, where each object contains EntityType.ORG_VDC_NETWORK XML data which represents an org vdc network.
Return type:list
list_orgvdc_network_records()

Fetch all org vdc network’s record in the current vdc.

Returns:org vdc network’s name (as key) and admin href (as value)
Return type:dict
list_orgvdc_network_resources(name=None, type=None)

Fetch org vdc networks filtered by name and type.

Parameters:
  • name (str) – name of the network we want to retrieve.
  • type (str) – type of network we want to retrieve, valid values are ‘bridged’ and ‘isolated’.
Returns:

a list of lxml.objectify.ObjectifiedElement objects, where each object contains EntityType.ORG_VDC_NETWORK XML data which represents an org vdc network.

Return type:

list

list_resources(entity_type=None)

Fetch information about all resources in the current org vdc.

Parameters:entity_type (str) – filter to restrict type of resource we want to fetch. EntityType.VAPP.value and EntityType.VAPP_TEMPLATE.value both are acceptable values.
Returns:a list of dictionaries, where each dictionary represents a resource e.g. vApp templates, vApps. And each dictionary has ‘name’ and ‘type’ of the resource.
Return type:dict
reload()

Reloads the resource representation of the org vdc.

This method should be called in between two method invocations on the VDC object, if the former call changes the representation of the org vdc in vCD.

remove_access_settings(access_settings_list=None, remove_all=False)

Remove access settings from the vdc.

Parameters:
  • access_settings_list (list) –

    list of dictionaries, where each dictionary represents a single access setting. The dictionary structure is as follows,

    • type: (str): type of the subject. One of ‘org’ or ‘user’.
    • name: (str): name of the user or org.
  • remove_all (bool) – True, if the entire Access Control List of the vdc should be removed, else False.
Returns:

an object containing EntityType.CONTROL_ACCESS_PARAMS XML data representing the updated access control setting of the vdc.

Return type:

lxml.objectify.ObjectifiedElement`

share_with_org_members(everyone_access_level='ReadOnly')

Share the vdc to all members of the organization.

Parameters:everyone_access_level (str) – level of access granted while sharing the vdc with everyone. ‘ReadOnly’ is the only allowed value.
Returns:an object containing EntityType.CONTROL_ACCESS_PARAMS XML data representing the updated access control setting of the vdc.
Return type:lxml.objectify.ObjectifiedElement
unshare_from_org_members()

Unshare the vdc from all members of current organization.

Should give individual access to at least one user before unsharing access to the whole org.

Returns:an object containing EntityType.CONTROL_ACCESS_PARAMS XML data representing the updated access control setting of the vdc.
Return type:lxml.objectify.ObjectifiedElement
update_disk(name=None, disk_id=None, new_name=None, new_size=None, new_description=None, new_storage_profile_name=None, new_iops=None)

Update an existing independent disk.

Parameters:
  • name (str) – name of the existing disk.
  • disk_id (str) – id of the existing disk.
  • new_name (str) – new name of the disk.
  • new_size (str) – new size of the disk in bytes.
  • new_description (str) – new description of the disk.
  • new_storage_profile_name (str) – new storage profile that the disk will be moved to.
  • new_iops (int) – new iops requirement of the disk.
Returns:

an object containing EntityType.TASK XML data which represents the asynchronous task that is updating the disk.

Return type:

lxml.objectify.ObjectifiedElement

Raises:

EntityNotFoundException: if the named disk cannot be located.