pyvcloud.vcd.platform module

class pyvcloud.vcd.platform.Platform(client)

Bases: object

Helper class to interact with vSphere Platform resources.

Attributes:
  • client (pyvcloud.vcd.client): Low level client to connect to vCD.
  • extension (pyvcloud.vcd.Extension, optional): It holds an
    Extension object to interact with vCD admin extension.
attach_resource_pools_to_provider_vdc(pvdc_name, resource_pool_names)

Attach Resource Pools to a Provider Virtual Datacenter.

This function attaches one or more resource pools (RPs) to a Provider Virtual Datacenter (PVDC).

Caveat: The current implementation of this function takes a list of RP “basenames” as input. A basename is the last element of a full pathname. For example, given a pathname /a/b/c, the basename of that pathname is “c”. Since RP names are only required to have unique pathnames but not unique basenames, this function may not work correctly if there are non-unique RP basenames. Therefore, in order to use this function, all RP basenames must be unique. It is therefore up to the user of this function to be aware of this limitation and name their RPs appropriately. This limitation will be fixed in a future version of this function.

Parameters:
  • pvdc_name (str) – name of the Provider Virtual Datacenter.
  • resource_pool_names (list) – list or resource pool names.
Returns:

an object containing EntityType.TASK XML data which represents the asynchronous task that is adding Resource Pools to the PVDC.

Return type:

lxml.objectify.ObjectifiedElement

attach_vcenter(vc_server_name, vc_server_host, vc_admin_user, vc_admin_pwd, is_enabled, vc_root_folder=None, nsx_server_name=None, nsx_host=None, nsx_admin_user=None, nsx_admin_pwd=None)

Register (attach) a VirtualCenter server (also known as VimServer).

Parameters:
  • vc_server_name (str) – vc server name (virtual center name).
  • vc_server_host (str) – FQDN or IP address of vc host.
  • vc_admin_user (str) – vc admin user.
  • vc_admin_pwd (str) – vc admin password.
  • is_enabled (str) – true if VC is to be enabled.
  • vc_root_folder (str) – vc root folder.
  • nsx_server_name (str) – NSX server name.
  • nsx_host (str) – FQDN or IP address of NSX host.
  • nsx_admin_user (str) – NSX admin user.
  • nsx_admin_pwd (str) – NSX admin password.
Returns:

an object containing REGISTER_VC_SERVER_PARAMS XML data that represents the newly registered (attached) VimServer.

Return type:

lxml.objectify.ObjectifiedElement

create_provider_vdc(vim_server_name, resource_pool_names, storage_profiles, pvdc_name, is_enabled=None, description=None, highest_hw_vers=None, vxlan_network_pool=None, nsxt_manager_name=None)

Create a Provider Virtual Datacenter.

Parameters:
  • vim_server_name (str) – vim_server_name (VC name).
  • resource_pool_names (list) – list of resource_pool_names.
  • storage_profiles (list) – (list): list of storageProfile namespace.
  • pvdc_name (str) – name of PVDC to be created.
  • is_enabled (bool) – flag, True to enable and False to disable.
  • description (str) – description of pvdc.
  • highest_hw_vers (str) – highest supported hw version number.
  • vxlan_network_pool (str) – name of vxlan_network_pool.
  • nsxt_manager_name (str) – name of nsx-t manager.
Returns:

an object containing vmext:VMWProviderVdc XML element that represents the new provider VDC.

Return type:

lxml.objectify.ObjectifiedElement

detach_resource_pools_from_provider_vdc(pvdc_name, resource_pool_names)

Disable & Detach Resource Pools from a Provider Virtual Datacenter.

This function deletes resource pools (RPs) from a Provider Virtual Datacenter (PVDC). In order to do this, the input “user-friendly” RP names must be translated into RP hrefs. This is a multi-step process. 1) create a dictionary that maps RP names associated w/ this PVDC’s backing VC to morefs. 2) create a list of morefs_to_delete, using the dictionary created in step 1 – filtered by the input set of RP names. 3) create a dictionary that maps RP morefs associated w/ this PVDC to RP hrefs. 4) Use the list of morefs_to_delete (created in step 2) to filter the list of RP hrefs created as a dictionary in step 3 to create the final payload.

Note that in order to delete a RP, it must first be disabled. This is done for each RP to be deleted if the disable link is present (which indicates that the RP is enabled).

Caveat: The current implementation of this function takes a list of RP “basenames” as input. A basename is the last element of a full pathname. For example, given a pathname /a/b/c, the basename of that pathname is “c”. Since RP names are only required to have unique pathnames but not unique basenames, this function may not work correctly if there are non-unique RP basenames. Therefore, in order to use this function, all RP basenames must be unique. It is therefore up to the user of this function to be aware of this limitation and name their RPs appropriately. This limitation will be fixed in a future version of this function.

Parameters:
  • pvdc_name (str) – name of the Provider Virtual Datacenter.
  • resource_pool_names (list) – list or resource pool names.
Returns:

an object containing EntityType.TASK XML data which represents the async task that is deleting Resource Pools from the PVDC.

