digitalocean package¶
Submodules¶
digitalocean.Account module¶
-
class
digitalocean.Account.Account(*args, **kwargs)¶ Bases:
digitalocean.baseapi.BaseAPI-
classmethod
get_object(api_token)¶ Class method that will return an Account object.
-
load()¶
-
classmethod
digitalocean.Action module¶
-
class
digitalocean.Action.Action(*args, **kwargs)¶ Bases:
digitalocean.baseapi.BaseAPI-
classmethod
get_object(api_token, action_id)¶ Class method that will return a Action object by ID.
-
load()¶
-
load_directly()¶
-
wait(update_every_seconds=1)¶ Wait until the action is marked as completed or with an error. It will return True in case of success, otherwise False.
- Optional Args:
- update_every_seconds - int : number of seconds to wait before
- checking if the action is completed.
-
classmethod
digitalocean.Domain module¶
-
class
digitalocean.Domain.Domain(*args, **kwargs)¶ Bases:
digitalocean.baseapi.BaseAPI-
create()¶ Create new doamin
-
create_new_domain_record(*args, **kwargs)¶ 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
-
destroy()¶ Destroy the domain by name
-
classmethod
get_object(api_token, domain_name)¶ Class method that will return a Domain object by ID.
-
get_records(params=None)¶ Returns a list of Record objects
-
load()¶
-
digitalocean.Droplet module¶
-
exception
digitalocean.Droplet.BadKernelObject¶
-
exception
digitalocean.Droplet.BadSSHKeyFormat¶
-
class
digitalocean.Droplet.Droplet(*args, **kwargs)¶ 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)¶ 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)¶ Create the droplet with object properties.
Note: Every argument and parameter given to this method will be assigned to the object.
-
classmethod
create_multiple(*args, **kwargs)¶
-
destroy()¶ Destroy the droplet
Returns dict
-
disable_backups(return_dict=True)¶ 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)¶ 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)¶ 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)¶ 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)¶ Returns a specific Action by its ID.
Parameters: action_id (int) – id of action
-
get_actions()¶ Returns a list of Action objects This actions can be used to check the droplet’s status
-
get_data(*args, **kwargs)¶ Customized version of get_data to perform __check_actions_in_data
-
get_events()¶ A helper function for backwards compatability. Calls get_actions()
-
get_kernel_available()¶ Get a list of kernels available
-
classmethod
get_object(api_token, droplet_id)¶ Class method that will return a Droplet object by ID.
Parameters:
-
get_snapshots()¶ This method will return the snapshots/images connected to that specific droplet.
-
load()¶ Fetch data about droplet - use this instead of get_data()
-
power_cycle(return_dict=True)¶ 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)¶ 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)¶ 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)¶ 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)¶ 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)¶ 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)¶ 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)¶ 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)¶ 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)¶ 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)¶ 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¶ Bases:
digitalocean.baseapi.ErrorBase exception class for this module
digitalocean.FloatingIP module¶
-
class
digitalocean.FloatingIP.FloatingIP(*args, **kwargs)¶ Bases:
digitalocean.baseapi.BaseAPI-
assign(droplet_id)¶ Assign a FloatingIP to a Droplet.
Parameters: droplet_id – int - droplet id
-
create(*args, **kwargs)¶ 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
-
destroy()¶ Destroy the FloatingIP
-
classmethod
get_object(api_token, ip)¶ Class method that will return a FloatingIP object by its IP.
Parameters: - api_token – str - token
- ip – str - floating ip address
-
load()¶ Load the FloatingIP object from DigitalOcean.
Requires self.ip to be set.
-
reserve(*args, **kwargs)¶ Creates a FloatingIP in a region without assigning it to a specific Droplet.
Note: Every argument and parameter given to this method will be assigned to the object.
Parameters: region_slug – str - region’s slug (e.g. ‘nyc3’)
-
unassign()¶ Unassign a FloatingIP.
-
digitalocean.Image module¶
digitalocean.Kernel module¶
-
class
digitalocean.Kernel.Kernel(*args, **kwargs)¶ 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)¶ Bases:
objectAn 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)¶ Bases:
objectAn 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)¶ Bases:
digitalocean.baseapi.BaseAPIAn 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)¶ Assign a LoadBalancer to a Droplet.
Parameters: (obj (droplet_ids) – list of int): A list of Droplet IDs
-
add_forwarding_rules(forwarding_rules)¶ Adds new forwarding rules to a LoadBalancer.
Parameters: (obj (forwarding_rules) – list): A list of ForwrdingRules objects
-
create(*args, **kwargs)¶ 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’)
-
destroy()¶ Destroy the LoadBalancer
-
classmethod
get_object(api_token, id)¶ Class method that will return a LoadBalancer object by its ID.
Parameters:
-
load()¶ Loads updated attributues for a LoadBalancer object.
Requires self.id to be set.
-
remove_droplets(droplet_ids)¶ Unassign a LoadBalancer.
Parameters: (obj (droplet_ids) – list of int): A list of Droplet IDs
-
remove_forwarding_rules(forwarding_rules)¶ Removes existing forwarding rules from a LoadBalancer.
Parameters: (obj (forwarding_rules) – list): A list of ForwrdingRules objects
digitalocean.Manager module¶
-
class
digitalocean.Manager.Manager(*args, **kwargs)¶ Bases:
digitalocean.baseapi.BaseAPI-
get_account()¶ Returns an Account object.
-
get_action(action_id)¶ Return an Action object by a specific ID.
-
get_all_certificates()¶ This function returns a list of Certificate objects.
-
get_all_domains()¶ This function returns a list of Domain object.
-
get_all_droplets(tag_name=None)¶ This function returns a list of Droplet object.
-
get_all_floating_ips()¶ This function returns a list of FloatingIP objects.
-
get_all_images()¶ This function returns a list of Image objects containing all available DigitalOcean images, both public and private.
-
get_all_load_balancers()¶ Returns a list of Load Balancer objects.
-
get_all_regions()¶ This function returns a list of Region object.
-
get_all_sizes()¶ This function returns a list of Size object.
-
get_all_sshkeys()¶ This function returns a list of SSHKey object.
-
get_all_volumes()¶ This function returns a list of Volume objects.
-
get_app_images()¶ This function returns a list of Image objectobjects representing public DigitalOcean ‘One-Click’ application images.
-
get_distro_images()¶ This function returns a list of Image objects representing public base distribution images.
-
get_domain(domain_name)¶ Return a Domain by its domain_name
-
get_droplet(droplet_id)¶ Return a Droplet by its ID.
-
get_floating_ip(ip)¶ Returns a of FloatingIP object by its IP address.
-
get_global_images()¶ This function returns a list of Image objects representing public DigitalOcean images (e.g. base distribution images and ‘One-Click’ applications).
-
get_image(image_id)¶ Return a Image by its ID.
-
get_images(private=False, type=None)¶ This function returns a list of Image object.
-
get_load_balancer(id)¶ Returns a Load Balancer object by its ID.
Parameters: id (str) – Load Balancer ID
-
get_my_images()¶ This function returns a list of Image objects representing private DigitalOcean images (e.g. snapshots and backups).
-
get_ssh_key(ssh_key_id)¶ Return a SSHKey object by its ID.
-
get_volume(volume_id)¶ Returns a Volume object by its ID.
-
digitalocean.Metadata module¶
-
class
digitalocean.Metadata.Metadata(*args, **kwargs)¶ Bases:
digitalocean.baseapi.BaseAPIMetadata 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'¶
-
get_data(url, headers={}, params={}, render_json=True)¶ Customized version of get_data to directly get the data without using the authentication method.
-
load()¶
-
digitalocean.Record module¶
-
class
digitalocean.Record.Record(domain_name=None, *args, **kwargs)¶ Bases:
digitalocean.baseapi.BaseAPI-
create()¶ Create a record for a domain
-
destroy()¶ Destroy the record
-
classmethod
get_object(api_token, domain, record_id)¶ Class method that will return a Record object by ID and the domain.
-
load()¶
-
save()¶ Save existing record
-
digitalocean.Region module¶
-
class
digitalocean.Region.Region(*args, **kwargs)¶ Bases:
digitalocean.baseapi.BaseAPI
digitalocean.SSHKey module¶
-
class
digitalocean.SSHKey.SSHKey(*args, **kwargs)¶ Bases:
digitalocean.baseapi.BaseAPI-
create()¶ Create the SSH Key
-
destroy()¶ Destroy the SSH Key
-
edit()¶ Edit the SSH Key
-
classmethod
get_object(api_token, ssh_key_id)¶ Class method that will return a SSHKey object by ID.
-
load()¶ Load the SSHKey object from DigitalOcean.
Requires either self.id or self.fingerprint to be set.
-
load_by_pub_key(public_key)¶ This method will laod a SSHKey object from DigitalOcean from a public_key. This method will avoid problem like uploading the same public_key twice.
-
digitalocean.Size module¶
-
class
digitalocean.Size.Size(*args, **kwargs)¶ Bases:
digitalocean.baseapi.BaseAPI
digitalocean.Tag module¶
-
class
digitalocean.Tag.Tag(*args, **kwargs)¶ Bases:
digitalocean.baseapi.BaseAPI-
add_droplets(droplet)¶ Add the Tag to a Droplet.
- Attributes accepted at creation time:
- droplet: array of string or array of int, or array of Droplets.
-
create(**kwargs)¶ Create the tag.
-
delete()¶
-
classmethod
get_object(api_token, tag_name)¶
-
load()¶ Fetch data about tag
-
remove_droplets(droplet)¶ Remove the Tag from the Droplet.
- Attributes accepted at creation time:
- droplet: array of string or array of int, or array of Droplets.
-
update_tag(name)¶
-
digitalocean.Volume module¶
-
class
digitalocean.Volume.Volume(*args, **kwargs)¶ Bases:
digitalocean.baseapi.BaseAPI-
attach(droplet_id, region)¶ Attach a Volume to a Droplet.
Parameters: - droplet_id – int - droplet id
- region – string - slug identifier for the region
-
create(*args, **kwargs)¶ 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
-
destroy()¶ Destroy a volume
-
detach(droplet_id, region)¶ 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)¶ Class method that will return an Volume object by ID.
-
load()¶
-
resize(size_gigabytes, region)¶ Detach a Volume to a Droplet.
Parameters: - size_gigabytes – int - size of the Block Storage volume in GiB
- region – string - slug identifier for the region
-
digitalocean.baseapi module¶
-
class
digitalocean.baseapi.BaseAPI(*args, **kwargs)¶ Bases:
objectBasic api class for
-
end_point= 'https://api.digitalocean.com/v2/'¶
-
get_data(url, type='GET', params=None)¶ 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()¶ 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¶ Bases:
digitalocean.baseapi.Error
-
exception
digitalocean.baseapi.Error¶ Bases:
exceptions.ExceptionBase exception class for this module
-
exception
digitalocean.baseapi.JSONReadError¶ Bases:
digitalocean.baseapi.Error
-
exception
digitalocean.baseapi.NotFoundError¶ Bases:
digitalocean.baseapi.Error
-
exception
digitalocean.baseapi.TokenError¶ Bases:
digitalocean.baseapi.Error
Module contents¶
digitalocean API to manage droplets