libcloud.compute.drivers.vsphere module

VMware vSphere driver. Uses pyvmomi - https://github.com/vmware/pyvmomi Code inspired by https://github.com/vmware/pyvmomi-community-samples

Authors: Dimitris Moraitis, Alex Tsiliris, Markos Gogoulos

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

Bases: ConnectionKey

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

add_default_headers(headers)[source]

VSphere needs an initial connection to a specific API endpoint to generate a session-token, which will be used for the purpose of authenticating for the rest of the session.

responseCls

alias of VSphereResponse

session_token = None
exception libcloud.compute.drivers.vsphere.VSphereException(code, message)[source]

Bases: Exception

class libcloud.compute.drivers.vsphere.VSphereNetwork(id, name, extra=None)[source]

Bases: object

Represents information about a VPC (Virtual Private Cloud) network

Note: This class is VSphere specific.

class libcloud.compute.drivers.vsphere.VSphereNodeDriver(host, username, password, port=443, ca_cert=None)[source]

Bases: NodeDriver

Initialize a connection by providing a hostname, username and password

NODE_STATE_MAP: Dict[str, NodeState] = {'poweredOff': NodeState.STOPPED, 'poweredOn': NodeState.RUNNING, 'suspended': NodeState.SUSPENDED}
create_node(name, image, size, location=None, ex_cluster=None, ex_network=None, ex_datacenter=None, ex_folder=None, ex_resource_pool=None, ex_datastore_cluster=None, ex_datastore=None)[source]

Creates and returns node.

Parameters:

ex_network (str) – Name of a “Network” to connect the VM to “,

destroy_node(node)[source]
ex_connect_network(vm, network_name)[source]
ex_create_snapshot(node, snapshot_name, description='', dump_memory=False, quiesce=False)[source]

Create node snapshot

ex_list_datastores()[source]
ex_list_folders()[source]
ex_list_networks()[source]

List networks

ex_list_snapshots(node)[source]

List node snapshots

ex_open_console(vm_uuid)[source]
ex_remove_snapshot(node, snapshot_name=None, remove_children=True)[source]

Remove a snapshot from node. If snapshot_name is not defined remove the last one.

ex_revert_to_snapshot(node, snapshot_name=None)[source]

Revert node to a specific snapshot. If snapshot_name is not defined revert to the last one.

find_by_uuid(node_uuid)[source]

Searches VMs for a given uuid returns pyVmomi.VmomiSupport.vim.VirtualMachine

find_custom_field_key(key_id)[source]

Return custom field key name, provided it’s id

get_obj(vimtype, name)[source]

Return an object by name, if name is None the first found object is returned

list_images(location=None, folder_ids=None)[source]

Lists VM templates as images. If folder is given then it will list images contained in that folder only.

list_locations(ex_show_hosts_in_drs=True)[source]

Lists locations

list_nodes(enhance=True, max_properties=20)[source]

List nodes, excluding templates

list_nodes_recursive(enhance=True)[source]

Lists nodes, excluding templates

list_sizes()[source]

Returns sizes

name: str = 'VMware vSphere'
reboot_node(node)[source]
start_node(node)[source]
stop_node(node)[source]
type: Provider | str = 'vsphere'
wait_for_task(task, timeout=1800, interval=10)[source]

wait for a vCenter task to finish

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

Bases: JsonResponse

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

  • connection (Connection) – Parent connection object.

parse_error()[source]

Parse the error messages.

Override in a provider’s subclass.

Returns:

Parsed error.

Return type:

str

class libcloud.compute.drivers.vsphere.VSphere_REST_NodeDriver(key, secret=None, secure=True, host=None, port=443, ca_cert=None)[source]

Bases: 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

NODE_STATE_MAP: Dict[str, NodeState] = {'powered_off': NodeState.STOPPED, 'powered_on': NodeState.RUNNING, 'suspended': NodeState.SUSPENDED}
VALID_RESPONSE_CODES = [<HTTPStatus.OK: 200>, <HTTPStatus.ACCEPTED: 202>, <HTTPStatus.CREATED: 201>, <HTTPStatus.NO_CONTENT: 204>]
async_list_nodes()[source]

