Skip to main content

digitalocean.com API to manage Droplets and Images

Project description

This library provides easy access to Digital Ocean APIs to deploy droplets, images and more.

image0

image1
image2
image3

How to install

You can install python-digitalocean using pip

pip install -U python-digitalocean

or via sources:

python setup.py install

Features

python-digitalocean support all the features provided via digitalocean.com APIs, such as:

  • Get user’s Droplets

  • Get user’s Images (Snapshot and Backups)

  • Get public Images

  • Get Droplet’s event status

  • Create and Remove a Droplet

  • Resize a Droplet

  • Shutdown, restart and boot a Droplet

  • Power off, power on and “power cycle” a Droplet

  • Perform Snapshot

  • Enable/Disable automatic Backups

  • Restore root password of a Droplet

 Examples

Listing the droplets

This example shows how to list all the active droplets:

import digitalocean
manager = digitalocean.Manager(token="secretspecialuniquesnowflake")
print(manager.get_all_droplets())

Shutdown all droplets

This example shows how to shutdown all the active droplets:

import digitalocean
manager = digitalocean.Manager(token="secretspecialuniquesnowflake")
my_droplets = manager.get_all_droplets()
for droplet in my_droplets:
    droplet.shutdown()

Creating a Droplet and checking its status

This example shows how to create a droplet and how to check its status

import digitalocean
droplet = digitalocean.Droplet(token="secretspecialuniquesnowflake",
                               name='Example',
                               region='nyc2', # New York 2
                               image='ubuntu-14-04-x64', # Ubuntu 14.04 x64
                               size_slug='512mb',  # 512MB
                               backups=True)
droplet.create()

Checking the status of the droplet

actions = droplet.get_actions()
for action in actions:
    action.load()
    # Once it shows complete, droplet is up and running
    print action.status

Add SSHKey into DigitalOcean Account

from digitalocean import SSHKey

user_ssh_key = open('/home/<$USER>/.ssh/id_rsa.pub').read()
key = SSHKey(token='secretspecialuniquesnowflake',
             name='uniquehostname',
             public_key=user_ssh_key)
key.create()

Creating a new droplet with all your SSH keys

manager = digitalocean.Manager(token="secretspecialuniquesnowflake")
keys = manager.get_all_sshkeys()

droplet = digitalocean.Droplet(token="secretspecialuniquesnowflake",
                               name='DropletWithSSHKeys',
                               region='ams3', # Amster
                               image='ubuntu-14-04-x64', # Ubuntu 14.04 x64
                               size_slug='512mb',  # 512MB
                               ssh_keys=keys, #Automatic conversion
                               backups=False)
droplet.create()

Testing

Test using Docker

To test this python-digitalocean you can use docker to have a clean environment automatically. First you have to build the container by running in your shell on the repository directory:

docker build -t "pdo-tests" .

Then you can run all the tests (for both python 2 and python 3)

docker run pdo-tests

Note: This will use Ubuntu 14.04 as base and use your repository to run tests. So every time you edit some files, please run these commands to perform tests on your changes.

Testing using pytest manually

Use pytest to perform testing. It is recommended to use a dedicated virtualenv to perform tests, using these commands:

$ virtualenv /tmp/digitalocean_env
$ source /tmp/digitalocean_env/bin/activate
$ pip install -r requirements.txt

To run all the tests manually use py.test command:

$ python -m pytest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python-digitalocean-1.12.tar.gz (18.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python-digitalocean-1.12.macosx-10.13-x86_64.tar.gz (48.1 kB view details)

Uploaded Source

File details

Details for the file python-digitalocean-1.12.tar.gz.

File metadata

File hashes

Hashes for python-digitalocean-1.12.tar.gz
Algorithm Hash digest
SHA256 1b5f3295fdf916dc1045f9b5576b50491f1a8a45da448692dc0b1a1ef1e34eb3
MD5 3dd049bdf49c7e5ef90295f9b572c8ed
BLAKE2b-256 6d3507273f28fb550f92ab0db432e5b64849b8786bc16589eb29d83a453df861

See more details on using hashes here.

File details

Details for the file python-digitalocean-1.12.macosx-10.13-x86_64.tar.gz.

File metadata

File hashes

Hashes for python-digitalocean-1.12.macosx-10.13-x86_64.tar.gz
Algorithm Hash digest
SHA256 65b3d8d1c5716714c59686f27f35fc915ac169cbfa9cbd4da8b5f4e191840362
MD5 e6880cf38f9f6c7ee2436c4259c27a80
BLAKE2b-256 0a2141e53e1f55453a789c4eab97e92ede6e37fbe287a2d36479acb15eb0bd13

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page