libcloud.compute.drivers.vultr module

Vultr Driver

class libcloud.compute.drivers.vultr.SSHKey(id, name, pub_key)[source]

Bases: object

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

Bases: ConnectionKey

Connection class for the Vultr driver.

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

add_default_headers(headers)[source]

Adds API-Key default header.

Returns:

Updated headers.

Return type:

dict

encode_data(data)[source]

Encode body data.

Override in a provider’s subclass.

get(url)[source]
host: str = 'api.vultr.com'
post(url, data)[source]
require_api_key()[source]

Check whether this call (method + action) must be authenticated.

Returns:

True if API-Key header required, False otherwise.

Return type:

bool

responseCls

alias of VultrResponse

unauthenticated_endpoints = {'/v1/app/list': ['GET'], '/v1/os/list': ['GET'], '/v1/plans/list': ['GET'], '/v1/plans/list_vc2': ['GET'], '/v1/plans/list_vdc2': ['GET'], '/v1/regions/availability': ['GET'], '/v1/regions/list': ['GET']}
class libcloud.compute.drivers.vultr.VultrNodeDriver(key, secret=None, secure=True, host=None, port=None, api_version='2', region=None, **kwargs)[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

name: str = 'Vultr'
type: Provider | str = 'vultr'
website: str = 'https://www.vultr.com'
class libcloud.compute.drivers.vultr.VultrNodeDriverHelper[source]

Bases: object

VultrNode helper class.

handle_extra(extra_keys, data)[source]
class libcloud.compute.drivers.vultr.VultrNodeDriverV1(key, secret=None, secure=True, host=None, port=None, api_version='2', region=None, **kwargs)[source]

Bases: VultrNodeDriver

VultrNode 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

EX_CREATE_ATTRIBUTES = ['ipxe_chain_url', 'label', 'userdata', 'reserved_ip_v4', 'hostname', 'tag', 'enable_ipv6', 'enable_private_network', 'auto_backups', 'notify_activate', 'ddos_protection', 'iso_id', 'script_id', 'snapshot_id', 'app_id']
EX_CREATE_ID_ATTRIBUTES = {'app_id': 'APPID', 'iso_id': 'ISOID', 'script_id': 'SCRIPTID', 'snapshot_id': 'SNAPSHOTID'}
EX_CREATE_YES_NO_ATTRIBUTES = ['enable_ipv6', 'enable_private_network', 'auto_backups', 'notify_activate', 'ddos_protection']
NODE_STATE_MAP: Dict[str, NodeState] = {'active': NodeState.RUNNING, 'pending': NodeState.PENDING}
connectionCls

alias of VultrConnection

create_key_pair(name, public_key='')[source]

Create a new SSH key. :param name: Name of the new SSH key :type name: str

Key public_key:

Public part of the new SSH key

Returns:

True on success

Return type:

bool

create_node(name, size, image, location, ex_ssh_key_ids=None, ex_create_attr=None)[source]

Create a node

Parameters:
  • name (str) – Name for the new node

  • size (NodeSize) – Size of the new node

  • image (NodeImage) – Image for the new node

  • location (NodeLocation) – Location of the new node

  • ex_ssh_key_ids – IDs of the SSH keys to initialize

  • ex_create_attr (dict) – Extra attributes for node creation

The ex_create_attr parameter can include the following dictionary key and value pairs:

  • ipxe_chain_url: str for specifying URL to boot via IPXE

  • iso_id: str the ID of a specific ISO to mount, only meaningful with the Custom NodeImage

  • script_id: int ID of a startup script to execute on boot, only meaningful when the NodeImage is not Custom

  • ‘snapshot_id`: str Snapshot ID to restore for the initial installation, only meaningful with the Snapshot NodeImage

  • enable_ipv6: bool Whether an IPv6 subnet should be assigned

  • enable_private_network: bool Whether private networking support should be added

  • label: str Text label to be shown in the control panel

  • auto_backups: bool Whether automatic backups should be enabled

  • app_id: int App ID to launch if launching an application, only meaningful when the NodeImage is Application

  • userdata: str Base64 encoded cloud-init user-data

  • notify_activate: bool Whether an activation email should be sent when the server is ready

  • ddos_protection: bool Whether DDOS protection should be enabled

  • reserved_ip_v4: str IP address of the floating IP to use as the main IP of this server

  • hostname: str The hostname to assign to this server

  • tag: str The tag to assign to this server

Returns:

The newly created node.

Return type:

Node

delete_key_pair(key_pair)[source]

Delete an SSH key. :param key_pair: The SSH key to delete :type key_pair: SSHKey

Returns:

True on success

Return type:

bool

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

list_images()[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_key_pairs()[source]

List all the available SSH keys. :return: Available SSH keys. :rtype: list of SSHKey

list_locations()[source]

List data centers for a provider

Returns:

list of node location objects

Return type:

list of NodeLocation

list_nodes()[source]

List all nodes.

Returns:

list of node objects

Return type:

list of Node

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

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.vultr.VultrNodeDriverV2(key, secret=None, secure=True, host=None, port=None, api_version='2', region=None, **kwargs)[source]

Bases: VultrNodeDriver

Vultr API v2 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] = {'active': NodeState.RUNNING, 'halted': NodeState.STOPPED, 'pending': NodeState.PENDING, 'rebooting': NodeState.REBOOTING, 'resizing': NodeState.RECONFIGURING}
SNAPSHOT_STATE_MAP = {'complete': VolumeSnapshotState.AVAILABLE, 'pending': VolumeSnapshotState.CREATING}
VOLUME_STATE_MAP = {'active': StorageVolumeState.AVAILABLE, 'pending': StorageVolumeState.CREATING}
attach_volume(node: Node, volume: StorageVolume, ex_live: bool = True) bool[source]

Attaches volume to node.

Parameters:
  • node (Node) – Node to attach volume to.

  • volume (StorageVolume) – Volume to attach.

  • ex_live (bool) – Attach the volume without restarting the node.

Rytpe:

bool

connectionCls

alias of VultrConnectionV2

create_node(name: str, size: NodeSize, location: NodeLocation, image: NodeImage | None = None, ex_ssh_key_ids: List[str] | None = None, ex_private_network_ids: List[str] | None = None, ex_snapshot: VultrNodeSnapshot | str | None = None, ex_enable_ipv6: bool = False, ex_backups: bool = False, ex_userdata: str | None = None, ex_ddos_protection: bool = False, ex_enable_private_network: bool = False, ex_ipxe_chain_url: str | None = None, ex_iso_id: str | None = None, ex_script_id: str | None = None, ex_image_id: str | None = None, ex_activation_email: bool = False, ex_hostname: str | None = None, ex_tag: str | None = None, ex_firewall_group_id: str | None = None, ex_reserved_ipv4: str | None = None, ex_persistent_pxe: bool = False) Node[source]

Create a new node.

Parameters:
  • name (str) – The new node’s name.

  • size – The size to use to create the node.

  • location – The location to provision the node.

  • image – The image to use to provision the node.

  • ex_ssh_key_ids (list of str) – List of SSH keys to install on this node.

  • ex_private_network_ids (list of str) – The network ids to attach to node. This parameter takes precedence over ex_enable_private_network (VPS only)

  • ex_snapshot – The snapshot to use when deploying the node. Mutually exclusive with image,

  • ex_enable_ipv6 (bool) – Whether to enable IPv6.

  • ex_backups (bool) – Enable automatic backups for the node. (VPS only)

  • ex_userdata (str) – String containing user data

  • ex_ddos_protection (bool) – Enable DDoS protection (VPS only)

  • ex_enable_private_network (bool) –

    Enable private networking. Mutually exclusive with

    ex_private_network_ids.

    (VPS only)

  • ex_ipxe_chain_url (str) – The URL location of the iPXE chainloader (VPS only)

  • ex_iso_id (str) – The ISO id to use when deploying this node. (VPS only)

  • ex_script_id (str) – The startup script id to use when deploying this node.

  • ex_image_id (str) – The Application image_id to use when deploying this node.

  • ex_activation_email (bool) – Notify by email after deployment.

  • ex_hostname (str) – The hostname to use when deploying this node.

  • ex_tag (str) – The user-supplied tag.

  • ex_firewall_group_id (str) – The Firewall Group id to attach to this node. (VPS only)

  • ex_reserved_ipv4 (str) – Id of the floating IP to use as the main IP of this node.

  • ex_persistent_pxe (bool) – Enable persistent PXE (Bare Metal only)

create_volume(size: int, name: str, location: NodeLocation | str) StorageVolume[source]

Create a new volume.

Parameters:
  • size (int) – Size of the volume in gigabytes. Size may range between 10 and 10000.

  • name (str) – Name of the volume to be created.

  • location (NodeLocation or str) – Which data center to create the volume in.

Returns:

The newly created volume.

Return type:

StorageVolume

delete_key_pair(key_pair: KeyPair) bool[source]

Delete existing key pair.

Parameters:

key_pair (KeyPair) – The key pair object to delete.

Return type:

bool

destroy_node(node: Node) bool[source]

Destroy the given node.

Parameters:

node – The node to be destroyed.

Return type:

bool

destroy_volume(volume: StorageVolume) bool[source]

Destroys a storage volume.

Parameters:

volume (StorageVolume) – Volume to be destroyed

Return type:

bool

detach_volume(volume: StorageVolume, ex_live: bool = True) bool[source]

Detaches a volume from a node.

Parameters:
  • volume (StorageVolume) – Volume to be detached

  • ex_live (bool) – Detach the volume without restarting the node.

Return type:

bool

ex_create_network(cidr_block: str, location: NodeLocation | str, description: str | None = None) VultrNetwork[source]

Create a private network.

Parameters:
  • cidr_block (str) – The CIDR block assigned to the network.

  • location – The location to create the network.

  • description (str) – A description of the private network.

Return type:

class:

VultrNetwork

ex_create_snapshot(node: Node, description: str | None = None) VultrNodeSnapshot[source]

Create snapshot from a node.

Parameters:
  • node – Node to create the snapshot from.

  • description (str) – A description of the snapshot.

Return type:

class:

VultrNodeSnapshot

ex_delete_snapshot(snapshot: VultrNodeSnapshot) bool[source]

Delete the given snapshot.

Parameters:

snapshot – The snapshot to delete.

Return type:

bool

ex_destroy_bare_metal_node(node: Node) bool[source]

Destroy the given bare metal node.

Parameters:

node – The bare metal node to be destroyed.

Return type:

bool

ex_destroy_network(network: VultrNetwork) bool[source]

Delete a private network.

Parameters:

network – The network to destroy.

Return type:

bool

ex_get_network(network_id: str) VultrNetwork[source]

Retrieve a private network.

Parameters:

network_id (str) – ID of the network to retrieve.

Return type:

class:

VultrNetwork

ex_get_node(node_id: str) Node[source]

Retrieve a node object.

Parameters:

node_id – ID of the node to retrieve.

Return type:

class:

Node

ex_get_snapshot(snapshot_id: str) VultrNodeSnapshot[source]

Retrieve a snapshot.

Parameters:

snapshot_id (str) – ID of the snapshot to retrieve.

Return type:

class:

VultrNodeSnapshot

ex_get_volume(volume_id: str) StorageVolume[source]

Retrieve a single volume.

Parameters:

volume_id (str) – The ID of the volume to fetch.

Rtype :class:

StorageVolume

Returns:

StorageVolume instance on success.

ex_list_available_sizes_for_location(location: NodeLocation) List[str][source]

Get a list of available sizes for the given location.

Parameters:

location – The location to get available sizes for.

Returns:

A list of available size IDs for the given location.

Return type:

list of str

ex_list_bare_metal_nodes() List[Node][source]

List all bare metal nodes.

Returns:

list of node objects

Return type:

list of :class: Node

ex_list_bare_metal_sizes() List[NodeSize][source]

List bare metal sizes.

Return type:

list of :class: NodeSize

ex_list_networks() List[VultrNetwork][source]

List all private networks.

Return type:

list of :class: VultrNetwork

ex_list_snapshots() List[VultrNodeSnapshot][source]

List node snapshots.

Return type:

list of :class: VultrNodeSnapshot

ex_reboot_bare_metal_node(node: Node) bool[source]

Reboot the given bare metal node.

Parameters:

node – The bare metal node to be rebooted.

Return type:

bool

ex_resize_node(node: Node, size: NodeSize) bool[source]

Change size for the given node, only applicable for VPS nodes.

Parameters:
  • node – The node to be resized.

  • size – The new size.

ex_resize_volume(volume: StorageVolume, size: int) bool[source]

Resize a volume.

Parameters:
  • volume (StorageVolume) – The volume to resize.

  • size (int) – The new volume size in GBs. Size may range between 10 and 10000.

Return type:

bool

ex_start_bare_metal_node(node: Node) bool[source]

Start the given bare metal node.

Parameters:

node – The bare metal node to be started.

Return type:

bool

ex_stop_bare_metal_node(node: Node) bool[source]

Stop the given bare metal node.

Parameters:

node – The bare metal node to be stopped.

Return type:

bool

ex_stop_nodes(nodes: List[Node]) bool[source]

Stops all the nodes given.

: param nodes: A list of the nodes to stop. : type node: list of: class Node

: rtype: bool

get_key_pair(key_id: str) KeyPair[source]

Retrieve a single key pair.

Parameters:

key_id (str) – ID of the key pair to retrieve.

Return type:

class:

KeyPair

import_key_pair_from_string(name: str, key_material: str) KeyPair[source]

Import a new public key from string.

Parameters:
  • name (str) – Key pair name.

  • key_material (str) – Public key material.

Return type:

class:

KeyPair

list_images() List[NodeImage][source]

List available node images.

Return type:

list of :class: NodeImage

list_key_pairs() List[KeyPair][source]

List all the available SSH key pair objects.

Return type:

list of KeyPair

list_locations() List[NodeLocation][source]

List available node locations.

Return type:

list of :class: NodeLocation

list_nodes(ex_list_bare_metals: bool = True) List[Node][source]

List all nodes.

Parameters:

ex_list_bare_metals (bool) – Whether to fetch bare metal nodes.

Returns:

list of node objects

Return type:

list of :class: Node

list_sizes(ex_list_bare_metals: bool = True) List[NodeSize][source]

List available node sizes.

Parameters:

ex_list_bare_metals (bool) – Whether to fetch bare metal sizes.

Return type:

list of :class: NodeSize

list_volumes() List[StorageVolume][source]

List storage volumes.

Return type:

list of StorageVolume

reboot_node(node: Node) bool[source]

Reboot the given node.

Parameters:

node – The node to be rebooted.

Return type:

bool

start_node(node: Node) bool[source]

Start the given node.

Parameters:

node – The node to be started.

Return type:

bool

stop_node(node: Node) bool[source]

Stop the given node.

Parameters:

node – The node to be stopped.

Return type:

bool

class libcloud.compute.drivers.vultr.VultrResponse(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.vultr.rate_limited(sleep=0.5, retries=1)[source]

Bases: object

Decorator for retrying Vultr calls that are rate-limited.

Parameters:
  • sleep (int) – Seconds to sleep after being rate-limited.

  • retries (int) – Number of retries.