libcloud.compute.drivers.vcloud module

VMware vCloud driver.

class libcloud.compute.drivers.vcloud.Capacity(limit, used, units)[source]

Bases: object

Represents CPU, Memory or Storage capacity of vDC.

class libcloud.compute.drivers.vcloud.ControlAccess(node, everyone_access_level, subjects=None)[source]

Bases: object

Represents control access settings of a node

class AccessLevel[source]

Bases: object

CHANGE = 'Change'
FULL_CONTROL = 'FullControl'
READ_ONLY = 'ReadOnly'
libcloud.compute.drivers.vcloud.DEFAULT_API_VERSION = '0.8'

Valid vCloud API v1.5 input values.

class libcloud.compute.drivers.vcloud.HostingComConnection(user_id, key, secure=True, host=None, port=None, url=None, timeout=None, proxy_url=None, backoff=None, retry_delay=None)[source]

Bases: VCloudConnection

vCloud connection subclass for Hosting.com

Initialize user_id and key; set secure to an int based on passed value.

host: str = 'vcloud.safesecureweb.com'
class libcloud.compute.drivers.vcloud.HostingComDriver(key, secret=None, secure=True, host=None, port=None, api_version='0.8', **kwargs)[source]

Bases: VCloudNodeDriver

vCloud node driver for Hosting.com

Parameters:
  • key (str) – API key or username to be used (required)

  • secret (str) – Secret password to be used (required)

  • secure (bool) – Whether to use HTTPS or HTTP. Note: Some providers only support HTTPS, and it is on by default.

  • host (str) – Override hostname used for connections.

  • port (int) – Override port used for connections.

  • api_version (str) – Optional API version. Only used by drivers which support multiple API versions.

  • region (str) – Optional driver region. Only used by drivers which support multiple regions.

Return type:

None

connectionCls

alias of HostingComConnection

class libcloud.compute.drivers.vcloud.InstantiateVAppXML(name, template, net_href, cpus, memory, password=None, row=None, group=None)[source]

Bases: object

tostring()[source]
class libcloud.compute.drivers.vcloud.Instantiate_1_5_VAppXML(name, template, network, vm_network=None, vm_fence=None, description=None)[source]

Bases: object

tostring()[source]
class libcloud.compute.drivers.vcloud.Lease(lease_id, deployment_lease=None, storage_lease=None, deployment_lease_expiration=None, storage_lease_expiration=None)[source]

Bases: object

Lease information for vApps.

More info at: ‘https://www.vmware.com/support/vcd/doc/

rest-api-doc-1.5-html/types/LeaseSettingsSectionType.html’

Parameters:
  • lease_id (str) – ID (link) to the lease settings section of a vApp.

  • deployment_lease (int or None) – Deployment lease time in seconds

  • storage_lease (int or None) – Storage lease time in seconds

  • deployment_lease_expiration (datetime.datetime or None) – Deployment lease expiration time

  • storage_lease_expiration (datetime.datetime or None) – Storage lease expiration time

get_deployment_time()[source]

Gets the date and time a vApp was deployed. Time is inferred from the deployment lease and expiration or the storage lease and expiration.

Returns:

Date and time the vApp was deployed or None if unable to calculate

Return type:

datetime.datetime or None

classmethod to_lease(lease_element)[source]

Convert lease settings element to lease instance.

Parameters:

lease_element (ET.Element) – “LeaseSettingsSection” XML element

Returns:

Lease instance

Return type:

Lease

class libcloud.compute.drivers.vcloud.Subject(type, name, access_level, id=None)[source]

Bases: object

User or group subject

class libcloud.compute.drivers.vcloud.TerremarkConnection(user_id, key, secure=True, host=None, port=None, url=None, timeout=None, proxy_url=None, backoff=None, retry_delay=None)[source]

Bases: VCloudConnection

vCloud connection subclass for Terremark

Initialize user_id and key; set secure to an int based on passed value.

