Vultr Compute Driver Documentation¶
Vultr is a public cloud provider based in multiple countries.
How to get API Key¶
Visit https://my.vultr.com/settings/#API
You can see Your API Key in API Information Section in the middle of page. If you want to change your API Key, press the Regenerate Button.
Examples¶
1. Create vultr driver - how to create vultr driver with api key¶
from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver
cls = get_driver(Provider.VULTR)
driver = cls('your api key')
API Docs¶
-
class
libcloud.compute.drivers.vultr.VultrNodeDriver(key, secret=None, secure=True, host=None, port=None, api_version=None, region=None, **kwargs)[source]¶ 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-
attach_volume(node, volume, device=None)¶ Attaches volume to node.
Parameters: - node (
Node) – Node to attach volume to. - volume (
StorageVolume) – Volume to attach. - device (
str) – Where the device is exposed, e.g. ‘/dev/sdb’
Rytpe: bool- node (
-
connectionCls¶ alias of
VultrConnection
-
copy_image(source_region, node_image, name, description=None)¶ Copies an image from a source region to the current region.
Parameters: - source_region (
str) – Region to copy the node from. - node_image (
NodeImage:) – NodeImage to copy. - name (
str) – name for new image. - description – description for new image.
Return type: NodeImage:Returns: NodeImage instance on success.
- source_region (
-
create_image(node, name, description=None)¶ Creates an image from a node object.
Parameters: - node (
Node) – Node to run the task on. - name (
description) – name for new image. - description – description for new image.
Return type: NodeImage:Returns: NodeImage instance on success.
- node (
-
create_key_pair(name, public_key='')[source]¶ Create a new SSH key. :param name: Name of the new SSH key :type name:
strKey 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:
strfor specifying URL to boot via IPXE - iso_id:
strthe ID of a specific ISO to mount, only meaningful with the Custom NodeImage - script_id:
intID of a startup script to execute on boot, only meaningful when the NodeImage is not Custom - ‘snapshot_id`:
strSnapshot ID to restore for the initial installation, only meaningful with the Snapshot NodeImage - enable_ipv6:
boolWhether an IPv6 subnet should be assigned - enable_private_network:
boolWhether private networking support should be added - label:
strText label to be shown in the control panel - auto_backups:
boolWhether automatic backups should be enabled - app_id:
intApp ID to launch if launching an application, only meaningful when the NodeImage is Application - userdata:
strBase64 encoded cloud-init user-data - notify_activate:
boolWhether an activation email should be sent when the server is ready - ddos_protection:
boolWhether DDOS protection should be enabled - reserved_ip_v4:
strIP address of the floating IP to use as the main IP of this server - hostname:
strThe hostname to assign to this server - tag:
strThe tag to assign to this server
Returns: The newly created node. Return type: Node- name (
-
create_volume(size, name, location=None, snapshot=None)¶ Create a new volume.
Parameters: - size (
int) – Size of volume in gigabytes (required) - name (
str) – Name of the volume to be created - location (
NodeLocation) – Which data center to create a volume in. If empty, undefined behavior will be selected. (optional) - snapshot (
VolumeSnapshot) – Snapshot from which to create the new volume. (optional)
Returns: The newly created volume.
Return type: StorageVolume- size (
-
create_volume_snapshot(volume, name=None)¶ Creates a snapshot of the storage volume.
Parameters: - volume (
StorageVolume) – The StorageVolume to create a VolumeSnapshot from - name (str) – Name of created snapshot (optional)
Return type: VolumeSnapshot- volume (
-
delete_image(node_image)¶ Deletes a node image from a provider.
Parameters: node_image ( NodeImage) – Node image object.Returns: Trueif delete_image was successful,Falseotherwise.Return type: bool
-
delete_key_pair(key_pair)[source]¶ Delete an SSH key. :param key_pair: The SSH key to delete :type key_pair:
SSHKeyReturns: True on success Return type: bool
-
deploy_node(deploy, ssh_username='root', ssh_alternate_usernames=None, ssh_port=22, ssh_timeout=10, ssh_key=None, auth=None, timeout=300, max_tries=3, ssh_interface='public_ips', **create_node_kwargs)¶ Create a new node, and start deployment.
In order to be able to SSH into a created node access credentials are required.
A user can pass either a
NodeAuthPasswordorNodeAuthSSHKeyto theauthargument. If thecreate_nodeimplementation supports that kind if credential (as declared inself.features['create_node']) then it is passed on tocreate_node. Otherwise it is not passed on tocreate_nodeand it is only used for authentication.If the
authparameter is not supplied but the driver declares it supportsgenerates_passwordthen the password returned bycreate_nodewill be used to SSH into the server.Finally, if the
ssh_key_fileis supplied that key will be used to SSH into the server.This function may raise a
DeploymentException, if a create_node call was successful, but there is a later error (like SSH failing or timing out). This exception includes a Node object which you may want to destroy if incomplete deployments are not desirable.>>> from libcloud.compute.drivers.dummy import DummyNodeDriver >>> from libcloud.compute.deployment import ScriptDeployment >>> from libcloud.compute.deployment import MultiStepDeployment >>> from libcloud.compute.base import NodeAuthSSHKey >>> driver = DummyNodeDriver(0) >>> key = NodeAuthSSHKey('...') # read from file >>> script = ScriptDeployment("yum -y install emacs strace tcpdump") >>> msd = MultiStepDeployment([key, script]) >>> def d(): ... try: ... driver.deploy_node(deploy=msd) ... except NotImplementedError: ... print ("not implemented for dummy driver") >>> d() not implemented for dummy driver
Deploy node is typically not overridden in subclasses. The existing implementation should be able to handle most such.
Parameters: - deploy (
Deployment) – Deployment to run once machine is online and available to SSH. - ssh_username (
str) – Optional name of the account which is used when connecting to SSH server (default is root) - ssh_alternate_usernames (
list) – Optional list of ssh usernames to try to connect with if using the default one fails - ssh_port (
int) – Optional SSH server port (default is 22) - ssh_timeout (
float) – Optional SSH connection timeout in seconds (default is 10) - auth (
NodeAuthSSHKeyorNodeAuthPassword) – Initial authentication information for the node (optional) - ssh_key (
strorlistofstr) – A path (or paths) to an SSH private key with which to attempt to authenticate. (optional) - timeout (
int) – How many seconds to wait before timing out. (default is 600) - max_tries (
int) – How many times to retry if a deployment fails before giving up (default is 3) - ssh_interface (
str) – The interface to wait for. Default is ‘public_ips’, other option is ‘private_ips’.
- deploy (
-
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 destroyedReturns: True if the destroy was successful, False otherwise. Return type: bool
-
destroy_volume(volume)¶ Destroys a storage volume.
Parameters: volume ( StorageVolume) – Volume to be destroyedReturn type: bool
-
destroy_volume_snapshot(snapshot)¶ Destroys a snapshot.
Parameters: snapshot ( VolumeSnapshot) – The snapshot to deleteReturn type: bool
-
detach_volume(volume)¶ Detaches a volume from a node.
Parameters: volume ( StorageVolume) – Volume to be detachedReturn type: bool
-
get_image(image_id)¶ Returns a single node image from a provider.
Parameters: image_id ( str) – Node to run the task on.:rtype
NodeImage: :return: NodeImage instance on success.
-
get_key_pair(name)¶ Retrieve a single key pair.
Parameters: name ( str) – Name of the key pair to retrieve.Return type: KeyPair
-
import_key_pair_from_file(name, key_file_path)¶ Import a new public key from string.
Parameters: - name (
str) – Key pair name. - key_file_path (
str) – Path to the public key file.
Return type: KeyPairobject- name (
-
import_key_pair_from_string(name, key_material)¶ Import a new public key from string.
Parameters: - name (
str) – Key pair name. - key_material (
str) – Public key material.
Return type: KeyPairobject- name (
-
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: listofNodeImage
-
list_key_pairs()[source]¶ List all the available SSH keys. :return: Available SSH keys. :rtype:
listofSSHKey
-
list_locations()[source]¶ List data centers for a provider
Returns: list of node location objects Return type: listofNodeLocation
-
list_sizes()[source]¶ List sizes on a provider
Parameters: location ( NodeLocation) – The location at which to list sizesReturns: list of node size objects Return type: listofNodeSize
-
list_volume_snapshots(volume)¶ List snapshots for a storage volume.
Return type: listofVolumeSnapshot
-
list_volumes()¶ List storage volumes.
Return type: listofStorageVolume
-
reboot_node(node)[source]¶ Reboot a node.
Parameters: node ( Node) – The node to be rebootedReturns: True if the reboot was successful, otherwise False Return type: bool
-
start_node(node)¶ Start a node.
Parameters: node ( Node) – The node to be startedReturns: True if the start was successful, otherwise False Return type: bool
-
stop_node(node)¶ Stop a node
Parameters: node ( Node) – The node to be stopped.Returns: True if the stop was successful, otherwise False Return type: bool
-
wait_until_running(nodes, wait_period=3, timeout=600, ssh_interface='public_ips', force_ipv4=True, ex_list_nodes_kwargs=None)¶ Block until the provided nodes are considered running.
Node is considered running when it’s state is “running” and when it has at least one IP address assigned.
Parameters: - nodes (
listofNode) – List of nodes to wait for. - wait_period (
int) – How many seconds to wait between each loop iteration. (default is 3) - timeout (
int) – How many seconds to wait before giving up. (default is 600) - ssh_interface (
str) – Which attribute on the node to use to obtain an IP address. Valid options: public_ips, private_ips. Default is public_ips. - force_ipv4 (
bool) – Ignore IPv6 addresses (default is True). - ex_list_nodes_kwargs (
dict) – Optional driver-specific keyword arguments which are passed to thelist_nodesmethod.
Returns: [(Node, ip_addresses)]list of tuple of Node instance and list of ip_address on success.Return type: listoftuple- nodes (
- key (
