Package: python-digitalocean-me
This library provides easy access to Digital Ocean APIs to deploy
droplets, images and more.How to installYou can install python-digitalocean usingpippip install -U python-digitaloceanor via sources:python setup.py installFeaturespython-digitalocean support all the features provided via
digitalocean.com APIs, such as:Get user’s DropletsGet user’s Images (Snapshot and Backups)Get public ImagesGet Droplet’s event statusCreate and Remove a DropletResize a DropletShutdown, restart and boot a DropletPower off, power on and “power cycle” a DropletPerform SnapshotEnable/Disable automatic BackupsRestore root password of a DropletExamplesListing the dropletsThis example shows how to list all the active droplets:importdigitaloceanmanager=digitalocean.Manager(token="secretspecialuniquesnowflake")print(manager.get_all_droplets())Shutdown all dropletsThis example shows how to shutdown all the active droplets:importdigitaloceanmanager=digitalocean.Manager(token="secretspecialuniquesnowflake")my_droplets=manager.get_all_droplets()fordropletinmy_droplets:droplet.shutdown()Creating a Droplet and checking its statusThis example shows how to create a droplet and how to check its statusimportdigitaloceandroplet=digitalocean.Droplet(token="secretspecialuniquesnowflake",name='Example',region='nyc2',# New York 2image='ubuntu-14-04-x64',# Ubuntu 14.04 x64size_slug='512mb',# 512MBbackups=True)droplet.create()Checking the status of the dropletactions=droplet.get_actions()foractioninactions:action.load()# Once it shows complete, droplet is up and runningprintaction.statusAdd SSHKey into DigitalOcean AccountfromdigitaloceanimportSSHKeyuser_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 keysmanager=digitalocean.Manager(token="secretspecialuniquesnowflake")keys=manager.get_all_sshkeys()droplet=digitalocean.Droplet(token="secretspecialuniquesnowflake",name='DropletWithSSHKeys',region='ams3',# Amsterimage='ubuntu-14-04-x64',# Ubuntu 14.04 x64size_slug='512mb',# 512MBssh_keys=keys,#Automatic conversionbackups=False)droplet.create()TestingTest using DockerTo test this python-digitalocean you can usedockerto have aclean 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-testsNote: 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 manuallyUsepytestto 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.txtTo run all the tests manually use py.test command:$ python -m pytestLinksGitHub:https://github.com/aliasifk/python-digitaloceanPyPI page:https://pypi.python.org/pypi/python-digitalocean/Author Website:http://who.is.lorenzo.setale.me/?Author Blog:http://blog.setale.me/