libcloud.compute.drivers.digitalocean module

DigitalOcean Driver

class libcloud.compute.drivers.digitalocean.DigitalOceanNodeDriver(key, secret=None, api_version='v2', **kwargs)[source]

Bases: NodeDriver

DigitalOcean NodeDriver defaulting to using APIv2.

Parameters:
  • key (str) – Personal Access Token required for authentication.

  • secret (str) – Previously used with API version v1. (deprecated)

  • api_version (str) – Specifies the API version to use. Defaults to using v2, currently the only valid option. (optional)

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

  • secret – 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 – 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 = 'DigitalOcean'
type: Provider | str = 'digitalocean'
website: str = 'https://www.digitalocean.com'
class libcloud.compute.drivers.digitalocean.DigitalOcean_v2_NodeDriver(key, secret=None, api_version='v2', **kwargs)[source]

Bases: DigitalOcean_v2_BaseDriver, DigitalOceanNodeDriver

DigitalOcean NodeDriver using v2 of the API.

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 = ['backups', 'ipv6', 'private_networking', 'tags', 'ssh_keys']
NODE_STATE_MAP: Dict[str, NodeState] = {'active': NodeState.RUNNING, 'archive': NodeState.TERMINATED, 'new': NodeState.PENDING, 'off': NodeState.STOPPED}
attach_volume(node, volume, device=None)[source]

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

create_image(node, name)[source]

Create an image from a Node.

@inherits: NodeDriver.create_image

Parameters:
  • node (str) – Node to use as base for image

  • node – Name for image

Return type:

bool

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

Create a new SSH key.

Parameters:
  • name (str) – Key name (required)

  • public_key (str) – Valid public key string (required)

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

Create a node.

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

  • backups: bool defaults to False

  • ipv6: bool defaults to False

  • private_networking: bool defaults to False

  • tags: list of str tags

  • user_data: str for cloud-config data

  • ssh_keys: list of int key ids or str fingerprints

ex_create_attr[‘ssh_keys’] will override ex_ssh_key_ids assignment.

Parameters:
  • ex_create_attr (dict) – A dictionary of optional attributes for droplet creation

  • ex_ssh_key_ids (list of int key ids or str key fingerprints) – A list of ssh key ids which will be added to the server. (optional)

  • ex_user_data (str) – User data to be added to the node on create. (optional)

Returns:

The newly created node.

Return type:

Node

create_volume(size, name, location=None, snapshot=None)[source]

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

create_volume_snapshot(volume, name)[source]

Create a new volume snapshot.

Parameters:

volume (class:StorageVolume) – Volume to create a snapshot for

Returns:

The newly created volume snapshot.

Return type:

VolumeSnapshot

delete_image(image)[source]

Delete an image for node.

@inherits: NodeDriver.delete_image

Parameters:

image (NodeImage) – the image to be deleted

Return type:

bool

delete_key_pair(key)[source]

Delete an existing SSH key.

Parameters:

key (KeyPair) – SSH key (required)

delete_volume_snapshot(snapshot)[source]

Delete a volume snapshot

Parameters:

snapshot (class:VolumeSnapshot) – volume snapshot to delete

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

destroy_volume(volume)[source]

Destroys a storage volume.

Parameters:

volume (StorageVolume) – Volume to be destroyed

Return type:

bool

detach_volume(volume)[source]

Detaches a volume from a node.

Parameters:

volume (StorageVolume) – Volume to be detached

Return type:

bool

ex_attach_floating_ip_to_node(node, ip)[source]

Attach the floating IP to the node

Parameters:
  • node (Node) – node

  • ip (str or DigitalOcean_v2_FloatingIpAddress) – floating IP to attach

Return type:

bool

ex_change_kernel(node, kernel_id)[source]
ex_create_floating_ip(location)[source]

Create new floating IP reserved to a region.

The newly created floating IP will not be associated to a Droplet.

See https://developers.digitalocean.com/documentation/v2/#floating-ips

Parameters:

location (NodeLocation) – Which data center to create the floating IP in.

Return type:

DigitalOcean_v2_FloatingIpAddress

ex_delete_floating_ip(ip)[source]

Delete specified floating IP

Parameters:

ip (DigitalOcean_v2_FloatingIpAddress) – floating IP to remove

Return type:

bool

ex_detach_floating_ip_from_node(node, ip)[source]

Detach a floating IP from the given node

Note: the ‘node’ object is not used in this method but it is added to the signature of ex_detach_floating_ip_from_node anyway so it conforms to the interface of the method of the same name for other drivers like for example OpenStack.

Parameters:
  • node (Node) – Node from which the IP should be detached

  • ip (DigitalOcean_v2_FloatingIpAddress) – Floating IP to detach

Return type:

bool

ex_enable_ipv6(node)[source]
ex_get_floating_ip(ip)[source]

Get specified floating IP

Parameters:

ip (str) – floating IP to get

Return type:

DigitalOcean_v2_FloatingIpAddress

ex_get_node_details(node_id)[source]

Lists details of the specified server.

Parameters:

node_id (str) – ID of the node which should be used

Return type:

Node

ex_hard_reboot(node)[source]
ex_list_floating_ips()[source]

List floating IPs

Return type:

list of DigitalOcean_v2_FloatingIpAddress

ex_power_on_node(node)[source]
ex_rebuild_node(node)[source]

Destroy and rebuild the node using its base image.

Parameters:

node (Node) – Node to rebuild

:return True if the operation began successfully :rtype bool

ex_rename_node(node, name)[source]
ex_resize_node(node, size)[source]

Resize the node to a different machine size. Note that some resize operations are reversible, and others are irreversible.

Parameters:
  • node (NodeSize) – Node to rebuild

  • size – New size for this machine

:return True if the operation began successfully :rtype bool

ex_shutdown_node(node)[source]
get_image(image_id)[source]

Get an image based on an image_id

@inherits: NodeDriver.get_image

Parameters:

image_id (int) – Image identifier

Returns:

A NodeImage object

Return type:

NodeImage

get_key_pair(name)[source]

Retrieve a single key pair.

Parameters:

name (str) – Name of the key pair to retrieve.

Return type:

KeyPair

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.

Returns:

Available SSH keys.

Return type:

list of KeyPair

list_locations(ex_available=True)[source]

List locations

Parameters:

ex_available – Only return locations which are available.

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

list_volume_snapshots(volume)[source]

List snapshots for a volume.

Parameters:

volume (class:StorageVolume) – Volume to list snapshots for

Returns:

List of volume snapshots.

Return type:

list of :class: StorageVolume

list_volumes()[source]

List storage volumes.

Return type:

list of StorageVolume

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