host: str = 'services.vcloudexpress.terremark.com'
class libcloud.compute.drivers.vcloud.TerremarkDriver(key, secret=None, secure=True, host=None, port=None, api_version='0.8', **kwargs)[source]

Bases: VCloudNodeDriver

vCloud node driver for Terremark

Parameters:
  • key (str) – API key or username to be used (required)

  • secret (str) – Secret password to be used (required)

  • secure (bool) – Whether to use HTTPS or HTTP. Note: Some providers only support HTTPS, and it is on by default.

  • host (str) – Override hostname used for connections.

  • port (int) – Override port used for connections.

  • api_version (str) – Optional API version. Only used by drivers which support multiple API versions.

  • region (str) – Optional driver region. Only used by drivers which support multiple regions.

Return type:

None

connectionCls

alias of TerremarkConnection

list_locations()[source]

List data centers for a provider

Returns:

list of node location objects

Return type:

list of NodeLocation

class libcloud.compute.drivers.vcloud.VCloudConnection(user_id, key, secure=True, host=None, port=None, url=None, timeout=None, proxy_url=None, backoff=None, retry_delay=None)[source]

Bases: ConnectionUserAndKey

Connection class for the vCloud driver

Initialize user_id and key; set secure to an int based on passed value.

add_default_headers(headers)[source]

Adds default headers (such as Authorization, X-Foo-Bar) to the passed headers

Should return a dictionary.

check_org()[source]
host: str = None
request(*args, **kwargs)[source]

Request a given action.

Basically a wrapper around the connection object’s request that does some helpful pre-processing.

Parameters:
  • action (str) – A path. This can include arguments. If included, any extra parameters are appended to the existing ones.

  • params (dict) – Optional mapping of additional parameters to send. If None, leave as an empty dict.

  • data (unicode) – A body of data to send with the request.

  • headers (dict) – Extra headers to add to the request None, leave as an empty dict.

  • method (str) – An HTTP method such as “GET” or “POST”.

  • raw (bool) – True to perform a “raw” request aka only send the headers and use the rawResponseCls class. This is used with storage API when uploading a file.

  • stream (bool) – True to return an iterator in Response.iter_content and allow streaming of the response data (for downloading large files)

  • retry_failed – True if failed requests should be retried. This argument can override module level constant and environment variable value on per-request basis.

Returns:

An Response instance.

Return type:

Response instance

responseCls

alias of VCloudResponse

token = None
class libcloud.compute.drivers.vcloud.VCloudNodeDriver(key, secret=None, secure=True, host=None, port=None, api_version='0.8', **kwargs)[source]

Bases: NodeDriver

vCloud node driver

Parameters:
  • key (str) – API key or username to be used (required)

  • secret (str) – Secret password to be used (required)

  • secure (bool) – Whether to use HTTPS or HTTP. Note: Some providers only support HTTPS, and it is on by default.

  • host (str) – Override hostname used for connections.

  • port (int) – Override port used for connections.

  • api_version (str) – Optional API version. Only used by drivers which support multiple API versions.

  • region (str) – Optional driver region. Only used by drivers which support multiple regions.

Return type:

None

NODE_STATE_MAP: Dict[str, NodeState] = {'0': NodeState.PENDING, '1': NodeState.PENDING, '2': NodeState.PENDING, '3': NodeState.PENDING, '4': NodeState.RUNNING}
connectionCls

alias of VCloudConnection

create_node(name, size, image, auth=None, ex_network=None, ex_vdc=None, ex_cpus=1, ex_row=None, ex_group=None)[source]

Creates and returns node.

Parameters:
  • ex_network (str) – link to a “Network” e.g., https://services.vcloudexpress...

  • ex_vdc (str) – Name of organisation’s virtual data center where vApp VMs will be deployed.

  • ex_cpus (int) – number of virtual cpus (limit depends on provider)

destroy_node(node)[source]

Destroy a node.

Depending upon the provider, this may destroy all data associated with the node, including backups.