Return type:

lxml.objectify.ObjectifiedElement

Raises:

EntityNotFoundException: if any resource_pool_name cannot be found.

Raises:

ValidationError: if primary resource pool is input for deletion.

detach_vcenter(vc_name)

Detach (unregister) a Virtual Center (VC) server.

Parameters:vc_name (str) – name of VC server.
Returns:an object containing XML data of the VC server specifically, EntityType.VIRTUAL_CENTER
Return type:lxml.objectify.ObjectifiedElement
enable_disable_vcenter(vc_name, enable_flag)

Enable or disable a Virtual Center (VC) server.

Parameters:
  • vc_name (str) – name of VC server.
  • enable_flag (boolean) – True means enable, False means disable.
Returns:

an object containing EntityType.TASK XML data which represents the asynchronous task that is enabling or disabling the VC.

rtype: lxml.objectify.ObjectifiedElement’

get_external_network(name)

Fetch an external network resource identified by its name.

Parameters:name (str) – name of the external network to be retrieved.
Returns:an object containing EntityType.EXTERNAL_NETWORK XML data which represents an external network.
Return type:lxml.objectify.ObjectifiedElement
Raises:EntityNotFoundException: If the named external network cannot be located.
get_ref_by_name(resource_type, resource_name)

Fetch a reference to a resource by its name.

Parameters:
Returns:

an object containing sub-type of QueryResultFormat.REFERENCES XML data representing a reference to the resource.

Return type:

lxml.objectify.ObjectifiedElement

Raises:

EntityNotFoundException: if the named resource cannot be found.

get_resource_pool_morefs(vc_href, resource_pool_names)

Fetch list of morefs for a given list of resource_pool_names.

Parameters:
  • vc_href (str) – vim_server href.
  • resource_pool_names (list) – resource pool names as a list of strings.
Returns:

morefs of resource pools.

Return type:

list

Raises:

EntityNotFoundException: if any resource_pool_name cannot be found.

get_vcenter(name)

Fetch a vCenter attached to the system by name.

Parameters:name (str) – name of vCenter.
Returns:an object containing EntityType.VIRTUAL_CENTER XML data which represents a vCenter server.
Return type:lxml.objectify.ObjectifiedElement
Raises:EntityNotFoundException: if the named vCenter cannot be located.
get_vxlan_network_pool(vxlan_network_pool_name)

[Deprecated] Fetch a vxlan_network_pool by its name.

Parameters:vxlan_network_pool_name (str) – name of the vxlan_network_pool.
Returns:an object containing NetworkPoolRecord XML element which represents a vxlan_network_pool.
Return type:lxml.objectify.ObjectifiedElement
Raises:EntityNotFoundException: If the named vxlan_network_pool cannot be found.
list_external_networks()

List all external networks available in the system.

Returns:list of lxml.objectify.ObjectifiedElement objects which contains vmext:ExternalNetworkReference XML element representing the external network references.
Return type:list
list_nsxt_managers()

Return list of all registered NSX-T managers.

Returns:NsxTManagerRecords.
Return type:generator object
list_vcenters()

List vCenter servers attached to the system.

Returns:list of object containing vmext:VimServerReference XML element that represent vCenter references.
Return type:list
pvdc_migrate_vms(pvdc_name, vms_to_migrate, src_resource_pool, target_resource_pool=None)

Migrate VMs to (an optionally) specified ResourcePool.

Parameters:
  • pvdc_name (str) – name of the Provider Virtual Datacenter.
  • vms_to_migrate (list(str)) – list of VMs to migrate.
  • src_resource_pool (str) – source resource pool name.
  • target_resource_pool (str) – target resource pool name (optional).

This function migrates the specified VMs to (an optionally) specified target resource pool. If no target resource pool is specified, the system will automatically choose a target resource pool and migrate the VMs to it. If any of the vms_to_migrate are not found on the source resource pool, an exception will be thrown.

Returns:an object containing EntityType.TASK XML data which represents the async task that is migrating VMs.
Return type:lxml.objectify.ObjectifiedElement
Raises:EntityNotFoundException: if source or target resource pool cannot be found, or if any of the vms_to_migrate are not found on the source resource pool.
register_nsxt_manager(nsxt_manager_name, nsxt_manager_url, nsxt_manager_username, nsxt_manager_password, nsxt_manager_description=None)

Register a NSX-T manager.

Parameters:
  • nsxt_manager_name (str) – name of NSX-T manager.
  • nsxt_manager_url (str) – URL of NSX-T manager server.
  • nsxt_manager_username (str) – username of NSX-T manager admin.
  • nsxt_manager_password (str) – password of NSX-T manager admin.
  • nsxt_manager_description (str) – description of NSX-T manager.
Returns:

an object containing XML data the newly registered NSX-T manager.

Return type:

lxml.objectify.ObjectifiedElement

unregister_nsxt_manager(nsxt_manager_name)

Un-register an NSX-T Manager.

Parameters:nsxt_manager_name (str) – name of the NSX-T manager.