digitalocean package¶
Submodules¶
digitalocean.Account module¶
digitalocean.Action module¶
-
class
digitalocean.Action.
Action
(*args, **kwargs)[source]¶ Bases:
digitalocean.baseapi.BaseAPI
digitalocean.Domain module¶
-
class
digitalocean.Domain.
Domain
(*args, **kwargs)[source]¶ Bases:
digitalocean.baseapi.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
-
digitalocean.Droplet module¶
-
class
digitalocean.Droplet.
Droplet
(*args, **kwargs)[source]¶ Bases:
digitalocean.baseapi.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 keys - backups (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 volumes - monitoring – (bool) - True if installing the DigitalOcean monitoring agent
- Attributes returned by API:
id (int): droplet id memory (str): memory size vcpus (int): number of vcpus disk (int): disk size in GB status (str): status 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 droplet snapshot_ids (int
, optional): list of ids of snapshots of this droplet action_ids (int
, optional): list of ids of actions features (str
, optional): list of enabled features. e.g.[u’private_networking’, u’virtio’]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 assigned end_point (str): url of api endpoint used volume_ids (str
, optional): list of blockstorage volumes
-
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.baseapi.Error
Base exception class for this module
digitalocean.FloatingIP module¶
-
class
digitalocean.FloatingIP.
FloatingIP
(*args, **kwargs)[source]¶ Bases:
digitalocean.baseapi.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.BaseAPI
-
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.
-
classmethod
digitalocean.Kernel module¶
-
class
digitalocean.Kernel.
Kernel
(*args, **kwargs)[source]¶ Bases:
digitalocean.baseapi.BaseAPI
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.BaseAPI
An object representing an DigitalOcean Load Balancer.
Attributes accepted at creation time:
- Args:
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”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 (mutually exclusive with ‘tag’)
- tag (str): A string representing a DigitalOcean Droplet tag
- (mutually exclusive with ‘droplet_ids’)
- 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
-
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’)
-
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.
StickySesions
(type='none', cookie_name='', cookie_ttl_seconds=None)[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.BaseAPI
-
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.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.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¶
-
class
digitalocean.Region.
Region
(*args, **kwargs)[source]¶ Bases:
digitalocean.baseapi.BaseAPI
digitalocean.SSHKey module¶
-
class
digitalocean.SSHKey.
SSHKey
(*args, **kwargs)[source]¶ Bases:
digitalocean.baseapi.BaseAPI
-
classmethod
get_object
(api_token, ssh_key_id)[source]¶ Class method that will return a SSHKey object by ID.
-
classmethod
digitalocean.Size module¶
-
class
digitalocean.Size.
Size
(*args, **kwargs)[source]¶ Bases:
digitalocean.baseapi.BaseAPI
digitalocean.Tag module¶
-
class
digitalocean.Tag.
Tag
(*args, **kwargs)[source]¶ Bases:
digitalocean.baseapi.BaseAPI
digitalocean.Volume module¶
-
class
digitalocean.Volume.
Volume
(*args, **kwargs)[source]¶ Bases:
digitalocean.baseapi.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
- Optional Args:
- description: string - text field to describe a 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¶
-
class
digitalocean.baseapi.
BaseAPI
(*args, **kwargs)[source]¶ Bases:
object
Basic api class for
-
end_point
= 'https://api.digitalocean.com/v2/'¶
-
get_data
(url, type='GET', params=None)[source]¶ This method is a basic implementation of __call_api that checks errors too. In case of success the method will return True or the content of the response to the request.
Pagination is automatically detected and handled accordingly
-
get_timeout
()[source]¶ Checks if any timeout for the requests to DigitalOcean is required. To set a timeout, use the REQUEST_TIMEOUT_ENV_VAR environment variable.
-
token
= ''¶
-
-
exception
digitalocean.baseapi.
DataReadError
[source]¶ Bases:
digitalocean.baseapi.Error
-
exception
digitalocean.baseapi.
Error
[source]¶ Bases:
exceptions.Exception
Base exception class for this module
-
exception
digitalocean.baseapi.
JSONReadError
[source]¶ Bases:
digitalocean.baseapi.Error
-
exception
digitalocean.baseapi.
NotFoundError
[source]¶ Bases:
digitalocean.baseapi.Error
-
exception
digitalocean.baseapi.
TokenError
[source]¶ Bases:
digitalocean.baseapi.Error
Module contents¶
digitalocean API to manage droplets