Parameters:

node (Node) – The node to be destroyed

Returns:

True if the destroy was successful, False otherwise.

Return type:

bool

ex_list_nodes(vdcs=None)[source]

List all nodes across all vDCs. Using ‘vdcs’ you can specify which vDCs should be queried.

Parameters:

vdcs (Vdc) – None, vDC or a list of vDCs to query. If None all vDCs will be queried.

Return type:

list of Node

features: Dict[str, List[str]] = {'create_node': ['password']}
List of available features for a driver.
list_images(location=None)[source]

List images on a provider.

Parameters:

location (NodeLocation) – The location at which to list images.

Returns:

list of node image objects.

Return type:

list of NodeImage

list_nodes()[source]

List all nodes.

Returns:

list of node objects

Return type:

list of Node

list_sizes(location=None)[source]

List sizes on a provider

Parameters:

location (NodeLocation) – The location at which to list sizes

Returns:

list of node size objects

Return type:

list of NodeSize

name: str = 'vCloud'
property networks
org = None
reboot_node(node)[source]

Reboot a node.

Parameters:

node (Node) – The node to be rebooted

Returns:

True if the reboot was successful, otherwise False

Return type:

bool

type: Provider | str = 'vcloud'
property vdcs

vCloud virtual data centers (vDCs).

Returns:

list of vDC objects

Return type:

list of Vdc

website: str = 'http://www.vmware.com/products/vcloud/'
class libcloud.compute.drivers.vcloud.VCloudResponse(response, connection)[source]

Bases: XmlResponse

Parameters:
  • response (httplib.HTTPResponse) – HTTP response object. (optional)

  • connection (Connection) – Parent connection object.

success()[source]

Determine if our request was successful.

The meaning of this can be arbitrary; did we receive OK status? Did the node get created? Were we authenticated?

Return type:

bool

Returns:

True or False

class libcloud.compute.drivers.vcloud.VCloud_1_5_Connection(user_id, key, secure=True, host=None, port=None, url=None, timeout=None, proxy_url=None, backoff=None, retry_delay=None)[source]

Bases: VCloudConnection

Initialize user_id and key; set secure to an int based on passed value.

add_default_headers(headers)[source]

Adds default headers (such as Authorization, X-Foo-Bar) to the passed headers

Should return a dictionary.

class libcloud.compute.drivers.vcloud.VCloud_1_5_NodeDriver(key, secret=None, secure=True, host=None, port=None, api_version='0.8', **kwargs)[source]

Bases: VCloudNodeDriver

Parameters:
  • key (str) – API key or username to be used (required)

  • secret (str) – Secret password to be used (required)

  • secure (bool) – Whether to use HTTPS or HTTP. Note: Some providers only support HTTPS, and it is on by default.

  • host (str) – Override hostname used for connections.

  • port (int) – Override port used for connections.

  • api_version (str) – Optional API version. Only used by drivers which support multiple API versions.

  • region (str) – Optional driver region. Only used by drivers which support multiple regions.

Return type:

None

NODE_STATE_MAP: Dict[str, NodeState] = {'-1': NodeState.UNKNOWN, '0': NodeState.PENDING, '1': NodeState.PENDING, '10': NodeState.UNKNOWN, '2': NodeState.PENDING, '3': NodeState.PENDING, '4': NodeState.RUNNING, '5': NodeState.RUNNING, '6': NodeState.UNKNOWN, '7': NodeState.UNKNOWN, '8': NodeState.STOPPED, '9': NodeState.UNKNOWN}
connectionCls

alias of VCloud_1_5_Connection

create_node(**kwargs)[source]
Creates and returns node. If the source image is:
  • vApp template - a new vApp is instantiated from template

  • existing vApp - a new vApp is cloned from the source vApp. Can

    not clone more vApps is parallel otherwise resource busy error is raised.

@inherits: NodeDriver.create_node

