Welcome to doapi’s documentation!¶
Contents:
Library¶
Introduction¶
Todo
Organize this better
Todo
Document potential weirdness when accessing doapi.last_*
while a
generator is being evaluated
Under normal circumstances, the fetch
and fetch_all_*
methods of a
resource will only raise a DOAPIError
if the resource no longer exists.
Generators producing objects always yield them in whatever order the API endpoint returns them in.
If you want all paginated results to be fetched at once, wrap the generator in
list()
.
Passing objects produced by one doapi
object to methods of another results in
undefined behavior.
Resource Objects¶
Todo
Document doapi_manager
, dict/mapping methods, and conversion to a dict
Document that you can copy a Resource object by passing it to the constructor for its class?
Instances of classes representing DigitalOcean API resources — i.e., Account
,
Action
, BackupWindow
, Domain
, DomainRecord
, Droplet
, FloatingIP
,
Image
, Kernel
, NetworkInterface
, Networks
, Region
, SSHKey
, Size
,
and Tag
— make their API fields available in three different ways:
- as regular object attributes:
droplet.id
- via indexing:
droplet["id"]
- via indexing the
fields
dictionary attribute:droplet.fields["id"]
Modifying a resource object’s fields only affects your local copy of the resource’s data; to actually modify the resource on DigitalOcean’s servers, call one of the object’s methods.
Note that calling a mutating method on a resource object simply sends a request
to the API endpoint and does not modify the local Python object. To get the
most up-to-date information on a resource, you must call the resource object’s
fetch
method to acquire a new object.
Note that resource objects have whatever attributes the API returns them with,
which may or may not be the same set of attributes as the documentation says
they should have. Also note that only documented attributes are ever converted
to custom classes; e.g., if the API suddenly returns an SSH key with a
"region"
field, the region data will be left as a dict
rather than
converted to a Region
.
All resource objects have the following method:
-
Resource.
for_json
()[source]¶ New in version 0.2.0.
Recursively convert the resource and its attributes to values suitable for direct JSONification. This method is primarily intended for use by
simplejson.dump()
.Return type: dict
doapi Class¶
-
class
doapi.
doapi
(api_token, endpoint='https://api.digitalocean.com', timeout=None, wait_interval=2, wait_time=None, per_page=None)[source]¶ The primary class for interacting with the DigitalOcean API, used for creating and fetching resources. The resource objects returned by these methods have methods of their own for manipulating them individually.
Parameters: - api_token (str) – the API token to use for authentication
- endpoint (string) – the URL relative to which requests will be made
- timeout (float, tuple, or
None
) – thetimeout
value to use when making requests - wait_interval (number) – the default number of seconds that “wait” operations will sleep for between requests
- wait_time – the default number of seconds after which “wait”
operations will return, or
None
or a negative number to wait indefinitely - per_page (integer or
None
) – the default number of objects thatpaginate()
will fetch on each request, orNone
to leave unspecified
-
DEFAULT_ENDPOINT
= 'https://api.digitalocean.com'¶ The official DigitalOcean API endpoint
-
api_token
= None¶ The API token used for authentication
-
endpoint
= None¶ The API endpoint URL relative to which requests will be made
-
timeout
= None¶ The
timeout
value to use when making requests; see the requests documentation for more information
-
wait_interval
= None¶ The default number of seconds that
wait_droplets()
,wait_actions()
, and thewait
methods ofAction
,Droplet
,FloatingIP
, andImage
will sleep for between requests
-
wait_time
= None¶ The default number of seconds after which “wait” operations will return, or
None
or a negative number to wait indefinitely
-
per_page
= None¶ The default number of objects that
paginate()
will fetch on each request, orNone
to leave unspecified
-
last_response
= None¶ The
requests.Response
object returned for the most recent request, orNone
if no requests have been made yet
-
last_meta
= None¶ The
meta
field in the body of the most recent response, orNone
if there was no such field, no requests have been made yet, or the last response was an error
-
session
= None¶ The
requests.Session
object through which all requests are performed
-
close
()[source]¶ Close the session. All API methods will be unusable after calling this method.
Returns: None
-
request
(url, params=None, data=None, method='GET')[source]¶ Perform an HTTP request and return the response body as a decoded JSON value
Parameters: - url (str) – the URL to make the request of. If
url
begins with a forward slash,endpoint
is prepended to it; otherwise,url
is treated as an absolute URL. - params (dict) – parameters to add to the URL’s query string
- data – a value to send in the body of the request. If
data
is not a string, it will be serialized as JSON before sending; either way, the Content-Type header of the request will be set to application/json. Note that adata
value ofNone
means “Don’t send any data”; to send an actualNone
value, convert it to JSON (i.e., the string"null"
) first. - method (str) – the HTTP method to use:
"GET"
,"POST"
,"PUT"
, or"DELETE"
(case-insensitive); default:"GET"
Returns: a decoded JSON value, or
None
if no data was returnedReturn type: Raises: - ValueError – if
method
is an invalid value - DOAPIError – if the API endpoint replies with an error
- url (str) – the URL to make the request of. If
-
last_rate_limit
¶ A
dict
of the rate limit information returned in the most recent response, orNone
if no requests have been made yet. Thedict
consists of all headers whose names begin with"RateLimit"
(case insensitive).The DigitalOcean API specifies the following rate limit headers:
Variables: - RateLimit-Limit (string) – the number of requests that can be made per hour
- RateLimit-Remaining (string) – the number of requests remaining until the limit is reached
- RateLimit-Reset (string) – the Unix timestamp for the time when the oldest request will expire from rate limit consideration
-
paginate
(url, key, params=None)[source]¶ Fetch a sequence of paginated resources from the API endpoint. The initial request to
url
and all subsequent requests must respond with a JSON object; the field specified bykey
must be a list, whose elements will be yielded, and the next request will be made to the URL in the.links.pages.next
field until the responses no longer contain that field.Parameters: - url (str) – the URL to make the initial request of. If
url
begins with a forward slash,endpoint
is prepended to it; otherwise,url
is treated as an absolute URL. - key (str) – the field on each page containing a list of values to yield
- params (dict) – parameters to add to the initial URL’s query
string. A
"per_page"
parameter may be included to override the defaultper_page
setting.
Return type: generator of decoded JSON values
Raises: - ValueError – if a response body is not an object or
key
is not one of its keys - DOAPIError – if the API endpoint replies with an error
- url (str) – the URL to make the initial request of. If
-
fetch_droplet
(obj)[source]¶ Fetch a droplet by ID number
Parameters: obj (integer, dict
, orDroplet
) – the ID of the droplet, adict
with an"id"
field, or aDroplet
object (to re-fetch the same droplet)Return type: Droplet Raises: DOAPIError – if the API endpoint replies with an error
-
fetch_all_droplets
(tag_name=None)[source]¶ Returns a generator that yields all of the droplets belonging to the account
Changed in version 0.2.0:
tag_name
parameter addedParameters: tag_name (string or Tag
) – if non-None
, only droplets with the given tag are returnedReturn type: generator of Droplet
sRaises: DOAPIError – if the API endpoint replies with an error
-
create_droplet
(name, image, size, region, ssh_keys=None, backups=None, ipv6=None, private_networking=None, user_data=None, **kwargs)[source]¶ Create a new droplet. All fields other than
name
,image
,size
, andregion
are optional and will be omitted from the API request if not specified.The returned
Droplet
object will represent the droplet at the moment of creation; the actual droplet may not be active yet and may not have even been assigned an IP address. To wait for the droplet to activate, use theDroplet
’swait()
method.Parameters: - name (str) – a name for the droplet
- image (integer, string, or
Image
) – the image ID, slug, orImage
object representing the base image to use for the droplet - size (string or
Size
) – the slug orSize
object representing the size of the new droplet - region (string or
Region
) – the slug orRegion
object representing the region in which to create the droplet - ssh_keys (iterable) – an iterable of SSH key resource IDs, SSH key
fingerprints, and/or
SSHKey
objects specifying the public keys to add to the new droplet’s/root/.ssh/authorized_keys
file - backups (bool) – whether to enable automatic backups on the new droplet
- ipv6 (bool) – whether to enable IPv6 on the new droplet
- private_networking (bool) – whether to enable private networking for the new droplet
- user_data (str) – a string of user data/metadata for the droplet
- kwargs – additional fields to include in the API request
Returns: the new droplet resource
Return type: Raises: DOAPIError – if the API endpoint replies with an error
-
create_multiple_droplets
(names, image, size, region, ssh_keys=None, backups=None, ipv6=None, private_networking=None, user_data=None, **kwargs)[source]¶ Create multiple new droplets at once with the same image, size, etc., differing only in name. All fields other than
names
,image
,size
, andregion
are optional and will be omitted from the API request if not specified.The returned
Droplet
objects will represent the droplets at the moment of creation; the actual droplets may not be active yet and may not have even been assigned IP addresses. To wait for the droplets to activate, use theirwait()
method orwait_droplets
.Parameters: - names (list of strings) – the names for the new droplets
- image (integer, string, or
Image
) – the image ID, slug, orImage
object representing the base image to use for the droplets - size (string or
Size
) – the slug orSize
object representing the size of the new droplets - region (string or
Region
) – the slug orRegion
object representing the region in which to create the droplets - ssh_keys (iterable) – an iterable of SSH key resource IDs, SSH key
fingerprints, and/or
SSHKey
objects specifying the public keys to add to the new droplets’/root/.ssh/authorized_keys
files - backups (bool) – whether to enable automatic backups on the new droplets
- ipv6 (bool) – whether to enable IPv6 on the new droplets
- private_networking (bool) – whether to enable private networking for the new droplets
- user_data (str) – a string of user data/metadata for the droplets
- kwargs – additional fields to include in the API request
Returns: the new droplet resources
Return type: list of
Droplet
sRaises: DOAPIError – if the API endpoint replies with an error
-
fetch_all_droplet_neighbors
()[source]¶ Returns a generator of all sets of multiple droplets that are running on the same physical hardware
Return type: generator of lists of Droplet
sRaises: DOAPIError – if the API endpoint replies with an error
-
wait_droplets
(droplets, status=None, locked=None, wait_interval=None, wait_time=None)[source]¶ Poll the server periodically until all droplets in
droplets
have reached some final state, yielding eachDroplet
’s final value when it’s done. Ifstatus
is non-None
,wait_droplets
will wait for each droplet’sstatus
field to equal the given value. Iflocked
is non-None
,wait_droplets
will wait for each droplet’slocked
field to equal (the truth value of) the given value. Exactly one ofstatus
andlocked
must be non-None
.If
wait_time
is exceeded, aWaitTimeoutError
(containing any remaining in-progress droplets) is raised.If a
KeyboardInterrupt
is caught, any remaining droplets are returned immediately without waiting for completion.Changed in version 0.2.0: Raises
WaitTimeoutError
on timeoutChanged in version 0.2.0:
locked
parameter addedChanged in version 0.2.0: No longer waits for actions to complete
Parameters: - droplets (iterable) – an iterable of
Droplet
s and/or other values that are acceptable arguments tofetch_droplet()
- status (string or
None
) – When non-None
, the desired value for thestatus
field of eachDroplet
, which should be one ofDroplet.STATUS_ACTIVE
,Droplet.STATUS_ARCHIVE
,Droplet.STATUS_NEW
, andDroplet.STATUS_OFF
. (For the sake of forwards-compatibility, any other value is accepted as well.) - locked (
bool
orNone
) – When non-None
, the desired value for thelocked
field of eachDroplet
- wait_interval (number) – how many seconds to sleep between
requests; defaults to
wait_interval
if not specified orNone
- wait_time (number) – the total number of seconds after which the
method will raise an error if any droplets have not yet completed,
or a negative number to wait indefinitely; defaults to
wait_time
if not specified orNone
Return type: generator of
Droplet
sRaises: - TypeError – if both or neither of
status
&locked
are defined - DOAPIError – if the API endpoint replies with an error
- WaitTimeoutError – if
wait_time
is exceeded
- droplets (iterable) – an iterable of
-
fetch_action
(obj)[source]¶ Fetch an action by ID number
Parameters: obj (integer, dict
, orAction
) – the ID of the action, adict
with an"id"
field, or anAction
object (to re-fetch the same action)Return type: Action Raises: DOAPIError – if the API endpoint replies with an error
-
fetch_last_action
()[source]¶ Fetch the most recent action performed on the account, or
None
if no actions have been performed yet. If multiple actions were triggered simultaneously, the choice of which to return is undefined.Return type: Action
orNone
Raises: DOAPIError – if the API endpoint replies with an error
-
fetch_all_actions
()[source]¶ Returns a generator that yields all of the actions associated with the account
Return type: generator of Action
sRaises: DOAPIError – if the API endpoint replies with an error
-
wait_actions
(actions, wait_interval=None, wait_time=None)[source]¶ Poll the server periodically until all actions in
actions
have either completed or errored out, yielding eachAction
’s final value as it ends.If
wait_time
is exceeded, aWaitTimeoutError
(containing any remaining in-progress actions) is raised.If a
KeyboardInterrupt
is caught, any remaining actions are returned immediately without waiting for completion.Changed in version 0.2.0: Raises
WaitTimeoutError
on timeoutParameters: - actions (iterable) – an iterable of
Action
s and/or other values that are acceptable arguments tofetch_action()
- wait_interval (number) – how many seconds to sleep between
requests; defaults to
wait_interval
if not specified orNone
- wait_time (number) – the total number of seconds after which the
method will raise an error if any actions have not yet completed,
or a negative number to wait indefinitely; defaults to
wait_time
if not specified orNone
Return type: generator of
Action
sRaises: - DOAPIError – if the API endpoint replies with an error
- WaitTimeoutError – if
wait_time
is exceeded
- actions (iterable) – an iterable of
-
wait_actions_on_objects
(objects, wait_interval=None, wait_time=None)[source]¶ New in version 0.2.0.
Poll the server periodically until the most recent action on each resource in
objects
has finished, yielding each resource’s final state when the corresponding action is done.If
wait_time
is exceeded, aWaitTimeoutError
(containing any remaining in-progress actions) is raised.If a
KeyboardInterrupt
is caught, any remaining actions are returned immediately without waiting for completion.Parameters: - objects (iterable) – an iterable of resource objects that have
fetch_last_action
methods - wait_interval (number) – how many seconds to sleep between
requests; defaults to
wait_interval
if not specified orNone
- wait_time (number) – the total number of seconds after which the
method will raise an error if any actions have not yet completed,
or a negative number to wait indefinitely; defaults to
wait_time
if not specified orNone
Return type: generator of objects
Raises: - DOAPIError – if the API endpoint replies with an error
- WaitTimeoutError – if
wait_time
is exceeded
- objects (iterable) – an iterable of resource objects that have
-
fetch_ssh_key
(obj)[source]¶ Fetch an SSH public key by ID number or fingerprint
Parameters: obj (integer, string, dict
, orSSHKey
) – the ID or fingerprint of the SSH key, adict
with an"id"
or"fingerprint"
field, or anSSHKey
object (to re-fetch the same SSH key)Return type: SSHKey Raises: DOAPIError – if the API endpoint replies with an error
-
fetch_all_ssh_keys
()[source]¶ Returns a generator that yields all of the SSH public keys belonging to the account
Return type: generator of SSHKey
sRaises: DOAPIError – if the API endpoint replies with an error
-
create_ssh_key
(name, public_key, **kwargs)[source]¶ Add a new SSH public key resource to the account
Parameters: Returns: the new SSH key resource
Return type: Raises: DOAPIError – if the API endpoint replies with an error
-
fetch_image
(obj)[source]¶ Fetch an image by ID number
Parameters: obj (integer, dict
, orImage
) – the ID of the image, adict
with an"id"
field, or anImage
object (to re-fetch the same image)Return type: Image Raises: DOAPIError – if the API endpoint replies with an error
-
fetch_image_by_slug
(slug)[source]¶ Fetch an image by its slug
Parameters: slug (str) – the slug of the image to fetch Return type: Image Raises: DOAPIError – if the API endpoint replies with an error
-
fetch_all_images
(type=None, private=None)[source]¶ Returns a generator that yields all of the images available to the account
Parameters: Return type: generator of
Image
sRaises: DOAPIError – if the API endpoint replies with an error
-
fetch_all_distribution_images
()[source]¶ Returns a generator that yields all of the distribution images available to the account
Return type: generator of Image
sRaises: DOAPIError – if the API endpoint replies with an error
-
fetch_all_application_images
()[source]¶ Returns a generator that yields all of the application images available to the account
Return type: generator of Image
sRaises: DOAPIError – if the API endpoint replies with an error
-
fetch_all_private_images
()[source]¶ Returns a generator that yields all of the user’s private images
Return type: generator of Image
sRaises: DOAPIError – if the API endpoint replies with an error
-
fetch_all_regions
()[source]¶ Returns a generator that yields all of the regions available to the account
Return type: generator of Region
sRaises: DOAPIError – if the API endpoint replies with an error
-
fetch_all_sizes
()[source]¶ Returns a generator that yields all of the sizes available to the account
Return type: generator of Size
sRaises: DOAPIError – if the API endpoint replies with an error
-
fetch_account
()[source]¶ Returns an
Account
object representing the user’s accountReturn type: Account Raises: DOAPIError – if the API endpoint replies with an error
-
fetch_domain
(obj)[source]¶ Fetch a domain by FQDN
Parameters: obj (string, dict
, orDomain
) – the domain name, adict
with a"name"
field, or aDomain
object (to re-fetch the same domain)Return type: Domain Raises: DOAPIError – if the API endpoint replies with an error
-
fetch_all_domains
()[source]¶ Returns a generator that yields all of the domains belonging to the account
Return type: generator of Domain
sRaises: DOAPIError – if the API endpoint replies with an error
-
create_domain
(name, ip_address, **kwargs)[source]¶ Add a new domain name resource to the account.
Note that this method does not actually register a new domain name; it merely configures DigitalOcean’s nameservers to provide DNS resolution for the domain. See How To Set Up a Host Name with DigitalOcean for more information.
Parameters: - name (str) – the domain name to add
- ip_address (string or
FloatingIP
) – the IP address to which the domain should point - kwargs – additional fields to include in the API request
Returns: the new domain resource
Return type: Raises: DOAPIError – if the API endpoint replies with an error
-
fetch_floating_ip
(obj)[source]¶ Fetch a floating IP
Parameters: obj (string, integer, dict
, orFloatingIP
) – an IP address (as a string or 32-bit integer), adict
with an"ip"
field, or aFloatingIP
object (to re-fetch the same floating IP)Return type: FloatingIP Raises: DOAPIError – if the API endpoint replies with an error
-
fetch_all_floating_ips
()[source]¶ Returns a generator that yields all of the floating IPs belonging to the account
Return type: generator of FloatingIP
sRaises: DOAPIError – if the API endpoint replies with an error
-
create_floating_ip
(droplet_id=None, region=None, **kwargs)[source]¶ Create a new floating IP assigned to a droplet or reserved to a region. Either
droplet_id
orregion
must be specified, but not both.The returned
FloatingIP
object will represent the IP at the moment of creation; if the IP address is supposed to be assigned to a droplet, the assignment may not have been completed at the time the object is returned. To wait for the assignment to complete, use theFloatingIP
’swait_for_action()
method.Parameters: Returns: the new floating IP
Return type: Raises: - TypeError – if both
droplet_id
®ion
or neither of them are defined - DOAPIError – if the API endpoint replies with an error
- TypeError – if both
-
fetch_tag
(obj)[source]¶ New in version 0.2.0.
Fetch a tag by name
Parameters: obj (string, dict
, orTag
) – the name of the tag, adict
with a"name"
field, or aTag
object (to re-fetch the same tag)Return type: Tag Raises: DOAPIError – if the API endpoint replies with an error
New in version 0.2.0.
Returns a generator that yields all of the tags belonging to the account
Return type: generator of Tag
sRaises: DOAPIError – if the API endpoint replies with an error
-
create_tag
(name)[source]¶ New in version 0.2.0.
Add a new tag resource to the account
Parameters: name (str) – the name of the new tag Return type: Tag Raises: DOAPIError – if the API endpoint replies with an error
Droplets¶
Droplet¶
-
class
doapi.
Droplet
[source]¶ A droplet resource, representing a virtual machine provided by DigitalOcean.
New droplets are created via the
doapi.create_droplet()
anddoapi.create_multiple_droplets()
methods and can be retrieved with thedoapi.fetch_droplet()
anddoapi.fetch_all_droplets()
methods.The DigitalOcean API specifies the following fields for droplet objects:
Variables: - id (int) – a unique identifier for the droplet
- backup_ids (list of integers) – image IDs of backups taken of the droplet
- created_at (datetime.datetime) – date & time of the droplet’s creation
- disk (number) – size of the droplet’s disk in gigabytes
- features (list of strings) – a list of strings naming the features enabled on the droplet
- image (
Image
) – the base image used to create the droplet - kernel (
Kernel
orNone
) – the droplet’s current kernel - locked (bool) – whether the droplet is currently locked, preventing actions on it
- memory (number) – RAM of the droplet in megabytes
- name (string) – a human-readable name for the droplet
- networks (
Networks
) – the network interfaces configured for the droplet - next_backup_window (
BackupWindow
orNone
) – the start & end of the next timeframe in which the droplet will be backed up; only defined if backups are enabled on the droplet - region (
Region
) – the region in which the droplet is located - size (
Size
) – the current size of the droplet - size_slug (string) – the unique slug identifier for the droplet’s size
- snapshot_ids (list of integers) – image IDs of snapshots taken of the droplet
- status (string) – the current state of the droplet:
"new"
,"active"
,"off"
, or"archive"
- tags (list of strings) – tags that have been applied to the droplet
- vcpus (int) – number of virtual CPUs
-
action_url
¶ The endpoint for actions on the individual resource
-
act
(**data)¶ Perform an arbitrary action on the resource.
data
will be serialized as JSON and POSTed to the resource’saction_url
. All currently-documented actions require the POST body to be a JSON object containing, at a minimum, a"type"
field.Returns: an Action
representing the in-progress operation on the resourceReturn type: Action Raises: DOAPIError – if the API endpoint replies with an error
-
wait_for_action
(wait_interval=None, wait_time=None)¶ Poll the server periodically until the resource’s most recent action has either completed or errored out, and return the resource’s final state afterwards. If no actions have ever been performed on the resource, return
self
. If the resource no longer exists by the time the action has completed, returnNone
.If
wait_time
is exceeded, aWaitTimeoutError
(containing the resource’s current state) is raised.If a
KeyboardInterrupt
is caught, the resource’s current state is returned immediately without waiting for completion.Changed in version 0.2.0: Raises
WaitTimeoutError
on timeoutChanged in version 0.2.0: Name changed from
wait
towait_for_action
Changed in version 0.2.0: Return
self
if there were no actions on the resourceChanged in version 0.2.0: Return
None
if the resource no longer exists afterwardsParameters: - wait_interval (number) – how many seconds to sleep between
requests; defaults to the
doapi
object’swait_interval
if not specified orNone
- wait_time (number) – the total number of seconds after which the
method will raise an error if the action has not yet completed, or
a negative number to wait indefinitely; defaults to the
doapi
object’swait_time
if not specified orNone
Returns: the resource’s final state
Raises: - DOAPIError – if the API endpoint replies with an error
- WaitTimeoutError – if
wait_time
is exceeded
- wait_interval (number) – how many seconds to sleep between
requests; defaults to the
-
fetch_all_actions
()¶ Returns a generator that yields all of the actions associated with the resource
Return type: generator of Action
sRaises: DOAPIError – if the API endpoint replies with an error
-
fetch_last_action
()¶ Fetch the most recent action performed on the resource, or
None
if no actions have been performed on it yet. If multiple actions were triggered simultaneously, the choice of which to return is undefined.Changed in version 0.2.0: Return
None
if there were no actions on the resourceReturn type: Action Raises: DOAPIError – if the API endpoint replies with an error
-
fetch_current_action
()¶ Fetch the action currently in progress on the resource, or
None
if there is no such actionReturn type: Action
orNone
Raises: DOAPIError – if the API endpoint replies with an error
-
__int__
()¶ Convert the resource to its unique integer ID
-
tag
(t)¶ New in version 0.2.0.
Apply the given tag to the resource
Parameters: t (string or Tag
) – the tag to applyReturns: None
Raises: DOAPIError – if the API endpoint replies with an error
-
untag
(t)¶ New in version 0.2.0.
Remove the given tag from the resource
Parameters: t (string or Tag
) – the tag to removeReturns: None
Raises: DOAPIError – if the API endpoint replies with an error
-
STATUS_ACTIVE
= 'active'¶ The status of droplets that are powered on and operating
-
STATUS_ARCHIVE
= 'archive'¶ The status of “archived” droplets
-
STATUS_NEW
= 'new'¶ The status of recently-created droplets that are not yet usable
-
STATUS_OFF
= 'off'¶ The status of droplets that are powered off
-
region_slug
¶ The unique slug identifier for the droplet’s region
-
image_slug
¶ The unique slug identifier for the droplet’s image, or
None
if the image doesn’t have a slug
-
ip_address
¶ The IP address of the first interface listed in the droplet’s
networks
field (ordering IPv4 before IPv6), orNone
if there are no interfaces
-
ipv4_address
¶ New in version 0.2.0.
The IP address of the first IPv4 interface listed in the droplet’s
networks
field, orNone
if there is no IPv4 interface
-
ipv6_address
¶ New in version 0.2.0.
The IP address of the first IPv6 interface listed in the droplet’s
networks
field, orNone
if there is no IPv4 interface
-
url
¶ The endpoint for general operations on the individual droplet
-
fetch
()[source]¶ Fetch & return a new
Droplet
object representing the droplet’s current stateReturn type: Droplet Raises: DOAPIError – if the API endpoint replies with an error (e.g., if the droplet no longer exists)
-
fetch_all_neighbors
()[source]¶ Returns a generator that yields all of the droplets running on the same physical server as the droplet
Return type: generator of Droplet
sRaises: DOAPIError – if the API endpoint replies with an error
-
fetch_all_snapshots
()[source]¶ Returns a generator that yields all of the snapshot images created from the droplet
Return type: generator of Image
sRaises: DOAPIError – if the API endpoint replies with an error
-
fetch_all_backups
()[source]¶ Returns a generator that yields all of the backup images created from the droplet
Return type: generator of Image
sRaises: DOAPIError – if the API endpoint replies with an error
-
fetch_all_kernels
()[source]¶ Returns a generator that yields all of the kernels available to the droplet
Return type: generator of Kernel
sRaises: DOAPIError – if the API endpoint replies with an error
-
enable_backups
()[source]¶ Enable backups on the droplet
Returns: an Action
representing the in-progress operation on the dropletReturn type: Action Raises: DOAPIError – if the API endpoint replies with an error
-
disable_backups
()[source]¶ Disable backups on the droplet
Returns: an Action
representing the in-progress operation on the dropletReturn type: Action Raises: DOAPIError – if the API endpoint replies with an error
-
reboot
()[source]¶ Reboot the droplet
A reboot action is an attempt to reboot the Droplet in a graceful way, similar to using the reboot command from the console. [APIDocs]Returns: an Action
representing the in-progress operation on the dropletReturn type: Action Raises: DOAPIError – if the API endpoint replies with an error
-
power_cycle
()[source]¶ Power cycle the droplet
A powercycle action is similar to pushing the reset button on a physical machine, it’s similar to booting from scratch. [APIDocs]Returns: an Action
representing the in-progress operation on the dropletReturn type: Action Raises: DOAPIError – if the API endpoint replies with an error
-
shutdown
()[source]¶ Shut down the droplet
A shutdown action is an attempt to shutdown the Droplet in a graceful way, similar to using the shutdown command from the console. Since ashutdown
command can fail, this action guarantees that the command is issued, not that it succeeds. The preferred way to turn off a Droplet is to attempt a shutdown, with a reasonable timeout, followed by a power off action to ensure the Droplet is off. [APIDocs]Returns: an Action
representing the in-progress operation on the dropletReturn type: Action Raises: DOAPIError – if the API endpoint replies with an error
-
power_off
()[source]¶ Power off the droplet
Apower_off
event is a hard shutdown and should only be used if theshutdown()
action is not successful. It is similar to cutting the power on a server and could lead to complications. [APIDocs]Returns: an Action
representing the in-progress operation on the dropletReturn type: Action Raises: DOAPIError – if the API endpoint replies with an error
-
power_on
()[source]¶ Power on the droplet
Returns: an Action
representing the in-progress operation on the dropletReturn type: Action Raises: DOAPIError – if the API endpoint replies with an error
-
restore
(image)[source]¶ Restore the droplet to the specified backup image
A Droplet restoration will rebuild an image using a backup image. The image ID that is passed in must be a backup of the current Droplet instance. The operation will leave any embedded SSH keys intact. [APIDocs]Parameters: image (integer, string, or Image
) – an image ID, an image slug, or anImage
object representing a backup image of the dropletReturns: an Action
representing the in-progress operation on the dropletReturn type: Action Raises: DOAPIError – if the API endpoint replies with an error
-
password_reset
()[source]¶ Reset the password for the droplet
Returns: an Action
representing the in-progress operation on the dropletReturn type: Action Raises: DOAPIError – if the API endpoint replies with an error
-
resize
(size, disk=None)[source]¶ Resize the droplet
Parameters: Returns: an
Action
representing the in-progress operation on the dropletReturn type: Raises: DOAPIError – if the API endpoint replies with an error
-
rebuild
(image)[source]¶ Rebuild the droplet with the specified image
A rebuild action functions just like a new create. [APIDocs]Parameters: image (integer, string, or Image
) – an image ID, an image slug, or anImage
object representing the image the droplet should use as a baseReturns: an Action
representing the in-progress operation on the dropletReturn type: Action Raises: DOAPIError – if the API endpoint replies with an error
-
rename
(name)[source]¶ Rename the droplet
Parameters: name (str) – the new name for the droplet Returns: an Action
representing the in-progress operation on the dropletReturn type: Action Raises: DOAPIError – if the API endpoint replies with an error
-
change_kernel
(kernel)[source]¶ Change the droplet’s kernel
Parameters: kernel (integer or Kernel
) – a kernel ID orKernel
object representing the new kernelReturns: an Action
representing the in-progress operation on the dropletReturn type: Action Raises: DOAPIError – if the API endpoint replies with an error
-
enable_ipv6
()[source]¶ Enable IPv6 networking on the droplet
Returns: an Action
representing the in-progress operation on the dropletReturn type: Action Raises: DOAPIError – if the API endpoint replies with an error
-
enable_private_networking
()[source]¶ Enable private networking on the droplet
Returns: an Action
representing the in-progress operation on the dropletReturn type: Action Raises: DOAPIError – if the API endpoint replies with an error
-
snapshot
(name)[source]¶ Create a snapshot image of the droplet
Parameters: name (str) – the name for the new snapshot Returns: an Action
representing the in-progress operation on the dropletReturn type: Action Raises: DOAPIError – if the API endpoint replies with an error
-
delete
()[source]¶ Delete the droplet
Returns: None
Raises: DOAPIError – if the API endpoint replies with an error
-
wait
(status=None, locked=None, wait_interval=None, wait_time=None)[source]¶ Poll the server periodically until the droplet has reached some final state. If
status
is non-None
,wait
will wait for the droplet’sstatus
field to equal the given value. Iflocked
is non-None
,wait
will wait for the droplet’slocked
field to equal (the truth value of) the given value. Exactly one ofstatus
andlocked
must be non-None
.If
wait_time
is exceeded, aWaitTimeoutError
(containing the droplet’s most recently fetched state) is raised.If a
KeyboardInterrupt
is caught, the droplet’s most recently fetched state is returned immediately without waiting for completion.Changed in version 0.2.0: Raises
WaitTimeoutError
on timeoutChanged in version 0.2.0:
locked
parameter addedChanged in version 0.2.0: No longer waits for latest action to complete
Parameters: - status (string or
None
) – When non-None
, the desired value for thestatus
field of the droplet, which should be one ofDroplet.STATUS_ACTIVE
,Droplet.STATUS_ARCHIVE
,Droplet.STATUS_NEW
, andDroplet.STATUS_OFF
. (For the sake of forwards-compatibility, any other value is accepted as well.) - locked (
bool
orNone
) – When non-None
, the desired value for thelocked
field of the droplet - wait_interval (number) – how many seconds to sleep between
requests; defaults to the
doapi
object’swait_interval
if not specified orNone
- wait_time (number) – the total number of seconds after which the
method will raise an error if the droplet has not yet completed, or
a negative number to wait indefinitely; defaults to the
doapi
object’swait_time
if not specified orNone
Returns: the droplet’s final state
Return type: Raises: - TypeError – if both or neither of
status
&locked
are defined - DOAPIError – if the API endpoint replies with an error
- WaitTimeoutError – if
wait_time
is exceeded
- status (string or
[APIDocs] | (1, 2, 3, 4, 5, 6) https://developers.digitalocean.com/documentation/v2/ |
BackupWindow¶
-
class
doapi.
BackupWindow
[source]¶ A backup window resource, representing an upcoming timeframe in which a droplet is scheduled to be backed up.
A
Droplet
’s next backup window is stored in itsnext_backup_window
attribute.The DigitalOcean API implicitly specifies the following fields for backup window objects:
Variables: - start (datetime.datetime) – beginning of the window
- end (datetime.datetime) – end of the window
Kernel¶
-
class
doapi.
Kernel
[source]¶ A kernel resource, representing a kernel version that can be installed on a given droplet.
A
Droplet
’s current kernel is stored in itskernel
attribute, and the set of kernels available to a givenDroplet
can be retrieved with thedroplet.fetch_all_kernels()
method.The DigitalOcean API specifies the following fields for kernel objects:
Variables: -
__int__
()¶ Convert the resource to its unique integer ID
-
Networks¶
-
class
doapi.
Networks
[source]¶ A networks resource, representing a set of network interfaces configured for a specific droplet.
A
Droplet
’s network information is stored in itsnetworks
attribute.The DigitalOcean API implicitly specifies the following fields for networks objects:
Variables: - v4 (list of
NetworkInterface
s) – a list of IPv4 interfaces allocated for a droplet - v6 (list of
NetworkInterface
s) – a list of IPv6 interfaces allocated for a droplet
- v4 (list of
NetworkInterface¶
-
class
doapi.
NetworkInterface
[source]¶ A network interface resource, representing an IP address allocated to a specific droplet.
A
Droplet
’s network interfaces are listed in itsnetworks
attribute.The DigitalOcean API implicitly specifies the following fields for network interface objects:
Variables: - gateway (string) – gateway
- ip_address (string) – IP address
- netmask – netmask
- type –
"public"
or"private"
-
ip_version
¶ The IP version used by the interface:
4
or6
Domains¶
Domain¶
-
class
doapi.
Domain
[source]¶ A domain resource, representing a domain name whose DNS is managed by DigitalOcean’s nameservers.
New domains are created via the
doapi.create_domain()
method and can be retrieved with thedoapi.fetch_domain()
anddoapi.fetch_all_domains()
methods.The DigitalOcean API specifies the following fields for domain objects:
Variables: - name (string) – the domain name
- ttl (number) – the time-to-live for the domain’s records, in seconds
- zone_file (string) – the complete zone file for the domain
-
url
¶ The endpoint for general operations on the individual domain
-
fetch
()[source]¶ Fetch & return a new
Domain
object representing the domain’s current stateReturn type: Domain Raises: DOAPIError – if the API endpoint replies with an error (e.g., if the domain no longer exists)
-
delete
()[source]¶ Delete the domain
Returns: None
Raises: DOAPIError – if the API endpoint replies with an error
-
record_url
¶ The endpoint for operations on the domain’s DNS records
-
fetch_record
(obj)[source]¶ Fetch a domain record by ID number
Parameters: obj (integer, dict
, orDomainRecord
) – the ID of the record, adict
with an"id"
field, or aDomainRecord
object (to re-fetch the same record)Return type: DomainRecord Raises: DOAPIError – if the API endpoint replies with an error
-
fetch_all_records
()[source]¶ Returns a generator that yields all of the DNS records for the domain
Return type: generator of DomainRecord
sRaises: DOAPIError – if the API endpoint replies with an error
-
create_record
(type, name, data, priority=None, port=None, weight=None, **kwargs)[source]¶ Add a new DNS record to the domain
Parameters: - type (str) – the type of DNS record to add (
"A"
,"CNAME"
, etc.) - name (str) – the name (hostname, alias, etc.) of the new record
- data (str) – the value of the new record
- priority (int) – the priority of the new record (SRV and MX records only)
- port (int) – the port that the service is accessible on (SRV records only)
- weight (int) – the weight of records with the same priority (SRV records only)
- kwargs – additional fields to include in the API request
Returns: the new domain record
Return type: Raises: DOAPIError – if the API endpoint replies with an error
- type (str) – the type of DNS record to add (
DomainRecord¶
-
class
doapi.
DomainRecord
[source]¶ A domain record resource, representing an individual DNS record that can be set & modified by the user of the DigitalOcean API.
New domain records are created via the
Domain.create_record()
method and can be retrieved with theDomain.fetch_record()
andDomain.fetch_all_records()
methods.The DigitalOcean API specifies the following fields for domain record objects:
Variables: - id (int) – a unique identifier for the domain record
- type (string) – the type of the DNS record
- name (string) – the name of the DNS record
- data (string) – the value of the DNS record
- priority (number or
None
) – the priority of the record (SRV and MX records only) - port (number or
None
) – the port of the record (SRV records only) - weight (number or
None
) – the weight of the record (SRV records only)
-
__int__
()¶ Convert the resource to its unique integer ID
-
url
¶ The endpoint for general operations on the individual domain record
-
fetch
()[source]¶ Fetch & return a new
DomainRecord
object representing the domain record’s current stateReturn type: DomainRecord Raises: DOAPIError – if the API endpoint replies with an error (e.g., if the domain record no longer exists)
-
fetch_domain
()[source]¶ Fetch & return the domain resource that the record belongs to
Return type: Domain Raises: DOAPIError – if the API endpoint replies with an error
-
update_record
(**attrs)[source]¶ Update the record, modifying any number of its attributes (except
id
).update_record
takes the same keyword arguments asDomain.create_record()
; pass in only those attributes that you want to update.Returns: an updated DomainRecord
objectReturn type: DomainRecord Raises: DOAPIError – if the API endpoint replies with an error
-
delete
()[source]¶ Delete the domain record
Returns: None
Raises: DOAPIError – if the API endpoint replies with an error
Floating IPs¶
FloatingIP¶
-
class
doapi.
FloatingIP
[source]¶ A floating IP resource, representing a public IP address that can be (re)assigned at any time to any droplet in a certain region.
New floating IPs are created via the
doapi.create_floating_ip()
method and can be retrieved with thedoapi.fetch_floating_ip()
anddoapi.fetch_all_floating_ips()
methods.The DigitalOcean API specifies the following fields for floating IP objects:
Variables: -
action_url
¶ The endpoint for actions on the individual resource
-
act
(**data)¶ Perform an arbitrary action on the resource.
data
will be serialized as JSON and POSTed to the resource’saction_url
. All currently-documented actions require the POST body to be a JSON object containing, at a minimum, a"type"
field.Returns: an Action
representing the in-progress operation on the resourceReturn type: Action Raises: DOAPIError – if the API endpoint replies with an error
-
wait_for_action
(wait_interval=None, wait_time=None)¶ Poll the server periodically until the resource’s most recent action has either completed or errored out, and return the resource’s final state afterwards. If no actions have ever been performed on the resource, return
self
. If the resource no longer exists by the time the action has completed, returnNone
.If
wait_time
is exceeded, aWaitTimeoutError
(containing the resource’s current state) is raised.If a
KeyboardInterrupt
is caught, the resource’s current state is returned immediately without waiting for completion.Changed in version 0.2.0: Raises
WaitTimeoutError
on timeoutChanged in version 0.2.0: Name changed from
wait
towait_for_action
Changed in version 0.2.0: Return
self
if there were no actions on the resourceChanged in version 0.2.0: Return
None
if the resource no longer exists afterwardsParameters: - wait_interval (number) – how many seconds to sleep between
requests; defaults to the
doapi
object’swait_interval
if not specified orNone
- wait_time (number) – the total number of seconds after which the
method will raise an error if the action has not yet completed, or
a negative number to wait indefinitely; defaults to the
doapi
object’swait_time
if not specified orNone
Returns: the resource’s final state
Raises: - DOAPIError – if the API endpoint replies with an error
- WaitTimeoutError – if
wait_time
is exceeded
- wait_interval (number) – how many seconds to sleep between
requests; defaults to the
-
fetch_all_actions
()¶ Returns a generator that yields all of the actions associated with the resource
Return type: generator of Action
sRaises: DOAPIError – if the API endpoint replies with an error
-
fetch_last_action
()¶ Fetch the most recent action performed on the resource, or
None
if no actions have been performed on it yet. If multiple actions were triggered simultaneously, the choice of which to return is undefined.Changed in version 0.2.0: Return
None
if there were no actions on the resourceReturn type: Action Raises: DOAPIError – if the API endpoint replies with an error
-
fetch_current_action
()¶ Fetch the action currently in progress on the resource, or
None
if there is no such actionReturn type: Action
orNone
Raises: DOAPIError – if the API endpoint replies with an error
-
url
¶ The endpoint for general operations on the individual floating IP
-
fetch
()[source]¶ Fetch & return a new
FloatingIP
object representing the floating IP’s current stateReturn type: FloatingIP Raises: DOAPIError – if the API endpoint replies with an error (e.g., if the floating IP no longer exists)
-
delete
()[source]¶ Delete the floating IP
Returns: None
Raises: DOAPIError – if the API endpoint replies with an error
-
assign
(droplet_id)[source]¶ Assign the floating IP to a droplet
Parameters: droplet_id (integer or Droplet
) – the droplet to assign the floating IP to as either an ID or aDroplet
objectReturns: an Action
representing the in-progress operation on the floating IPReturn type: Action Raises: DOAPIError – if the API endpoint replies with an error
-
unassign
()[source]¶ Unassign the floating IP
Returns: an Action
representing the in-progress operation on the floating IPReturn type: Action Raises: DOAPIError – if the API endpoint replies with an error
-
Images¶
Image¶
-
class
doapi.
Image
[source]¶ An image resource, representing an OS image that can be used to create or reset a droplet.
New images can be created via the
Droplet.snapshot()
method. They are also automatically created regularly for droplets that have backups enabled. Images can be retrieved with thedoapi.fetch_image()
anddoapi.fetch_all_images()
methods, among others.The DigitalOcean API specifies the following fields for domain objects:
Variables: - id (int) – a unique identifier for the image
- created_at (datetime.datetime) – date & time of the image’s creation
- distribution (string) – the base Linux distribution used for the image
- min_disk_size (number) – the minimum
disk
size (in gigabytes) required for a droplet to use the image - name (string) – a human-readable name for the image
- public (bool) – whether the image is public (i.e., available to all accounts) or not (i.e., only accessible from your account)
- regions (list of strings) – the slugs of the regions in which the image is available
- size_gigabytes (number) – the size of the image in gigabytes
- slug (string or
None
) – the unique slug identifier for the image (only defined for public images) - type (string) – the type of the image:
"snapshot"
or"backup"
-
action_url
¶ The endpoint for actions on the individual resource
-
act
(**data)¶ Perform an arbitrary action on the resource.
data
will be serialized as JSON and POSTed to the resource’saction_url
. All currently-documented actions require the POST body to be a JSON object containing, at a minimum, a"type"
field.Returns: an Action
representing the in-progress operation on the resourceReturn type: Action Raises: DOAPIError – if the API endpoint replies with an error
-
wait_for_action
(wait_interval=None, wait_time=None)¶ Poll the server periodically until the resource’s most recent action has either completed or errored out, and return the resource’s final state afterwards. If no actions have ever been performed on the resource, return
self
. If the resource no longer exists by the time the action has completed, returnNone
.If
wait_time
is exceeded, aWaitTimeoutError
(containing the resource’s current state) is raised.If a
KeyboardInterrupt
is caught, the resource’s current state is returned immediately without waiting for completion.Changed in version 0.2.0: Raises
WaitTimeoutError
on timeoutChanged in version 0.2.0: Name changed from
wait
towait_for_action
Changed in version 0.2.0: Return
self
if there were no actions on the resourceChanged in version 0.2.0: Return
None
if the resource no longer exists afterwardsParameters: - wait_interval (number) – how many seconds to sleep between
requests; defaults to the
doapi
object’swait_interval
if not specified orNone
- wait_time (number) – the total number of seconds after which the
method will raise an error if the action has not yet completed, or
a negative number to wait indefinitely; defaults to the
doapi
object’swait_time
if not specified orNone
Returns: the resource’s final state
Raises: - DOAPIError – if the API endpoint replies with an error
- WaitTimeoutError – if
wait_time
is exceeded
- wait_interval (number) – how many seconds to sleep between
requests; defaults to the
-
fetch_all_actions
()¶ Returns a generator that yields all of the actions associated with the resource
Return type: generator of Action
sRaises: DOAPIError – if the API endpoint replies with an error
-
fetch_last_action
()¶ Fetch the most recent action performed on the resource, or
None
if no actions have been performed on it yet. If multiple actions were triggered simultaneously, the choice of which to return is undefined.Changed in version 0.2.0: Return
None
if there were no actions on the resourceReturn type: Action Raises: DOAPIError – if the API endpoint replies with an error
-
fetch_current_action
()¶ Fetch the action currently in progress on the resource, or
None
if there is no such actionReturn type: Action
orNone
Raises: DOAPIError – if the API endpoint replies with an error
-
__int__
()¶ Convert the resource to its unique integer ID
-
__str__
()[source]¶ Convert the image to its slug representation. If the image does not have a slug, an
AttributeError
is raised.
-
url
¶ The endpoint for general operations on the individual image
-
fetch
()[source]¶ Fetch & return a new
Image
object representing the image’s current stateReturn type: Image Raises: DOAPIError – if the API endpoint replies with an error (e.g., if the image no longer exists)
-
update_image
(name)[source]¶ Update (i.e., rename) the image
Parameters: name (str) – the new name for the image Returns: an updated Image
objectReturn type: Image Raises: DOAPIError – if the API endpoint replies with an error
-
delete
()[source]¶ Delete the image
Returns: None
Raises: DOAPIError – if the API endpoint replies with an error
-
transfer
(region)[source]¶ Transfer the image to another region
Parameters: region (string or Region
) – the slug orRegion
object representing the region to which to transfer the imageReturns: an Action
representing the in-progress operation on the imageReturn type: Action Raises: DOAPIError – if the API endpoint replies with an error
-
convert
()[source]¶ Convert the image to a snapshot
Returns: an Action
representing the in-progress operation on the imageReturn type: Action Raises: DOAPIError – if the API endpoint replies with an error
SSH Keys¶
SSHKey¶
-
class
doapi.
SSHKey
[source]¶ An SSH key resource, representing an SSH public key that can be automatically added to the
/root/.ssh/authorized_keys
files of new droplets.New SSH keys are created via the
doapi.create_ssh_key()
method and can be retrieved with thedoapi.fetch_ssh_key()
anddoapi.fetch_all_ssh_keys()
methods.The DigitalOcean API specifies the following fields for SSH key objects:
Variables: -
__int__
()¶ Convert the resource to its unique integer ID
-
url
¶ The endpoint for general operations on the individual SSH key
-
fetch
()[source]¶ Fetch & return a new
SSHKey
object representing the SSH key’s current stateReturn type: SSHKey Raises: DOAPIError – if the API endpoint replies with an error (e.g., if the SSH key no longer exists)
-
update_ssh_key
(name)[source]¶ Update (i.e., rename) the SSH key
Parameters: name (str) – the new name for the SSH key Returns: an updated SSHKey
objectReturn type: SSHKey Raises: DOAPIError – if the API endpoint replies with an error
-
delete
()[source]¶ Delete the SSH key
Returns: None
Raises: DOAPIError – if the API endpoint replies with an error
-
Tags¶
Tag¶
-
class
doapi.
Tag
[source]¶ New in version 0.2.0.
A tag resource, representing a label that can be applied to other resources.
New tags are created via the
doapi.create_tag()
method and can be retrieved with thedoapi.fetch_tag()
anddoapi.fetch_all_tags()
methods.The DigitalOcean API specifies the following fields for tag objects:
Variables: -
url
¶ The endpoint for general operations on the individual tag
-
fetch
()[source]¶ Fetch & return a new
Tag
object representing the tag’s current stateReturn type: Tag Raises: DOAPIError – if the API endpoint replies with an error (e.g., if the tag no longer exists)
-
update_tag
(name)[source]¶ Update (i.e., rename) the tag
Parameters: name (str) – the new name for the tag Returns: an updated Tag
objectReturn type: Tag Raises: DOAPIError – if the API endpoint replies with an error
-
delete
()[source]¶ Delete the tag
Returns: None
Raises: DOAPIError – if the API endpoint replies with an error
-
add
(*resources)[source]¶ Apply the tag to one or more resources
Parameters: resources – one or more Resource
objects to which tags can be appliedReturns: None
Raises: DOAPIError – if the API endpoint replies with an error
-
remove
(*resources)[source]¶ Remove the tag from one or more resources
Parameters: resources – one or more Resource
objects to which tags can be appliedReturns: None
Raises: DOAPIError – if the API endpoint replies with an error
-
fetch_all_droplets
()[source]¶ Returns a generator that yields all of the droplets to which the tag is currently applied
Return type: generator of Droplet
sRaises: DOAPIError – if the API endpoint replies with an error
-
delete_all_droplets
()[source]¶ Delete all of the droplets to which the tag is applied
Returns: None
Raises: DOAPIError – if the API endpoint replies with an error
-
act_on_droplets
(**data)[source]¶ Perform an arbitrary action on all of the droplets to which the tag is applied.
data
will be serialized as JSON and POSTed to the proper API endpoint. All currently-documented actions require the POST body to be a JSON object containing, at a minimum, a"type"
field.Returns: a generator of Action
s representing the in-progress operations on the dropletsReturn type: generator of Action
sRaises: DOAPIError – if the API endpoint replies with an error
-
power_cycle
()[source]¶ Power cycle all of the droplets to which the tag is applied
Returns: a generator of Action
s representing the in-progress operations on the dropletsReturn type: generator of Action
sRaises: DOAPIError – if the API endpoint replies with an error
-
power_on
()[source]¶ Power on all of the droplets to which the tag is applied
Returns: a generator of Action
s representing the in-progress operations on the dropletsReturn type: generator of Action
sRaises: DOAPIError – if the API endpoint replies with an error
-
power_off
()[source]¶ Power off all of the droplets to which the tag is applied
Returns: a generator of Action
s representing the in-progress operations on the dropletsReturn type: generator of Action
sRaises: DOAPIError – if the API endpoint replies with an error
-
shutdown
()[source]¶ Shut down all of the droplets to which the tag is applied
Returns: a generator of Action
s representing the in-progress operations on the dropletsReturn type: generator of Action
sRaises: DOAPIError – if the API endpoint replies with an error
-
enable_private_networking
()[source]¶ Enable private networking on all of the droplets to which the tag is applied
Returns: a generator of Action
s representing the in-progress operations on the dropletsReturn type: generator of Action
sRaises: DOAPIError – if the API endpoint replies with an error
-
enable_ipv6
()[source]¶ Enable IPv6 networking on all of the droplets to which the tag is applied
Returns: a generator of Action
s representing the in-progress operations on the dropletsReturn type: generator of Action
sRaises: DOAPIError – if the API endpoint replies with an error
-
enable_backups
()[source]¶ Enable backups on all of the droplets to which the tag is applied
Returns: a generator of Action
s representing the in-progress operations on the dropletsReturn type: generator of Action
sRaises: DOAPIError – if the API endpoint replies with an error
-
disable_backups
()[source]¶ Disable backups on all of the droplets to which the tag is applied
Returns: a generator of Action
s representing the in-progress operations on the dropletsReturn type: generator of Action
sRaises: DOAPIError – if the API endpoint replies with an error
-
snapshot
(name)[source]¶ Create snapshot images of all of the droplets to which the tag is applied
Parameters: name (str) – the name for the new snapshots Returns: a generator of Action
s representing the in-progress operations on the dropletsReturn type: generator of Action
sRaises: DOAPIError – if the API endpoint replies with an error
-
Immutable Resources¶
Account¶
-
class
doapi.
Account
[source]¶ An account resource describing the user’s DigitalOcean account.
Current details on the user’s account can be retrieved with the
doapi.fetch_account()
method.The DigitalOcean API specifies the following fields for account objects:
Variables: - droplet_limit (int) – the maximum number of droplets the account may have at any one time
- email (string) – the e-mail address the account used to register for DigitalOcean
- email_verified (bool) – whether the user’s account has been verified via e-mail
- floating_ip_limit (int) – the maximum number of floating IPs the account may have at any one time
- status (string) – the status of the account:
"active"
,"warning"
, or"locked"
- status_message – a human-readable string describing the status of the account
- uuid (alphanumeric string) – a UUID for the user
-
STATUS_ACTIVE
= 'active'¶ The status of an account that is currently active and warning-free
-
STATUS_WARNING
= 'warning'¶ The status of an account that is currently in a “warning” state, e.g., from having reached the droplet limit
-
STATUS_LOCKED
= 'locked'¶ The status of a locked account
-
fetch
()[source]¶ Fetch & return a new
Account
object representing the account’s current stateReturn type: Account Raises: DOAPIError – if the API endpoint replies with an error
-
url
¶ The endpoint for operations on the user’s account
Action¶
-
class
doapi.
Action
[source]¶ An action resource, representing a change made to another resource.
Actions are created in response to almost all mutating requests on droplets, images, and floating IPs, and they can be retrieved with the
doapi.fetch_action()
,doapi.fetch_last_action()
,doapi.fetch_all_actions()
methods as well as thefetch_all_actions
,fetch_last_action
, andfetch_current_action
methods ofDroplet
,Image
, andFloatingIP
.The DigitalOcean API specifies the following fields for action objects:
Variables: - id (int) – a unique identifier for the action
- completed_at (
datetime.datetime
orNone
) – date & time of the action’s completion, orNone
if the action has not completed yet - region (
Region
) – the region in which the action occurred - region_slug (string) – the unique slug identifier for the region in which the action occurred
- resource_id (int) – the unique ID of the resource that the action operated
on. If the resource was a droplet or image, this will be its
id
field. If the resource was a floating IP, this will be the IP address as a 32-bit integer. - resource_type (string) – the type of resource that the action operated on:
"droplet"
,"image"
, or"floating_ip"
- started_at (datetime.datetime) – date & time of the action’s initiation
- status (string) – the current status of the action:
"in-progress"
,"completed"
, or"errored"
- type (string) – the type of action performed
-
__int__
()¶ Convert the resource to its unique integer ID
-
STATUS_IN_PROGRESS
= 'in-progress'¶ The status of actions that are currently still in progress
-
STATUS_COMPLETED
= 'completed'¶ The status of actions that have completed successfully
-
STATUS_ERRORED
= 'errored'¶ The status of actions that failed to complete successfully
-
url
¶ The endpoint for general operations on the individual action
-
fetch
()[source]¶ Fetch & return a new
Action
object representing the action’s current stateReturn type: Action Raises: DOAPIError – if the API endpoint replies with an error
-
fetch_resource
()[source]¶ Fetch & return the resource that the action operated on, or
None
if the resource no longer exists (specifically, if the API returns a 404)Return type: Droplet
,Image
,FloatingIP
, orNone
Raises: - ValueError – if the action has an unknown
resource_type
(This indicates a deficiency in the library; please report it!) - DOAPIError – if the API endpoint replies with a non-404 error
- ValueError – if the action has an unknown
-
wait
(wait_interval=None, wait_time=None)[source]¶ Poll the server periodically until the action has either completed or errored out and return its final state.
If
wait_time
is exceeded, aWaitTimeoutError
(containing the action’s most recently fetched state) is raised.If a
KeyboardInterrupt
is caught, the action’s most recently fetched state is returned immediately without waiting for completion.Changed in version 0.2.0: Raises
WaitTimeoutError
on timeoutParameters: - wait_interval (number) – how many seconds to sleep between
requests; defaults to the
doapi
object’swait_interval
if not specified orNone
- wait_time (number) – the total number of seconds after which the
method will raise an error if the action has not yet completed, or
a negative number to wait indefinitely; defaults to the
doapi
object’swait_time
if not specified orNone
Returns: the action’s final state
Return type: Raises: - DOAPIError – if the API endpoint replies with an error
- WaitTimeoutError – if
wait_time
is exceeded
- wait_interval (number) – how many seconds to sleep between
requests; defaults to the
-
raise_for_error
()[source]¶ New in version 0.2.0.
If the action’s status is
"errored"
, raise anActionError
. Otherwise, do nothing.Returns: None
Raises: ActionError – if the action’s status is "errored"
Region¶
-
class
doapi.
Region
[source]¶ A region resource, representing a physical datacenter in which droplets can be located.
Available regions can be retreived with the
doapi.fetch_all_regions()
method.The DigitalOcean API specifies the following fields for region objects:
Variables: - available (bool) – whether new droplets can be created in the region
- features (list of strings) – a list of strings naming the features available in the region
- name (string) – a human-readable name for the region
- sizes (list of strings) – the slugs of the sizes available in the region
- slug (string) – the unique slug identifier for the region
Size¶
-
class
doapi.
Size
[source]¶ A size resource, representing an option for the amount of RAM, disk space, etc. provisioned for a droplet.
Available sizes can be retreived with the
doapi.fetch_all_sizes()
method.The DigitalOcean API specifies the following fields for size objects:
Variables: - available (bool) – whether new droplets can be created with this size
- disk (number) – disk size of a droplet of this size in gigabytes
- memory (number) – RAM of a droplet of this size in megabytes
- price_hourly (number) – the hourly cost for a droplet of this size in USD
- price_monthly (number) – the monthly cost for a droplet of this size in USD
- regions (list of strings) – the slugs of the regions in which this size is available
- slug (string) – the unique slug identifier for the size
- transfer (number) – the amount of transfer bandwidth in terabytes available for a droplet of this size
- vcpus (int) – the number of virtual CPUs on a droplet of this size
Utility Classes¶
Exceptions¶
ActionError¶
-
exception
doapi.
ActionError
(action)[source]¶ Bases:
exceptions.Exception
New in version 0.2.0.
Raised when
raise_for_error()
is called on anAction
that failed to complete successfully
DOAPIError¶
-
exception
doapi.
DOAPIError
(response)[source]¶ Bases:
exceptions.Exception
An exception raised in reaction to the API endpoint responding with a 4xx or 5xx error. Any method that performs an API request may raise this error.
If the body of the error response is a JSON object, its fields will be added to the
DOAPIError
’s attributes (except where a pre-existing attribute would be overwritten). DigitalOcean error response bodies have been observed to consist of an object with two string fields,"id"
and"message"
.Note that this class is only for representing errors reported by the endpoint in response to API requests. Everything else that can go wrong uses the normal Python exceptions.
-
response
= None¶ The
requests.Response
object
-
http_error_msg
= None¶ An error message that should be appropriate for human consumption, containing the type of HTTP error, the URL that was requested, and the body of the response.
-
WaitTimeoutError¶
-
exception
doapi.
WaitTimeoutError
(in_progress, attr, value, wait_interval, wait_time)[source]¶ Bases:
exceptions.Exception
New in version 0.2.0.
Raised when the runtime of a
wait
method exceedswait_time
-
in_progress
= None¶ A list of any waited-on objects that have not yet completed
-
attr
= None¶ The objects’ attribute that was being monitored
-
wait_interval
= None¶ The
wait_interval
value for the wait operation
-
wait_time
= None¶ The
wait_time
value for the wait operation
-
DOEncoder¶
-
class
doapi.
DOEncoder
(skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, encoding='utf-8', default=None)[source]¶ Bases:
json.encoder.JSONEncoder
A
json.JSONEncoder
subclass that converts resource objects todict
s for JSONification. It also converts iterators to lists.-
default
(obj)[source]¶ Implement this method in a subclass such that it returns a serializable object for
o
, or calls the base implementation (to raise aTypeError
).For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return JSONEncoder.default(self, o)
-
Examples¶
# Shut.
# Down.
# EVERYTHING.
actions = []
for droplet in manager.fetch_all_droplets():
if droplet.active: # Only droplets that are already up can be shut down.
actions.append(droplet.shutdown())
# `list` forces the generator returned by `wait_actions` to be fully
# evaluated, thereby making Python wait until all of the shutdown actions
# have completed.
list(manager.wait_actions(actions))
Command-Line Programs¶
Common CLI Behavior¶
Todo
Document the plain doapi command
API Authentication¶
In order to perform API requests, an OAuth token must be supplied to doapi so that it can authenticate with the DigitalOcean server. You can generate an OAuth token for your account via the “Apps & API” section of your DigitalOcean account’s control panel.
The doapi commands will look for an OAuth token in the following locations, in order:
- Specified on the command line with
--api-token token
or--api-token-file file
- The value of the
DO_API_TOKEN
environment variable - The contents of a
.doapi
file in your home directory
Handling Non-Uniqueness of Identifiers¶
Most resources in the API are referred to by only a single identifier each, but droplets, images, and SSH keys can be referred to by either a unique ID number, a unique slug (for certain images), a unique fingerprint (for SSH keys), or a (potentially) non-unique name.
When the user specifies an object identifier that could be an ID, slug, fingerprint, or name, the default order of resolution is as follows:
- If the identifier is an integer and there is an object of the relevant type with that integer as its ID number, doapi uses that object.
- For images, if there is an image whose slug equals the identifier, doapi uses that image.
- For SSH keys, if the identifier is in the form of an SSH public key fingerprint (16 colon-separated two-digit hexadecimal integers) and there is an SSH key with that fingerprint registered with the user’s DigitalOcean account, doapi uses that SSH key.
- Otherwise, the identifier is assumed to be a name, and if there exists exactly one object of the relevant type with that name, doapi uses that object. If there is not exactly one object with that name, doapi will exit without taking any action; if the name is shared by multiple objects, the error message will include all of the objects’ ID numbers.
For subcommands that operate on lists of objects, this behavior can be changed
by passing the --multiple
option to the subcommand, causing any
identifier shared by multiple objects of the relevant type (whether as ID,
slug, fingerprint, and/or name) to be interpreted as a list of all of those
objects in unspecified order.
In all cases, if the same object is specified more than once on the command line, all occurrences after the first are ignored with a warning.
Changed in version 0.2.0: --multiple
now also matches by ID, slug, & fingerprint
Todo
Mention --unique
and the warnings in its absence
Universal Options¶
All commands take the following options in addition to those listed in their individual documentation:
-
--api-token
<token>
¶ Use
<token>
as an OAuth token for authentication with the API; mutually exclusive with--api-token-file
-
--api-token-file
<file>
¶ Use the contents of
<file>
(after stripping leading & trailing whitespace) as an OAuth token for authentication with the API; mutually exclusive with--api-token
-
--endpoint
<URL>
¶ Use
<URL>
as the base URL for all API requests; default value:https://api.digitalocean.com
(the official DigitalOcean API endpoint)
-
--help
¶
Show command usage and exit
-
--timeout
<seconds>
¶ The maximum number of seconds to wait when attempting to connect to or read from the remote endpoint; default value: no timeout
-
--version
¶
Show doapi version and exit
Note that these options (other than --help
) cannot be attached to
subcommands:
doapi-droplet --timeout 1000 show # Good
doapi --timeout 1000 droplet show # Good
doapi-droplet show --timeout 1000 # Bad!
Waiting Options¶
By default, all subcommands that perform non-atomic actions return immediately
after initiating the action, without waiting for it to complete. They can be
made to instead wait until completion with the --wait
option, which
can be configured further with --wait-interval
and
--wait-time
, as described below:
-
-w
,
--wait
¶
Periodically poll the server for the current status of all actions until they all complete or error out or until the time limit specified by
--wait-time
is exceeded. If this action is not specified, the subcommand will exit immediately after initiating the actions.
-
--wait-interval
<seconds>
¶ How often to poll the server for the actions’ current statuses; default value: 2 seconds
Changed in version 0.2.0: Default value changed from 5 seconds to 2 seconds
-
--wait-time
<seconds>
¶ The maximum number of seconds to wait for all actions to complete. After this much time has passed since program invocation, any remaining in-progress actions will be output immediately without waiting for them to finish.
If
--wait
is specified but this option is not, the subcommand will wait indefinitely.
doapi-account¶
NAME¶
doapi-account — fetch DigitalOcean account data
SYNOPSIS¶
doapi-account [<universal options>] [--rate-limit]
DESCRIPTION¶
doapi-account displays the current information about your
DigitalOcean account as available via the API. The account information is
output as an Account
object converted to JSON.
OPTIONS¶
In addition to the universal options common to all doapi commands, doapi-account takes the following:
-
--rate-limit
¶
Fetch the account data, but instead of displaying it, output the rate limit headers from the response. (The account data is only requested so that there’s a response to get the headers from.)
doapi-action¶
NAME¶
doapi-action — manage DigitalOcean API actions
SYNOPSIS¶
doapi-action show [<action> ...]
doapi-action show {--in-progress | --last}
doapi-action wait [--wait-time <seconds>] [--wait-interval <seconds>] [<action> ...]
doapi-action resource <action> ...
doapi-action resource {--in-progress | --last}
doapi-action also takes the universal options common to all doapi commands.
Actions are specified by ID number.
show¶
doapi-action show [<action> ...]
doapi-action show {--in-progress | --last}
Show the given actions. If no actions or flags are specified, all actions ever
performed on the account are shown. The actions are output as a list of
Action
objects converted to JSON.
wait¶
doapi-action wait [--wait-time <seconds>] [--wait-interval <seconds>] [<action> ...]
Wait for the given actions to either complete or error out. The finished
actions are output as a list of Action
objects converted to JSON, with each
action output (roughly) as soon as it finishes. If no actions are specified,
wait will wait for all currently in-progress actions to complete.
Options¶
-
--wait-interval
<seconds>
¶ How often to poll the server for the actions’ current statuses; default value: 5 seconds
-
--wait-time
<seconds>
¶ The maximum number of seconds to wait for all actions to complete. After this much time has passed since program invocation, any remaining in-progress actions will be output immediately without waiting for them to finish.
If this option is not specified, wait will wait indefinitely.
resource¶
doapi-action resource <action> ...
doapi-action resource {--in-progress | --last}
Show the resources that the specified actions operated on. The resources are
output as a list of Droplet
, Image
, and/or FloatingIP
objects converted
to JSON. Resources that no longer exist are output as null
.
Options¶
-
--in-progress
¶
Show only the resources currently being acted upon
-
--last
¶
Show only the resource operated on by the account’s most recent action. If multiple actions were triggered simultaneously, the choice of which to display is undefined. If no actions have ever been performed on the account, the output is
null
.
doapi-domain¶
NAME¶
doapi-domain — manage DigitalOcean domains & domain records
SYNOPSIS¶
doapi-domain new <domain> <ip address>
doapi-domain show [<domain> ...]
doapi-domain delete <domain> ...
doapi-domain new-record [--priority <int>] [--port <int>] [--weight <int>]
[--delete] <domain> <type> <name> <data>
doapi-domain show-record <domain> [<record id> ...]
doapi-domain update-record [--type <type>]
[--name <name>]
[--data <data>]
[--port <int> | --no-port]
[--priority <int> | --no-priority]
[--weight <int> | --no-weight]
<domain> <record id>
doapi-domain delete-record <domain> <record id> [<record id> ...]
doapi-domain also takes the universal options common to all doapi commands.
Domains are specified as the base domain name without any subdomains (e.g.,
example.com
, never www.example.com
). Records of a given domain are
specified by ID number.
new¶
doapi-domain new <domain> <ip address>
Set up a domain name <domain>
pointing to <ip address>
. The new domain
is output as a Domain
object converted to JSON.
Note that this command does not actually register a new domain name; it merely configures DigitalOcean’s nameservers to provide DNS resolution for the domain. See How To Set Up a Host Name with DigitalOcean for more information.
show¶
doapi-domain show [<domain> ...]
Show domains. If no domains are specified, all domains registered to the
account are shown. The domains are output as a list of Domain
objects
converted to JSON.
delete¶
doapi-domain delete <domain> ...
Delete domains. If any of the given domains do not exist, nothing is deleted. There is no output.
new-record¶
doapi-domain new-record [--priority <int>] [--port <int>] [--weight <int>]
[--delete] <domain> <type> <name> <data>
Add a new domain record with the given type, name, & data to domain
<domain>
. The new record is output as a DomainRecord
object converted to
JSON.
Options¶
-
--delete
¶
After creating the new record, delete any old records with the same type & name.
-
--port
<int>
¶ Specify the port on which the service is available (SRV records only)
-
--priority
<int>
¶ Specify the priority for the new record (SRV and MX records only)
-
--weight
<int>
¶ Specify the weight for the new record (SRV records only)
show-record¶
doapi-domain show-record <domain> [<record id> ...]
Show records for domain <domain>
. If no records are specified, all records
for the domain are shown. The records are output as a list of DomainRecord
objects converted to JSON.
update-record¶
doapi-domain update-record [--type <type>]
[--name <name>]
[--data <data>]
[--port <int> | --no-port]
[--priority <int> | --no-priority]
[--weight <int> | --no-weight]
<domain> <record id>
Modify one or more fields of a domain record. The updated record is output as
a DomainRecord
object converted to JSON.
Options¶
-
--data
<data>
¶ Set the record’s data to
<data>
-
--name
<name>
¶ Set the record’s name to
<name>
-
--no-port
¶
Unset the record’s port field
-
--no-priority
¶
Unset the record’s priority field
-
--no-weight
¶
Unset the record’s weight field
-
--port
<int>
¶ Set the record’s port to
<int>
-
--priority
<int>
¶ Set the record’s priority to
<int>
-
--type
<type>
¶ Set the record’s type to
<type>
-
--weight
<int>
¶ Set the record’s weight to
<int>
delete-record¶
doapi-domain delete-record <domain> <record id> [<record id> ...]
Delete records of the given domain. If any of the given records do not exist, nothing is deleted. There is no output.
doapi-droplet¶
NAME¶
doapi-droplet — manage DigitalOcean droplets
SYNOPSIS¶
doapi-droplet new
-I|--image <image>
-S|--size <size>
-R|--region <region>
[-B|--backups]
[-6|--ipv6]
[-P|--private-networking]
[-U|--user-data <string|@file>]
[-K|--ssh-key <key>] ...
[--unique]
[-w|--wait] [--wait-time <seconds>] [--wait-interval <seconds>]
<name> ...
doapi-droplet show [-M|--multiple] [--tag <tag> | <droplet> ...]
doapi-droplet enable-backups [<wait options>] [-M|--multiple] {--tag <tag> | <droplet> ...}
doapi-droplet disable-backups [<wait options>] [-M|--multiple] {--tag <tag> | <droplet> ...}
doapi-droplet reboot [<wait options>] [-M|--multiple] <droplet> ...
doapi-droplet power-cycle [<wait options>] [-M|--multiple] {--tag <tag> | <droplet> ...}
doapi-droplet shutdown [<wait options>] [-M|--multiple] {--tag <tag> | <droplet> ...}
doapi-droplet power-off [<wait options>] [-M|--multiple] {--tag <tag> | <droplet> ...}
doapi-droplet power-on [<wait options>] [-M|--multiple] {--tag <tag> | <droplet> ...}
doapi-droplet password-reset [<wait options>] [-M|--multiple] <droplet> ...
doapi-droplet enable-ipv6 [<wait options>] [-M|--multiple] {--tag <tag> | <droplet> ...}
doapi-droplet enable-private-networking [<wait options>] [-M|--multiple] {--tag <tag> | <droplet> ...}
doapi-droplet show-snapshots [-M|--multiple] <droplet> ...
doapi-droplet backups [-M|--multiple] <droplet> ...
doapi-droplet kernels [-M|--multiple] <droplet> ...
doapi-droplet delete [-M|--multiple] {--tag <tag> | <droplet> ...}
doapi-droplet neighbors
doapi-droplet neighbors [-M|--multiple] <droplet> ...
doapi-droplet restore [<wait options>] <droplet> <backup>
doapi-droplet resize [<wait options>] [--disk] [-M|--multiple] <size> <droplet> ...
doapi-droplet rebuild [<wait options>] [-I|--image <image>] [-M|--multiple] <droplet> ...
doapi-droplet rename [<wait options>] [--unique] <droplet> <new name>
doapi-droplet snapshot [<wait options>] [--unique] <name> {--tag <tag> | <droplet> ...}
doapi-droplet change-kernel [<wait options>] [-M|--multiple] <kernel> <droplet> ...
doapi-droplet act [<wait options>] [-p|--params <JSON|@file>] [-M|--multiple] <type> {--tag <tag> | <droplet> ...}
doapi-droplet actions [--last | --in-progress] [-M|--multiple] <droplet> ...
doapi-droplet wait [--wait-time <seconds>] [--wait-interval <seconds>] [-M|--multiple] [-S|--status <status> | --locked | --unlocked] <droplet> ...
doapi-droplet tag [-M|--multiple] <tag> <droplet> ...
doapi-droplet untag [-M|--multiple] <tag> <droplet> ...
doapi-droplet also takes the universal options common to all doapi commands.
Droplets can be specified by ID number or name. A name that is also a valid ID is interpreted as such rather than as a name (and so droplets with such names must be referred to by their actual ID instead).
new¶
doapi-droplet new
-I|--image <image>
-S|--size <size>
-R|--region <region>
[-B|--backups]
[-6|--ipv6]
[-P|--private-networking]
[-U|--user-data <string|@file>]
[-K|--ssh-key <key>] ...
[--unique]
[-w|--wait] [--wait-time <seconds>] [--wait-interval <seconds>]
<name> ...
show¶
doapi-droplet show [-M|--multiple] [--tag <tag> | <droplet> ...]
Simple Actions¶
doapi-droplet enable-backups [<wait options>] [-M|--multiple] {--tag <tag> | <droplet> ...}
doapi-droplet disable-backups [<wait options>] [-M|--multiple] {--tag <tag> | <droplet> ...}
doapi-droplet reboot [<wait options>] [-M|--multiple] <droplet> ...
doapi-droplet power-cycle [<wait options>] [-M|--multiple] {--tag <tag> | <droplet> ...}
doapi-droplet shutdown [<wait options>] [-M|--multiple] {--tag <tag> | <droplet> ...}
doapi-droplet power-off [<wait options>] [-M|--multiple] {--tag <tag> | <droplet> ...}
doapi-droplet power-on [<wait options>] [-M|--multiple] {--tag <tag> | <droplet> ...}
doapi-droplet password-reset [<wait options>] [-M|--multiple] <droplet> ...
doapi-droplet enable-ipv6 [<wait options>] [-M|--multiple] {--tag <tag> | <droplet> ...}
doapi-droplet enable-private-networking [<wait options>] [-M|--multiple] {--tag <tag> | <droplet> ...}
show-snapshots¶
doapi-droplet show-snapshots [-M|--multiple] <droplet> ...
backups¶
doapi-droplet backups [-M|--multiple] <droplet> ...
kernels¶
doapi-droplet kernels [-M|--multiple] <droplet> ...
neighbors¶
doapi-droplet neighbors
doapi-droplet neighbors [-M|--multiple] <droplet> ...
restore¶
doapi-droplet restore [<wait options>] <droplet> <backup>
resize¶
doapi-droplet resize [<wait options>] [--disk] [-M|--multiple] <size> <droplet> ...
rebuild¶
doapi-droplet rebuild [<wait options>] [-I|--image <image>] [-M|--multiple] <droplet> ...
rename¶
doapi-droplet rename [<wait options>] [--unique] <droplet> <new name>
snapshot¶
doapi-droplet snapshot [<wait options>] [--unique] <name> {--tag <tag> | <droplet> ...}
change-kernel¶
doapi-droplet change-kernel [<wait options>] [-M|--multiple] <kernel> <droplet> ...
act¶
doapi-droplet act [<wait options>] [-p|--params <JSON|@file>] [-M|--multiple] <type> {--tag <tag> | <droplet> ...}
actions¶
doapi-droplet actions [--last | --in-progress] [-M|--multiple] <droplet> ...
wait¶
doapi-droplet wait [--wait-time <seconds>] [--wait-interval <seconds>] [-M|--multiple] [-S|--status <status> | --locked | --unlocked] <droplet> ...
delete¶
doapi-droplet delete [-M|--multiple] {--tag <tag> | <droplet> ...}
tag¶
doapi-droplet tag [-M|--multiple] <tag> <droplet> ...
untag¶
doapi-droplet untag [-M|--multiple] <tag> <droplet> ...
doapi-floating-ip¶
NAME¶
doapi-floating-ip — manage DigitalOcean floating IP addresses
SYNOPSIS¶
doapi-floating-ip new [<wait options>] -D|--droplet <droplet>
doapi-floating-ip new [<wait options>] -R|--region <region>
doapi-floating-ip show [<ip> ...]
doapi-floating-ip assign [<wait options>] <ip> <droplet>
doapi-floating-ip unassign [<wait options>] <ip> ...
doapi-floating-ip act [<wait options>] [-p|--params <JSON|@file>] <type> <ip> ...
doapi-floating-ip actions [--in-progress | --last] <ip> ...
doapi-floating-ip wait [--wait-interval <seconds>] [--wait-time <seconds>] <ip> ...
doapi-floating-ip delete <ip> ...
doapi-floating-ip also takes the universal options common to all doapi commands.
Floating IPs can be specified in either dotted-quad notation (e.g.,
127.0.0.1
) or as 32-bit integers (e.g., 2130706433
).
new¶
doapi-floating-ip new [<wait options>] -D|--droplet <droplet>
doapi-floating-ip new [<wait options>] -R|--region <region>
Create a new floating IP assigned to a droplet or reserved to a region. The
new IP is output as a FloatingIP
object converted to JSON.
Options¶
In addition to the waiting options, the new subcommand takes the following:
-
-D
<droplet>
,
--droplet
<droplet>
¶ Assign the new floating IP to the specified droplet (identified by ID or name). The floating IP will also be reserved to the droplet’s region.
-
-R
<region>
,
--region
<region>
¶ Reserve the floating IP to the specified region (identified by slug).
show¶
doapi-floating-ip show [<ip> ...]
Show floating IPs. If no IPs are specified, all IPs allocated to the account
are shown. The IPs are output as a list of FloatingIP
objects converted to
JSON.
assign¶
doapi-floating-ip assign [<wait options>] <ip> <droplet>
Assign the given floating IP to a given droplet (identified by ID or name).
The Action
object thus produced is output as JSON.
The assign subcommand only takes the waiting options.
unassign¶
doapi-floating-ip unassign [<wait options>] <ip> ...
Unassign the given floating IP(s) from their droplet(s). The Action
objects
thus produced are output as a JSON list.
The unassign subcommand only takes the waiting options.
act¶
doapi-floating-ip act [<wait options>] [-p|--params <JSON|@file>] <type> <ip> ...
Perform an arbitrary action of type <type>
(assign
, unassign
, or
something otherwise not implemented here) on one or more floating IPs. The
Action
objects thus produced are output as a JSON list.
Options¶
In addition to the waiting options, the act subcommand takes the following:
-
-p
<data>
,
--params
<data>
¶ A JSON object/dictionary of parameters to the action. If
<data>
begins with “@
”, the rest of the argument (if there is any) is treated as a file from which to read the JSON; a filename of-
causes data to be read from standard input.
actions¶
doapi-floating-ip actions [--in-progress | --last] <ip> ...
List all of the actions that have ever been performed on the given floating
IP(s). The results are output as a JSON list containing a sublist of Action
objects for each IP specified on the command line, in order.
Options¶
-
--in-progress
¶
Show only the currently in-progress action on each floating IP instead of a list of all actions. If there is currently no in-progress action on an IP, show
null
.
-
--last
¶
Show only the most recent action on each floating IP instead of a list of all actions. If multiple actions on a single IP were triggered simultaneously, the choice of which to return is undefined. If no actions were ever performed on a floating IP, show
null
.
wait¶
doapi-floating-ip wait [--wait-interval <seconds>] [--wait-time <seconds>] <ip> ...
Wait for the currently in-progress actions on the given floating IP(s) to
either complete or error out. The finished actions are output as a list of
Action
objects converted to JSON, with each action output (roughly) as soon
as it finishes. If there are no actions currently in progress on a given
floating IP, nothing will be output for it.
Options¶
-
--wait-interval
<seconds>
¶ How often to poll the server for the actions’ current statuses; default value: 2 seconds
-
--wait-time
<seconds>
¶ The maximum number of seconds to wait for all actions to complete. After this much time has passed since program invocation, any remaining in-progress actions will be output immediately without waiting for them to finish.
If this option is not specified, wait will wait indefinitely.
delete¶
doapi-floating-ip delete <ip> ...
Delete floating IPs. If any of the given floating IPs do not exist, nothing is deleted. There is no output.
doapi-image¶
NAME¶
doapi-image — manage DigitalOcean droplet images
SYNOPSIS¶
doapi-image show [-M|--multiple] [<image> ...]
doapi-image show {--application|--distribution|--type=<type>|--private}
doapi-image update [--unique] <image> <new name>
doapi-image convert [<wait options>] [-M|--multiple] <image> ...
doapi-image transfer [<wait options>] [-M|--multiple] <region> <image> ...
doapi-image act [<wait options>] [-p|--params <JSON|@file>] [-M|--multiple] <type> <image> ...
doapi-image actions [--in-progress | --last] [-M|--multiple] <image> ...
doapi-image wait [--wait-time <seconds>] [--wait-interval <seconds>] [-M|--multiple] <image> ...
doapi-image delete [-M|--multiple] <image> ...
doapi-image also takes the universal options common to all doapi commands.
Images can be specified by ID number, slug (if any), or name. A name that is also a valid ID or slug is interpreted as such rather than as a name (and so images with such names must be referred to by their ID instead).
show¶
doapi-image show [-M|--multiple] [<image> ...]
doapi-image show {--application|--distribution|--type=<type>|--private}
Show images. If no images or flags are specified, all images available to the
account are shown. The images are output as a list of Image
objects
converted to JSON.
Options¶
-
--application
¶
Only show application images
-
--distribution
¶
Only show distribution images
-
-M
,
--multiple
¶
Arguments that could refer to multiple images are interpreted as such rather than using the default resolution rules; see Handling Non-Uniqueness of Identifiers for more information.
-
--private
¶
Only show the user’s private images
-
--type
=<type>
¶ Only show images of type
<type>
(application
,distribution
, or something not otherwise implemented here)
update¶
doapi-image update [--unique] <image> <new name>
Update (i.e., rename) an image. The updated image is output as an Image
object converted to JSON.
convert¶
doapi-image convert [<wait options>] [-M|--multiple] <image> ...
Convert one or more images to snapshots. The Action
objects thus produced
are output as a JSON list.
Options¶
In addition to the waiting options, the convert subcommand takes the following:
-
-M
,
--multiple
¶
Arguments that could refer to multiple images are interpreted as such rather than using the default resolution rules; see Handling Non-Uniqueness of Identifiers for more information.
transfer¶
doapi-image transfer [<wait options>] [-M|--multiple] <region> <image> ...
Transfer one or more images to another region (identified by its slug). The
Action
objects thus produced are output as a JSON list.
Options¶
In addition to the waiting options, the transfer subcommand takes the following:
-
-M
,
--multiple
¶
Arguments that could refer to multiple images are interpreted as such rather than using the default resolution rules; see Handling Non-Uniqueness of Identifiers for more information.
act¶
doapi-image act [<wait options>] [-p|--params <JSON|@file>] [-M|--multiple] <type> <image> ...
Perform an arbitrary action of type <type>
(convert
, transfer
, or
something otherwise not implemented here) on one or more images. The Action
objects thus produced are output as a JSON list.
Options¶
In addition to the waiting options, the act subcommand takes the following:
-
-M
,
--multiple
¶
Arguments that could refer to multiple images are interpreted as such rather than using the default resolution rules; see Handling Non-Uniqueness of Identifiers for more information.
-
-p
<data>
,
--params
<data>
¶ A JSON object/dictionary of parameters to the action. If
<data>
begins with “@
”, the rest of the argument (if there is any) is treated as a file from which to read the JSON; a filename of-
causes data to be read from standard input.
actions¶
doapi-image actions [--in-progress | --last] <image> ...
List all of the actions that have ever been performed on the given image(s).
The results are output as a JSON list containing a sublist of Action
objects
for each image specified on the command line, in order.
Options¶
-
--in-progress
¶
Show only the currently in-progress action on each image instead of a list of all actions. If there is currently no in-progress action on an image, show
null
.
-
--last
¶
Show only the most recent action on each image instead of a list of all actions. If multiple actions on a single image were triggered simultaneously, the choice of which to return is undefined. If no actions were ever performed on an image, show
null
.
wait¶
doapi-image wait [--wait-interval <seconds>] [--wait-time <seconds>] <image> ...
Wait for the currently in-progress actions on the given image(s) to either
complete or error out. The finished actions are output as a list of Action
objects converted to JSON, with each action output (roughly) as soon as it
finishes. If there are no actions currently in progress on a given image,
nothing will be output for it.
Options¶
-
--wait-interval
<seconds>
¶ How often to poll the server for the actions’ current statuses; default value: 2 seconds
-
--wait-time
<seconds>
¶ The maximum number of seconds to wait for all actions to complete. After this much time has passed since program invocation, any remaining in-progress actions will be output immediately without waiting for them to finish.
If this option is not specified, wait will wait indefinitely.
delete¶
doapi-image delete [-M|--multiple] <image> ...
Delete images. If any of the given images do not exist, nothing is deleted. There is no output.
Options¶
-
-M
,
--multiple
¶
Arguments that could refer to multiple images are interpreted as such rather than using the default resolution rules; see Handling Non-Uniqueness of Identifiers for more information.
doapi-region¶
NAME¶
doapi-region — list available DigitalOcean droplet regions
SYNOPSIS¶
doapi-region [<universal options>]
DESCRIPTION¶
doapi-region lists all of the droplet regions available to your
DigitalOcean account. The regions are output as a list of Region
objects
converted to JSON.
OPTIONS¶
doapi-region only takes the universal options common to all doapi commands.
doapi-request¶
NAME¶
doapi-request — perform a raw DigitalOcean API request
SYNOPSIS¶
doapi-request [<universal options>]
[-d|--data <string|@file>]
[-D|--dump-header <file>]
[--paginate <key>]
[-X|--request <method>]
<URL>|<path>
DESCRIPTION¶
doapi-request makes a request to a DigitalOcean API endpoint and outputs the text of the response (if any) as nicely-formatted JSON. It’s like a DigitalOcean-centric curl(1) that doesn’t make you type out your API token every time, with an option for handling pagination.
A request can be made either to an absolute URL or to a path like
/v2/account
that will be appended to the API endpoint in use.
OPTIONS¶
In addition to the universal options common to all doapi commands, doapi-request takes the following:
-
-d
<data>
,
--data
<data>
¶ Send the given data (which must be valid JSON) in the body of the request. If
<data>
begins with “@
”, the rest of the argument (if there is any) is treated as a file from which to read the data; a filename of-
causes data to be read from standard input.--data
and--paginate
are mutually exclusive.
-
-D
<file>
,
--dump-header
<file>
¶ Dump the headers of the HTTP response as a JSON object to the given file. If
--paginate
is also used, only the headers for the last response will be dumped.<file>
may be-
to write the headers to standard output.
-
--paginate
<key>
¶ (
GET
method only) Assume that the API will respond with a paginated list of one or more values, i.e., an object containing a field<key>
mapped to a list of values and a field"links"
containing a URL for retrieving the next set of values in the result list, if any. Instead of performing a single request and outputting the response body, doapi-requests will perform multiple requests to retrieve all of the pages and will output a concatenated list of all of the values in the<key>
field of each page.--data
and--paginate
are mutually exclusive.
-
-X
<method>
,
--request
<method>
¶ Specifies the HTTP method to use for the request. Valid options are
GET
(the default),POST
,PUT
, andDELETE
(case insensitive).
doapi-size¶
NAME¶
doapi-size — list available DigitalOcean droplet sizes
SYNOPSIS¶
doapi-size [<universal options>]
DESCRIPTION¶
doapi-size lists all of the droplet sizes available to your
DigitalOcean account. The sizes are output as a list of Size
objects
converted to JSON.
OPTIONS¶
doapi-size only takes the universal options common to all doapi commands.
doapi-ssh-key¶
NAME¶
doapi-ssh-key — manage SSH public keys on DigitalOcean
SYNOPSIS¶
doapi-ssh-key new [--unique] <name> [<file>]
doapi-ssh-key show [-M|--multiple] [<ssh key> ...]
doapi-ssh-key update [--unique] <ssh key> <new name>
doapi-ssh-key delete [-M|--multiple] <ssh key> ...
doapi-ssh-key also takes the universal options common to all doapi commands.
SSH keys can be specified by ID number, fingerprint, or name. A name that is also a valid ID or fingerprint is interpreted as such rather than as a name (and so SSH keys with such names must be referred to by their ID or fingerprint instead).
new¶
doapi-ssh-key new [--unique] <name> [<file>]
Register the contents of <file>
(or standard input if no file is specified)
as a new SSH public key with name <name>
. The new key is output as an
SSHKey
object converted to JSON.
show¶
doapi-ssh-key show [-M|--multiple] [<ssh key> ...]
Show SSH keys. If no keys are specified, all keys registered to the account
are shown. The keys are output as a list of SSHKey
objects converted to
JSON.
Options¶
-
-M
,
--multiple
¶
Arguments that could refer to multiple SSH keys are interpreted as such rather than using the default resolution rules; see Handling Non-Uniqueness of Identifiers for more information.
update¶
doapi-ssh-key update [--unique] <ssh key> <new name>
Update (i.e., rename) an SSH key. The updated key is output as an SSHKey
object converted to JSON.
delete¶
doapi-ssh-key delete [-M|--multiple] <ssh key> ...
Delete SSH keys. If any of the given SSH keys do not exist, nothing is deleted. There is no output.
Options¶
-
-M
,
--multiple
¶
Arguments that could refer to multiple SSH keys are interpreted as such rather than using the default resolution rules; see Handling Non-Uniqueness of Identifiers for more information.
doapi-tag¶
NAME¶
doapi-tag — manage DigitalOcean tags
SYNOPSIS¶
doapi-tag new <tag> ...
doapi-tag show [<tag> ...]
doapi-tag update <tag> <new name>
doapi-tag delete <tag> ...
doapi-tag also takes the universal options common to all doapi commands.
new¶
doapi-tag new <tag> ...
Create one or more new tags with the given names. The new tags are output as
Tag
objects converted to JSON.
show¶
doapi-tag show [<tag> ...]
Show tags. If no tags are specified, all tags registered to the account are
shown. The tags are output as a list of Tag
objects converted to JSON.
To list the individual resources with a given tag, use the show
subcommand for the relevant resource type; e.g., to list all of the droplets
with a given tag, run doapi-droplet show --tag=tag
.
update¶
doapi-tag update <tag> <new name>
Update (i.e., rename) a tag. The updated tag is output as a Tag
object
converted to JSON.
delete¶
doapi-tag delete <tag> ...
Delete tags. If any of the given tags do not exist, nothing is deleted. There is no output.