In this case filtering is not possible. Use this method when the cloud has a lot of vms and you want to return them all.

connectionCls

alias of VSphereConnection

create_node(name, image, size=None, location=None, ex_datastore=None, ex_disks=None, ex_folder=None, ex_network=None, ex_turned_on=True)[source]

Image can be either a vm template , a ovf template or just the guest OS.

ex_folder is necessary if the image is a vm-template, this method will attempt to put the VM in a random folder and a warning about it will be issued in case the value remains None.

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_add_nic(node, network)[source]

Creates a network adapter that will connect to the specified network for the given node. Returns a boolean indicating success or not.

ex_create_snapshot(node, snapshot_name, description='', dump_memory=False, quiesce=False)[source]

Create node snapshot

ex_list_clusters(ex_filter_folders=None, ex_filter_names=None, ex_filter_datacenters=None, ex_filter_clusters=None)[source]
ex_list_content_libraries()[source]
ex_list_content_library_items(library_id)[source]
ex_list_datacenters(ex_filter_folders=None, ex_filter_names=None, ex_filter_datacenters=None)[source]
ex_list_datastores(ex_filter_folders=None, ex_filter_names=None, ex_filter_datacenters=None, ex_filter_types=None, ex_filter_datastores=None)[source]
ex_list_folders()[source]
ex_list_hosts(ex_filter_folders=None, ex_filter_standalone=None, ex_filter_hosts=None, ex_filter_clusters=None, ex_filter_names=None, ex_filter_datacenters=None, ex_filter_connection_states=None)[source]
ex_list_networks()[source]
ex_list_snapshots(node)[source]

List node snapshots

ex_open_console(vm_id)[source]
ex_remove_snapshot(node, snapshot_name=None, remove_children=True)[source]

Remove a snapshot from node. If snapshot_name is not defined remove the last one.

ex_revert_to_snapshot(node, snapshot_name=None)[source]

Revert node to a specific snapshot. If snapshot_name is not defined revert to the last one.

ex_suspend_node(node)[source]
ex_update_capacity(node, capacity)[source]
ex_update_cpu(node, cores)[source]

Assuming 1 Core per socket :param cores: Integer or string indicating number of cores :type cores: int or str

ex_update_memory(node, ram)[source]
Parameters:

ram (str or int) – The amount of ram in MB.

list_images(**kwargs)[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_locations(ex_show_hosts_in_drs=True)[source]

Location in the general sense means any resource that allows for node creation. In vSphere’s case that usually is a host but if a cluster has rds enabled, a cluster can be assigned to create the VM, thus the clusters with rds enabled will be added to locations.

Parameters:

ex_show_hosts_in_drs (boolean) – A DRS cluster schedules automatically on which host should be placed thus it may not be desired to show the hosts in a DRS enabled cluster. Set False to not show these hosts.

list_nodes(ex_filter_power_states=None, ex_filter_folders=None, ex_filter_names=None, ex_filter_hosts=None, ex_filter_clusters=None, ex_filter_vms=None, ex_filter_datacenters=None, ex_filter_resource_pools=None, max_properties=20)[source]

The ex parameters are search options and must be an array of strings, even ex_filter_power_states which can have at most two items but makes sense to keep only one (“POWERED_ON” or “POWERED_OFF”) Keep in mind that this method will return up to 1000 nodes so if your network has more, do use the provided filters and call it multiple times.

list_sizes()[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 = 'VMware vSphere'
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

session_token = None
start_node(node)[source]

Start a node.

Parameters:

node (Node) – The node to be started

Returns:

True if the start was successful, otherwise False

Return type:

bool

stop_node(node)[source]

Stop a node

Parameters:

node (Node) – The node to be stopped.

Returns:

True if the stop was successful, otherwise False

Return type:

bool

type: Provider | str = 'vsphere'
website: str = 'http://www.vmware.com/products/vsphere/'
libcloud.compute.drivers.vsphere.format_snapshots(snapshot_list)[source]
libcloud.compute.drivers.vsphere.recurse_snapshots(snapshot_list)[source]