Parameters:
  • image (NodeImage or Node) – OS Image to boot on node. (required). Can be a NodeImage or existing Node that will be cloned.

  • ex_network (str) – Organisation’s network name for attaching vApp VMs to.

  • ex_vdc (str) – Name of organisation’s virtual data center where vApp VMs will be deployed.

  • ex_vm_names (list of str) – list of names to be used as a VM and computer name. The name must be max. 15 characters long and follow the host name requirements.

  • ex_vm_cpu (int) – number of virtual CPUs/cores to allocate for each vApp VM.

  • ex_vm_memory (int) – amount of memory in MB to allocate for each vApp VM.

  • ex_vm_script (str) – full path to file containing guest customisation script for each vApp VM. Useful for creating users & pushing out public SSH keys etc.

  • ex_vm_script_text (str) – content of guest customisation script for each vApp VM. Overrides ex_vm_script parameter.

  • ex_vm_network (str) – Override default vApp VM network name. Useful for when you’ve imported an OVF originating from outside of the vCloud.

  • ex_vm_fence (str) – Fence mode for connecting the vApp VM network (ex_vm_network) to the parent organisation network (ex_network).

  • ex_vm_ipmode (str) – IP address allocation mode for all vApp VM network connections.

  • ex_deploy (bool) – set to False if the node shouldn’t be deployed (started) after creation

  • ex_force_customization (bool) – Used to specify whether to force customization on deployment, if not set default value is False.

  • ex_clone_timeout (int) – timeout in seconds for clone/instantiate VM operation. Cloning might be a time consuming operation especially when linked clones are disabled or VMs are created on different datastores. Overrides the default task completion value.

  • ex_admin_password (str) – set the node admin password explicitly.

  • ex_description (str) – Set a description for the vApp.

destroy_node(node, shutdown=True)[source]

Destroy a node.

Depending upon the provider, this may destroy all data associated with the node, including backups.

Parameters:

node (Node) – The node to be destroyed

Returns:

True if the destroy was successful, False otherwise.

Return type:

bool

ex_add_vm_disk(vapp_or_vm_id, vm_disk_size)[source]

Adds a virtual disk to the specified VM or VMs under the vApp. If the vapp_or_vm_id param represents a link to an vApp all VMs that are attached to this vApp will be modified.

Parameters:
  • vapp_or_vm_id (str) – vApp or VM ID that will be modified. If a vApp ID is used here all attached VMs will be modified

  • vm_disk_size (int) – the disk capacity in GB that will be added to the specified VM or VMs

Return type:

None

ex_change_vm_admin_password(vapp_or_vm_id, ex_admin_password)[source]

Changes the admin (or root) password of VM or VMs under the vApp. If the vapp_or_vm_id param represents a link to an vApp all VMs that are attached to this vApp will be modified.

Parameters:
  • vapp_or_vm_id (str) – vApp or VM ID that will be modified. If a vApp ID is used here all attached VMs will be modified

  • ex_admin_password (str) – admin password to be used.

Return type:

None

ex_deploy_node(node, ex_force_customization=False)[source]

Deploys existing node. Equal to vApp “start” operation.

Parameters:
  • node (Node) – The node to be deployed

  • ex_force_customization (bool) – Used to specify whether to force customization on deployment, if not set default value is False.

Return type:

Node

ex_find_node(node_name, vdcs=None)[source]

Searches for node across specified vDCs. This is more effective than querying all nodes to get a single instance.

Parameters:
  • node_name (str) – The name of the node to search for

  • vdcs (Vdc) – None, vDC or a list of vDCs to search in. If None all vDCs will be searched.

Returns:

node instance or None if not found

Return type:

Node or None

ex_find_vm_nodes(vm_name, max_results=50)[source]

Finds nodes that contain a VM with the specified name.

Parameters:
  • vm_name (str) – The VM name to find nodes for

  • max_results (int) – Maximum number of results up to 128

Returns:

List of node instances

Return type:

list of Node

ex_get_control_access(node)[source]

