Skip to main content

Python wrapper for Digital Ocean API V2

Project description

Python wrapper for Digital Ocean API V2.

Latest Version

Number of PyPI downloads

Travis Build

Installation

pip install dosa

Usage

import dosa

API_KEY = 'Your API Key'
dosa.set_debug()  # enables debug logs

client = dosa.Client(api_key=API_KEY)

# Droplets
client.droplets.list()
status, result = client.droplets.create(name='terminator', region='nyc2',\
    size='512mb', image='ubuntu-14-04-x32', ssh_keys=[12345])
new_droplet_id = result['id']

# Droplet
new_droplet = client.Droplet(new_droplet_id)
print(new_droplet.info())
## shortcuts
new_droplet.status()
new_droplet.ip_addresses()
client.droplets.delete(new_droplet_id)

# SSH Keys
pub_key = open('~/.ssh/id_rsa.pub').read()
client.keys.create(name='RSA key', public_key=pub_key)
client.keys.list()

# Images
client.images.list()
client.images.all()
client.images.search('ubuntu', 'sgp1', show_op=True)

# Domains
client.domains.list()
client.domains.all()
client.domains.create(name='example.com', ip_address='1.2.3.4')
client.domains.delete(id='example.com')

### Get specific domain
domain = client.Domain(domain='example.com')
domain.info()

# Domain Records
dr = client.DomainRecords(domain='example.com')
dr.list()
dr.create(type='A', name='example.com', data='162.10.66.0')

### Get specific domain record for a domain
record = dr.Record(record_id='7976006')
record.info()
record.update(name='new.example.com')

# Firewalls
## Create a firewall
params = {
 'inbound_rules': [{'ports': '22',
   'protocol': 'tcp',
   'sources': {'addresses': ['0.0.0.0/0', '::/0']}},
  {'ports': '80',
   'protocol': 'tcp',
   'sources': {'addresses': ['0.0.0.0/0', '::/0']}}],
 'name': 'firewall',
 'outbound_rules': [{'destinations': {'addresses': ['0.0.0.0/0', '::/0']},
   'ports': 'all',
   'protocol': 'tcp'}],
 'tags': []}
firewall = client.firewalls.create(**params)

# search firewall by name
firewall = client.firewalls.get_by_name('firewall')

## add a droplet to a firewall
firewall.add_droplet(new_droplet_id)

## remove a droplet from a firewall
firewall.remove_droplet(new_droplet_id)

## delete a firewall
client.firewalls.delete(id=firewall.id)

# Extras
# $ ls keys/
# rsa_pub1.id  rsa_pub2.key  rsa_pub3.key
keys_dir = 'keys'
client.sync_ssh_keys(keys_dir)

Notes

Image search:

>>> client.images.search('ubuntu', region='sgp1', show_op=True)

Above code snippets searches for images containing ubuntu in description or slug. Since region is specified (sgp1), only images in sgp1 region would be considered. If no region is specified all regions are included.

Credits

Created while working on Scroll.in’s project.

Dosa?

"Paper Masala Dosa" by SteveR- - http://www.flickr.com/photos/git/3936135033/. Licensed under Creative Commons Attribution 2.0 via Wikimedia Commons

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

dosa-0.10.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

dosa-0.10-py2.py3-none-any.whl (14.5 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file dosa-0.10.tar.gz.

File metadata

  • Download URL: dosa-0.10.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.6.7

File hashes

Hashes for dosa-0.10.tar.gz
Algorithm Hash digest
SHA256 d3535884264465ea8d4f648f849be5099d20483603d7bffc9c76015a37a4330f
MD5 81b458ecccf722e3442e6a69d72bc4de
BLAKE2b-256 ee6f64d74df1add54815ec5bff58de90a5d67c86a1e28471bf638d4273a793ba

See more details on using hashes here.

File details

Details for the file dosa-0.10-py2.py3-none-any.whl.

File metadata

  • Download URL: dosa-0.10-py2.py3-none-any.whl
  • Upload date:
  • Size: 14.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.6.7

File hashes

Hashes for dosa-0.10-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 61493fd9360b291e8d4a40d6fa0159cb88e7fe6788a136daa3a3444dfef405f2
MD5 cbe747b412f22b3aae58eadd85e614cd
BLAKE2b-256 443d0828ae9f7aac01fd7150e41c5af61a2330735c87c4fa7ba47759cd2bc9d0

See more details on using hashes here.

Supported by

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