digitalocean package¶
Submodules¶
digitalocean.Account module¶
digitalocean.Action module¶
digitalocean.Domain module¶
-
class
digitalocean.Domain.
Domain
(*args, **kwargs)[source]¶ Bases:
digitalocean.BaseAPI
-
create_new_domain_record
(*args, **kwargs)[source]¶ Create new domain record. https://developers.digitalocean.com/#create-a-new-domain-record
- Parameters
type – The record type (A, MX, CNAME, etc).
name – The host name, alias, or service being defined by the record
data – Variable data depending on record type.
- Optional Args:
priority: The priority of the host port: The port that the service is accessible on weight: The weight of records with the same priority ttl: This value is the time to live for the record, in seconds. flags: An unsigned integer between 0-255 used for CAA records. tag: The parameter tag for CAA records. Valid values are “issue”,
“issuewild”, or “iodef”.
-
digitalocean.Droplet module¶
-
class
digitalocean.Droplet.
Droplet
(*args, **kwargs)[source]¶ Bases:
digitalocean.BaseAPI
Droplet management
Attributes accepted at creation time:
- Parameters
name (str) – name
size_slug (str) – droplet size
image (str) – image name to use to create droplet
region (str) – region
ssh_keys (
str
, optional) – list of ssh keysbackups (bool) – True if backups enabled
ipv6 (bool) – True if ipv6 enabled
private_networking (bool) – True if private networking enabled
user_data (str) – arbitrary data to pass to droplet
volumes (
str
, optional) – list of blockstorage volumesmonitoring (bool) – True if installing the DigitalOcean monitoring agent
vpc_uuid (str, optional) – ID of a VPC in which the Droplet will be created
- Attributes returned by API:
id (int): droplet id
memory (str): memory size
vcpus (int): number of vcpus
disk (int): disk size in GB
locked (bool): True if locked
created_at (str): creation date in format u’2014-11-06T10:42:09Z’
status (str): status, e.g. ‘new’, ‘active’, etc
networks (dict): details of connected networks
kernel (dict): details of kernel
backup_ids (
int
, optional): list of ids of backups of this dropletsnapshot_ids (
int
, optional): list of ids of snapshots of this dropletaction_ids (
int
, optional): list of ids of actions- features (
str
, optional): list of enabled features. e.g. [u’private_networking’, u’virtio’]
- features (
image (dict): details of image used to create this droplet
ip_address (str): public ip addresses
private_ip_address (str): private ip address
ip_v6_address (
str
, optional): list of ipv6 addresses assignedend_point (str): url of api endpoint used
volume_ids (
str
, optional): list of blockstorage volumesvpc_uuid (str, optional): ID of the VPC that the Droplet is assigned to
-
change_kernel
(kernel, return_dict=True)[source]¶ Change the kernel to a new one
- Parameters
kernel – instance of digitalocean.Kernel.Kernel
- Optional Args:
- return_dict (bool): Return a dict when True (default),
otherwise return an Action.
Returns dict or Action
-
create
(*args, **kwargs)[source]¶ Create the droplet with object properties.
Note: Every argument and parameter given to this method will be assigned to the object.
-
disable_backups
(return_dict=True)[source]¶ Disable automatic backups
- Optional Args:
- return_dict (bool): Return a dict when True (default),
otherwise return an Action.
Returns dict or Action
-
enable_backups
(return_dict=True)[source]¶ Enable automatic backups
- Optional Args:
- return_dict (bool): Return a dict when True (default),
otherwise return an Action.
Returns dict or Action
-
enable_ipv6
(return_dict=True)[source]¶ Enable IPv6 on an existing Droplet where available.
- Optional Args:
- return_dict (bool): Return a dict when True (default),
otherwise return an Action.
Returns dict or Action
-
enable_private_networking
(return_dict=True)[source]¶ Enable private networking on an existing Droplet where available.
- Optional Args:
- return_dict (bool): Return a dict when True (default),
otherwise return an Action.
Returns dict or Action
-
get_action
(action_id)[source]¶ Returns a specific Action by its ID.
- Parameters
action_id (int) – id of action
-
get_actions
()[source]¶ Returns a list of Action objects This actions can be used to check the droplet’s status
-
get_data
(*args, **kwargs)[source]¶ Customized version of get_data to perform __check_actions_in_data
-
classmethod
get_object
(api_token, droplet_id)[source]¶ Class method that will return a Droplet object by ID.
- Parameters
api_token (str) – token
droplet_id (int) – droplet id
-
get_snapshots
()[source]¶ This method will return the snapshots/images connected to that specific droplet.
-
power_cycle
(return_dict=True)[source]¶ restart the droplet
- Optional Args:
- return_dict (bool): Return a dict when True (default),
otherwise return an Action.
Returns dict or Action
-
power_off
(return_dict=True)[source]¶ restart the droplet
- Optional Args:
- return_dict (bool): Return a dict when True (default),
otherwise return an Action.
Returns dict or Action
-
power_on
(return_dict=True)[source]¶ Boot up the droplet
- Optional Args:
- return_dict (bool): Return a dict when True (default),
otherwise return an Action.
Returns dict or Action
-
reboot
(return_dict=True)[source]¶ restart the droplet
- Optional Args:
- return_dict (bool): Return a dict when True (default),
otherwise return an Action.
Returns dict or Action
-
rebuild
(image_id=None, return_dict=True)[source]¶ Restore the droplet to an image ( snapshot or backup )
- Parameters
image_id (int) – id of image
- Optional Args:
- return_dict (bool): Return a dict when True (default),
otherwise return an Action.
Returns dict or Action
-
rename
(name, return_dict=True)[source]¶ Rename the droplet
- Parameters
name (str) – new name
- Optional Args:
- return_dict (bool): Return a dict when True (default),
otherwise return an Action.
Returns dict or Action
-
reset_root_password
(return_dict=True)[source]¶ reset the root password
- Optional Args:
- return_dict (bool): Return a dict when True (default),
otherwise return an Action.
Returns dict or Action
-
resize
(new_size_slug, return_dict=True, disk=True)[source]¶ Resize the droplet to a new size slug. https://developers.digitalocean.com/documentation/v2/#resize-a-droplet
- Parameters
new_size_slug (str) – name of new size
- Optional Args:
return_dict (bool): Return a dict when True (default), otherwise return an Action. disk (bool): If a permanent resize, with disk changes included.
Returns dict or Action
-
restore
(image_id, return_dict=True)[source]¶ Restore the droplet to an image ( snapshot or backup )
- Parameters
image_id (int) – id of image
- Optional Args:
- return_dict (bool): Return a dict when True (default),
otherwise return an Action.
Returns dict or Action
-
shutdown
(return_dict=True)[source]¶ shutdown the droplet
- Optional Args:
- return_dict (bool): Return a dict when True (default),
otherwise return an Action.
Returns dict or Action
-
take_snapshot
(snapshot_name, return_dict=True, power_off=False)[source]¶ Take a snapshot!
- Parameters
snapshot_name (str) – name of snapshot
- Optional Args:
- return_dict (bool): Return a dict when True (default),
otherwise return an Action.
- power_off (bool): Before taking the snapshot the droplet will be
turned off with another API call. It will wait until the droplet will be powered off.
Returns dict or Action
-
exception
digitalocean.Droplet.
DropletError
[source]¶ Bases:
digitalocean.Error
Base exception class for this module
digitalocean.FloatingIP module¶
-
class
digitalocean.FloatingIP.
FloatingIP
(*args, **kwargs)[source]¶ Bases:
digitalocean.BaseAPI
-
assign
(droplet_id)[source]¶ Assign a FloatingIP to a Droplet.
- Parameters
droplet_id – int - droplet id
-
create
(*args, **kwargs)[source]¶ Creates a FloatingIP and assigns it to a Droplet.
Note: Every argument and parameter given to this method will be assigned to the object.
- Parameters
droplet_id – int - droplet id
-
classmethod
get_object
(api_token, ip)[source]¶ Class method that will return a FloatingIP object by its IP.
- Parameters
api_token – str - token
ip – str - floating ip address
-
digitalocean.Image module¶
-
class
digitalocean.Image.
Image
(*args, **kwargs)[source]¶ Bases:
digitalocean.BaseAPI
An object representing an DigitalOcean Image.
Attributes accepted at creation time:
- Parameters
name (str) – The name to be given to an image.
url (str) – A URL from which the virtual machine image may be retrieved.
region (str) – The slug of the region where the image will be available.
distribution (str, optional) – The name of the image’s distribution.
description (str, optional) – Free-form text field to describe an image.
(obj (tags) – list of str, optional): List of tag names to apply to the image.
- Attributes returned by API:
id (int): A unique number to identify and reference a image.
name (str): The display name given to an image.
- type (str): The kind of image. This will be either “snapshot”,
“backup”, or “custom”.
distribution (str): The name of the image’s distribution.
slug (str): A uniquely identifying string that is associated with each of the DigitalOcean-provided public images.
public (bool): Indicates whether the image is public or not.
regions (obj:list of str): A list of the slugs of the regions where the image is available for use.
created_at (str): A time value given in ISO8601 combined date and time format that represents when the image was created.
min_disk_size (int): The minimum disk size in GB required for a Droplet to use this image.
size_gigabytes (int): The size of the image in gigabytes.
description (str): Free-form text field to describing an image.
tags (obj:list of str): List of tag names to applied to the image.
status (str): Indicates the state of a custom image. This may be “NEW”, “available”, “pending”, or “deleted”.
error_message (str): Information about errors that may occur when importing a custom image.
-
create
()[source]¶ Creates a new custom DigitalOcean Image from the Linux virtual machine image located at the provided url.
-
classmethod
get_object
(api_token, image_id_or_slug)[source]¶ Class method that will return an Image object by ID or slug.
This method is used to validate the type of the image. If it is a number, it will be considered as an Image ID, instead if it is a string, it will considered as slug.
digitalocean.Kernel module¶
digitalocean.LoadBalancer module¶
-
class
digitalocean.LoadBalancer.
ForwardingRule
(entry_protocol=None, entry_port=None, target_protocol=None, target_port=None, certificate_id='', tls_passthrough=False)[source]¶ Bases:
object
An object holding information about a LoadBalancer forwarding rule setting.
- Parameters
entry_protocol (str) – The protocol used for traffic to a LoadBalancer. The possible values are: “http”, “https”, or “tcp”
entry_port (int) – The port the LoadBalancer instance will listen on
target_protocol (str) – The protocol used for traffic from a LoadBalancer to the backend Droplets. The possible values are: “http”, “https”, or “tcp”
target_port (int) – The port on the backend Droplets on which the LoadBalancer will send traffic
certificate_id (str, optional) – The ID of the TLS certificate used for SSL termination if enabled
tls_passthrough (bool, optional) – A boolean indicating if SSL encrypted traffic will be passed through to the backend Droplets
-
class
digitalocean.LoadBalancer.
HealthCheck
(protocol='http', port=80, path='/', check_interval_seconds=10, response_timeout_seconds=5, healthy_threshold=5, unhealthy_threshold=3)[source]¶ Bases:
object
An object holding information about a LoadBalancer health check settings.
- Parameters
protocol (str) – The protocol used for health checks. The possible values are “http” or “tcp”.
port (int) – The port on the backend Droplets for heath checks
path (str) – The path to send a health check request to
check_interval_seconds (int) – The number of seconds between between two consecutive health checks
response_timeout_seconds (int) – The number of seconds the Load Balancer instance will wait for a response until marking a check as failed
healthy_threshold (int) – The number of times a health check must fail for a backend Droplet to be removed from the pool
unhealthy_threshold (int) – The number of times a health check must pass for a backend Droplet to be re-added to the pool
-
class
digitalocean.LoadBalancer.
LoadBalancer
(*args, **kwargs)[source]¶ Bases:
digitalocean.BaseAPI
An object representing an DigitalOcean Load Balancer.
Attributes accepted at creation time:
- Parameters
name (str) – The Load Balancer’s name
region (str) – The slug identifier for a DigitalOcean region
algorithm (str, optional) – The load balancing algorithm to be used. Currently, it must be either “round_robin” or “least_connections”
(obj (droplet_ids) – list): A list of ForwrdingRules objects
health_check (obj, optional) – A HealthCheck object
sticky_sessions (obj, optional) – A StickySessions object
redirect_http_to_https (bool, optional) – A boolean indicating whether HTTP requests to the Load Balancer should be redirected to HTTPS
(obj – list of int): A list of IDs representing Droplets to be added to the Load Balancer (mutually exclusive with ‘tag’)
tag (str) – A string representing a DigitalOcean Droplet tag (mutually exclusive with ‘droplet_ids’)
vpc_uuid (str) – ID of a VPC in which the Load Balancer will be created
- Attributes returned by API:
name (str): The Load Balancer’s name
id (str): An unique identifier for a LoadBalancer
ip (str): Public IP address for a LoadBalancer
region (str): The slug identifier for a DigitalOcean region
algorithm (str, optional): The load balancing algorithm to be used. Currently, it must be either “round_robin” or “least_connections”
forwarding_rules (obj:list): A list of ForwrdingRules objects
health_check (obj, optional): A HealthCheck object
sticky_sessions (obj, optional): A StickySessions object
redirect_http_to_https (bool, optional): A boolean indicating whether HTTP requests to the Load Balancer should be redirected to HTTPS
droplet_ids (obj:list of int): A list of IDs representing Droplets to be added to the Load Balancer
tag (str): A string representing a DigitalOcean Droplet tag
status (string): An indication the current state of the LoadBalancer
created_at (str): The date and time when the LoadBalancer was created
vpc_uuid (str): ID of a VPC which the Load Balancer is assigned to
-
add_droplets
(droplet_ids)[source]¶ Assign a LoadBalancer to a Droplet.
- Parameters
(obj (droplet_ids) – list of int): A list of Droplet IDs
-
add_forwarding_rules
(forwarding_rules)[source]¶ Adds new forwarding rules to a LoadBalancer.
- Parameters
(obj (forwarding_rules) – list): A list of ForwrdingRules objects
-
create
(*args, **kwargs)[source]¶ Creates a new LoadBalancer.
Note: Every argument and parameter given to this method will be assigned to the object.
- Parameters
name (str) – The Load Balancer’s name
region (str) – The slug identifier for a DigitalOcean region
algorithm (str, optional) – The load balancing algorithm to be used. Currently, it must be either “round_robin” or “least_connections”
(obj (droplet_ids) – list): A list of ForwrdingRules objects
health_check (obj, optional) – A HealthCheck object
sticky_sessions (obj, optional) – A StickySessions object
redirect_http_to_https (bool, optional) – A boolean indicating whether HTTP requests to the Load Balancer should be redirected to HTTPS
(obj – list of int): A list of IDs representing Droplets to be added to the Load Balancer (mutually exclusive with ‘tag’)
tag (str) – A string representing a DigitalOcean Droplet tag (mutually exclusive with ‘droplet_ids’)
vpc_uuid (str) – ID of a Load Balancer in which the Droplet will be created
-
classmethod
get_object
(api_token, id)[source]¶ Class method that will return a LoadBalancer object by its ID.
- Parameters
api_token (str) – DigitalOcean API token
id (str) – Load Balancer ID
-
remove_droplets
(droplet_ids)[source]¶ Unassign a LoadBalancer.
- Parameters
(obj (droplet_ids) – list of int): A list of Droplet IDs
-
class
digitalocean.LoadBalancer.
StickySessions
(type='none', cookie_name='', cookie_ttl_seconds=None, **kwargs)[source]¶ Bases:
object
An object holding information on a LoadBalancer’s sticky sessions settings.
- Parameters
type (str) – The type of sticky sessions used. Can be “cookies” or “none”
cookie_name (str, optional) – The name used for the client cookie when using cookies for sticky session
cookie_ttl_seconds (int, optional) – The number of seconds until the cookie expires
digitalocean.Manager module¶
-
class
digitalocean.Manager.
Manager
(*args, **kwargs)[source]¶ Bases:
digitalocean.BaseAPI
-
get_all_droplets
(params=None, tag_name=None)[source]¶ This function returns a list of Droplet object.
-
get_all_images
()[source]¶ This function returns a list of Image objects containing all available DigitalOcean images, both public and private.
This method returns a list of all tags.
-
get_app_images
()[source]¶ This function returns a list of Image objectobjects representing public DigitalOcean ‘One-Click’ application images.
-
get_certificate
(id)[source]¶ Returns a Certificate object by its ID.
- Parameters
id (str) – Certificate ID
-
get_distro_images
()[source]¶ This function returns a list of Image objects representing public base distribution images.
-
get_global_images
()[source]¶ This function returns a list of Image objects representing public DigitalOcean images (e.g. base distribution images and ‘One-Click’ applications).
-
get_load_balancer
(id)[source]¶ Returns a Load Balancer object by its ID.
- Parameters
id (str) – Load Balancer ID
-
digitalocean.Metadata module¶
-
class
digitalocean.Metadata.
Metadata
(*args, **kwargs)[source]¶ Bases:
digitalocean.BaseAPI
Metadata API: Provide useful information about the current Droplet. See: https://developers.digitalocean.com/metadata/#introduction
-
droplet_id
= None¶
-
end_point
= 'http://169.254.169.254/metadata/v1'¶
-
digitalocean.Record module¶
-
class
digitalocean.Record.
Record
(domain_name=None, *args, **kwargs)[source]¶ Bases:
digitalocean.BaseAPI
An object representing an DigitalOcean Domain Record.
- Parameters
type (str) – The type of the DNS record (e.g. A, CNAME, TXT).
name (str) – The host name, alias, or service being defined by the record.
data (int) – Variable data depending on record type.
priority (int) – The priority for SRV and MX records.
port (int) – The port for SRV records.
ttl (int) – The time to live for the record, in seconds.
weight (int) – The weight for SRV records.
flags (int) – An unsigned integer between 0-255 used for CAA records.
tags (string) – The parameter tag for CAA records. Valid values are “issue”, “wildissue”, or “iodef”
-
create
()[source]¶ Creates a new record for a domain.
- Parameters
type (str) – The type of the DNS record (e.g. A, CNAME, TXT).
name (str) – The host name, alias, or service being defined by the record.
data (int) – Variable data depending on record type.
priority (int) – The priority for SRV and MX records.
port (int) – The port for SRV records.
ttl (int) – The time to live for the record, in seconds.
weight (int) – The weight for SRV records.
flags (int) – An unsigned integer between 0-255 used for CAA records.
tags (string) – The parameter tag for CAA records. Valid values are “issue”, “wildissue”, or “iodef”
digitalocean.Region module¶
digitalocean.SSHKey module¶
-
class
digitalocean.SSHKey.
SSHKey
(*args, **kwargs)[source]¶ Bases:
digitalocean.BaseAPI
-
classmethod
get_object
(api_token, ssh_key_id)[source]¶ Class method that will return a SSHKey object by ID.
-
classmethod
digitalocean.Size module¶
digitalocean.Tag module¶
-
class
digitalocean.Tag.
Tag
(*args, **kwargs)[source]¶ Bases:
digitalocean.BaseAPI
-
add_droplets
(droplet)[source]¶ Add the Tag to a Droplet.
- Attributes accepted at creation time:
droplet: array of string or array of int, or array of Droplets.
-
add_snapshots
(snapshots)[source]¶ Add the Tag to the Snapshot.
- Attributes accepted at creation time:
snapshots: array of string or array of int or array of Snapshot.
-
digitalocean.Volume module¶
-
class
digitalocean.Volume.
Volume
(*args, **kwargs)[source]¶ Bases:
digitalocean.BaseAPI
-
attach
(droplet_id, region)[source]¶ Attach a Volume to a Droplet.
- Parameters
droplet_id – int - droplet id
region – string - slug identifier for the region
-
create
(*args, **kwargs)[source]¶ Creates a Block Storage volume
Note: Every argument and parameter given to this method will be assigned to the object.
- Parameters
name – string - a name for the volume
region – string - slug identifier for the region
size_gigabytes – int - size of the Block Storage volume in GiB
filesystem_type – string, optional - name of the filesystem type the volume will be formatted with (‘ext4’ or ‘xfs’)
filesystem_label – string, optional - the label to be applied to the filesystem, only used in conjunction with filesystem_type
- Optional Args:
description: string - text field to describe a volume tags: List[string], optional - the tags to be applied to the volume
-
create_from_snapshot
(*args, **kwargs)[source]¶ Creates a Block Storage volume
Note: Every argument and parameter given to this method will be assigned to the object.
- Parameters
name – string - a name for the volume
snapshot_id – string - unique identifier for the volume snapshot
size_gigabytes – int - size of the Block Storage volume in GiB
filesystem_type – string, optional - name of the filesystem type the volume will be formatted with (‘ext4’ or ‘xfs’)
filesystem_label – string, optional - the label to be applied to the filesystem, only used in conjunction with filesystem_type
- Optional Args:
description: string - text field to describe a volume tags: List[string], optional - the tags to be applied to the volume
-
detach
(droplet_id, region)[source]¶ Detach a Volume to a Droplet.
- Parameters
droplet_id – int - droplet id
region – string - slug identifier for the region
-
classmethod
get_object
(api_token, volume_id)[source]¶ Class method that will return an Volume object by ID.
-
digitalocean.baseapi module¶
Module contents¶
digitalocean API to manage droplets
-
exception
digitalocean.
DataReadError
¶ Bases:
digitalocean.Error
-
exception
digitalocean.
EndPointError
¶ Bases:
digitalocean.Error
-
exception
digitalocean.
Error
¶ Bases:
Exception
Base exception class for this module
-
exception
digitalocean.
NotFoundError
¶ Bases:
digitalocean.Error
-
exception
digitalocean.
TokenError
¶ Bases:
digitalocean.Error