Returns the control access settings for specified node.

Parameters:

node (Node) – node to get the control access for

Return type:

ControlAccess

ex_get_metadata(node)[source]
Parameters:

node (Node) – node

Returns:

dictionary mapping metadata keys to metadata values

Return type:

dictionary mapping str to str

ex_power_off_node(node)[source]

Powers on all VMs under specified node. VMs need to be This operation is allowed only when the vApp/VM is powered on.

Parameters:

node (Node) – The node to be powered off

Return type:

Node

ex_power_on_node(node)[source]

Powers on all VMs under specified node. This operation is allowed only when the vApp/VM is powered off or suspended.

Parameters:

node (Node) – The node to be powered on

Return type:

Node

ex_query(type, filter=None, page=1, page_size=100, sort_asc=None, sort_desc=None)[source]

Queries vCloud for specified type. See http://www.vmware.com/pdf/vcd_15_api_guide.pdf for details. Each element of the returned list is a dictionary with all attributes from the record.

Parameters:
  • type (str) – type to query (r.g. user, group, vApp etc.)

  • filter (str) – filter expression (see documentation for syntax)

  • page (int) – page number

  • page_size (int) – page size

  • sort_asc (str) – sort in ascending order by specified field

  • sort_desc (str) – sort in descending order by specified field

Return type:

list of dict

ex_set_control_access(node, control_access)[source]

Sets control access for the specified node.

Parameters:
  • node (Node) – node

  • control_access (ControlAccess) – control access settings

Return type:

None

ex_set_metadata_entry(node, key, value)[source]
Parameters:
  • node (Node) – node

  • key (str) – metadata key to be set

  • value (str) – metadata value to be set

Return type:

None

ex_set_vm_cpu(vapp_or_vm_id, vm_cpu)[source]

Sets the number of virtual CPUs for the specified VM or VMs under the vApp. If the vapp_or_vm_id param represents a link to an vApp all VMs that are attached to this vApp will be modified.

Please ensure that hot-adding a virtual CPU is enabled for the powered on virtual machines. Otherwise use this method on undeployed vApp.

Parameters:
  • vapp_or_vm_id (str) – vApp or VM ID that will be modified. If a vApp ID is used here all attached VMs will be modified

  • vm_cpu (int) – number of virtual CPUs/cores to allocate for specified VMs

Return type:

None

ex_set_vm_memory(vapp_or_vm_id, vm_memory)[source]

Sets the virtual memory in MB to allocate for the specified VM or VMs under the vApp. If the vapp_or_vm_id param represents a link to an vApp all VMs that are attached to this vApp will be modified.

Please ensure that hot-change of virtual memory is enabled for the powered on virtual machines. Otherwise use this method on undeployed vApp.

Parameters:
  • vapp_or_vm_id (str) – vApp or VM ID that will be modified. If a vApp ID is used here all attached VMs will be modified

  • vm_memory (int) – virtual memory in MB to allocate for the specified VM or VMs

Return type:

None

ex_shutdown_node(node)[source]

Shutdowns all VMs under specified node. This operation is allowed only when the vApp/VM is powered on.

Parameters:

node (Node) – The node to be shut down

Return type:

Node

ex_suspend_node(node)[source]

Suspends all VMs under specified node. This operation is allowed only when the vApp/VM is powered on.

Parameters:

node (Node) – The node to be suspended

Return type:

Node

ex_undeploy_node(node, shutdown=True)[source]

Undeploys existing node. Equal to vApp “stop” operation.

Parameters:
  • node (Node) – The node to be deployed

  • shutdown (bool) – Whether to shutdown or power off the guest when undeploying

Return type:

Node

list_locations()[source]

List data centers for a provider

Returns:

list of node location objects

Return type:

list of NodeLocation

reboot_node(node)[source]

Reboot a node.

Parameters:

node (Node) – The node to be rebooted

Returns:

True if the reboot was successful, otherwise False

Return type:

bool

class libcloud.compute.drivers.vcloud.VCloud_5_1_NodeDriver(key, secret=None, secure=True, host=None, port=None, api_version='0.8', **kwargs)[source]

Bases: VCloud_1_5_NodeDriver

Parameters:
  • key (str) – API key or username to be used (required)

  • secret (str) – Secret password to be used (required)

  • secure (bool) – Whether to use HTTPS or HTTP. Note: Some providers only support HTTPS, and it is on by default.

  • host (str) – Override hostname used for connections.

  • port (int) – Override port used for connections.

  • api_version (str) – Optional API version. Only used by drivers which support multiple API versions.

  • region (str) – Optional driver region. Only used by drivers which support multiple regions.

Return type:

None

class libcloud.compute.drivers.vcloud.VCloud_5_5_Connection(user_id, key, secure=True, host=None, port=None, url=None, timeout=None, proxy_url=None, backoff=None, retry_delay=None)[source]

Bases: VCloud_1_5_Connection

Initialize user_id and key; set secure to an int based on passed value.

add_default_headers(headers)[source]

Adds default headers (such as Authorization, X-Foo-Bar) to the passed headers

Should return a dictionary.

class libcloud.compute.drivers.vcloud.VCloud_5_5_NodeDriver(key, secret=None, secure=True, host=None, port=None, api_version='0.8', **kwargs)[source]

Bases: VCloud_5_1_NodeDriver

Use 5.5 Connection class to explicitly set 5.5 for the version in Accept headers

Parameters:
  • key (str) – API key or username to be used (required)

  • secret (str) – Secret password to be used (required)

  • secure (bool) – Whether to use HTTPS or HTTP. Note: Some providers only support HTTPS, and it is on by default.

  • host (str) – Override hostname used for connections.

  • port (int) – Override port used for connections.

  • api_version (str) – Optional API version. Only used by drivers which support multiple API versions.

  • region (str) – Optional driver region. Only used by drivers which support multiple regions.

Return type:

None

connectionCls

alias of VCloud_5_5_Connection

ex_acquire_mks_ticket(vapp_or_vm_id, vm_num=0)[source]

Retrieve a mks ticket that you can use to gain access to the console of a running VM. If successful, returns a dict with the following keys:

  • host: host (or proxy) through which the console connection

    is made

  • vmx: a reference to the VMX file of the VM for which this

    ticket was issued

  • ticket: screen ticket to use to authenticate the client

  • port: host port to be used for console access

Parameters:
  • vapp_or_vm_id (str) – vApp or VM ID you want to connect to.

  • vm_num (int) – If a vApp ID is provided, vm_num is position in the vApp VM list of the VM you want to get a screen ticket. Default is 0.

Return type:

dict

ex_create_snapshot(node)[source]

Creates new snapshot of a virtual machine or of all the virtual machines in a vApp. Prior to creation of the new snapshots, any existing user created snapshots associated with the virtual machines are removed.

Parameters:

node (Node) – node

Return type:

Node

ex_remove_snapshots(node)[source]

Removes all user created snapshots for a vApp or virtual machine.

Parameters:

node (Node) – node

Return type:

Node

ex_revert_to_snapshot(node)[source]

Reverts a vApp or virtual machine to the current snapshot, if any.

Parameters:

node (Node) – node

Return type:

Node

class libcloud.compute.drivers.vcloud.Vdc(id, name, driver, allocation_model=None, cpu=None, memory=None, storage=None)[source]

Bases: object

Virtual datacenter (vDC) representation

libcloud.compute.drivers.vcloud.fixxpath(root, xpath)[source]

ElementTree wants namespaces in its xpaths, so here we add them.

libcloud.compute.drivers.vcloud.get_url_path(url)[source]
libcloud.compute.drivers.vcloud.urlparse(url, scheme='', allow_fragments=True)[source]

From vcloud api “The VirtualQuantity element defines the number of MB of memory. This should be either 512 or a multiple of 1024 (1 GB).”