Difference between revisions of "Category:DigitalOcean"
| Line 43: | Line 43: | ||
* sfo1 ("San Francisco 1") | * sfo1 ("San Francisco 1") | ||
* sgp1 ("Singapore 1") | * sgp1 ("Singapore 1") | ||
| + | |||
| + | A quick-and-dirty way to get a pretty table output of the DigitalOcean regions available for Droplets (and the associated sizes and features) is with a Python script something like the following: | ||
| + | |||
| + | <pre> | ||
| + | #!/usr/bin/env python | ||
| + | import json | ||
| + | from prettytable import PrettyTable | ||
| + | |||
| + | # Create the 'do_regions.json' file by saving the output of: | ||
| + | # $ curl "${API_URL}/regions" \ | ||
| + | # -H "Authorization: Bearer ${TOKEN}" \ | ||
| + | # -H "Content-Type: application/json" > do_regions.json | ||
| + | |||
| + | with open('do_regions.json') as json_regions: | ||
| + | data = json.load(json_regions) | ||
| + | |||
| + | table = PrettyTable(["Slug", "Name", "Sizes", "Features"]) | ||
| + | table.align = "l" | ||
| + | |||
| + | for region in data["regions"]: | ||
| + | slug = region["slug"] | ||
| + | name = region["name"] | ||
| + | if region["available"]: | ||
| + | sizes = ', '.join(region["sizes"]) | ||
| + | else: | ||
| + | sizes = "<unavailable>" | ||
| + | features = ', '.join(region["features"]) | ||
| + | |||
| + | table.add_row([slug, name, sizes, features]) | ||
| + | |||
| + | print table | ||
| + | </pre> | ||
| + | |||
| + | Running the above script produces: | ||
| + | <pre> | ||
| + | +------+-----------------+---------------------------------------------------+-----------------------------------------------------+ | ||
| + | | Slug | Name | Sizes | Features | | ||
| + | +------+-----------------+---------------------------------------------------+-----------------------------------------------------+ | ||
| + | | nyc1 | New York 1 | <unavailable> | virtio, backups, metadata | | ||
| + | | ams1 | Amsterdam 1 | <unavailable> | virtio, backups | | ||
| + | | sfo1 | San Francisco 1 | 32gb, 16gb, 2gb, 1gb, 4gb, 8gb, 512mb, 64gb, 48gb | virtio, private_networking, backups, ipv6, metadata | | ||
| + | | nyc2 | New York 2 | 32gb, 16gb, 2gb, 1gb, 4gb, 8gb, 512mb, 64gb, 48gb | virtio, private_networking, backups | | ||
| + | | ams2 | Amsterdam 2 | 32gb, 16gb, 2gb, 1gb, 4gb, 8gb, 512mb, 64gb, 48gb | virtio, private_networking, backups, ipv6, metadata | | ||
| + | | sgp1 | Singapore 1 | 32gb, 16gb, 2gb, 1gb, 4gb, 8gb, 512mb, 64gb, 48gb | virtio, private_networking, backups, ipv6, metadata | | ||
| + | | lon1 | London 1 | 32gb, 16gb, 2gb, 1gb, 4gb, 8gb, 512mb, 64gb, 48gb | virtio, private_networking, backups, ipv6, metadata | | ||
| + | | nyc3 | New York 3 | 32gb, 16gb, 2gb, 1gb, 4gb, 8gb, 512mb, 64gb, 48gb | virtio, private_networking, backups, ipv6, metadata | | ||
| + | | ams3 | Amsterdam 3 | 32gb, 16gb, 2gb, 1gb, 4gb, 8gb, 512mb, 64gb, 48gb | virtio, private_networking, backups, ipv6, metadata | | ||
| + | | fra1 | Frankfurt 1 | 32gb, 16gb, 2gb, 1gb, 4gb, 8gb, 512mb, 64gb, 48gb | virtio, private_networking, backups, ipv6, metadata | | ||
| + | +------+-----------------+---------------------------------------------------+-----------------------------------------------------+ | ||
| + | </pre> | ||
===Droplets=== | ===Droplets=== | ||
| Line 99: | Line 149: | ||
-H "Authorization: Bearer ${TOKEN}" \ | -H "Authorization: Bearer ${TOKEN}" \ | ||
-H "Content-Type: application/json" | python -mjson.tool | -H "Content-Type: application/json" | python -mjson.tool | ||
| + | |||
| + | Or, pretty print the output: | ||
| + | $ curl -sXGET "${API_URL}/droplets" \ | ||
| + | -H "Authorization: Bearer ${TOKEN}" \ | ||
| + | -H "Content-Type: application/json" |\ | ||
| + | python -c 'import sys,json;data=json.loads(sys.stdin.read());\ | ||
| + | print "ID\tName\tRegion\n";\ | ||
| + | print "\n".join(["%s\t%s\t%s"%(d["id"],d["name"],d["region"]["slug"])\ | ||
| + | for d in data["droplets"]])'|column -t | ||
| + | |||
| + | ID Name Region | ||
| + | 1234567 my-test-droplet-1 nyc3 | ||
| + | 2345678 my-test-droplet-2 ams1 | ||
| + | |||
| + | * List the details of a given Droplet: | ||
| + | |||
| + | $ DROPLET_ID=1234567 | ||
| + | $ curl -sXGET "${API_URL}/droplets/${DROPLET_ID}" -H "Authorization: Bearer ${TOKEN}" -H "Content-Type: application/json" | python -mjson.tool | ||
| + | |||
| + | ===Images=== | ||
| + | |||
| + | A quick-and-dirty way to get a pretty table output of the DigitalOcean images available for Droplets is with a Python script something like the following: | ||
| + | <pre> | ||
| + | #!/usr/bin/env python | ||
| + | import json | ||
| + | from prettytable import PrettyTable | ||
| + | |||
| + | # Create the 'do_images.json' file by saving the output of: | ||
| + | # $ curl "${API_URL}/images" \ | ||
| + | # -H "Authorization: Bearer ${TOKEN}" \ | ||
| + | # -H "Content-Type: application/json" > do_images.json | ||
| + | |||
| + | with open('do_images.json') as json_data: | ||
| + | data = json.load(json_data) | ||
| + | |||
| + | table = PrettyTable(["ID","Slug","Distribution","Name","Type"]) | ||
| + | table.align = "l" | ||
| + | |||
| + | for image in data["images"]: | ||
| + | image_id = image["id"] | ||
| + | slug = image["slug"] | ||
| + | distribution = image["distribution"] | ||
| + | name = image["name"] | ||
| + | image_type = image["type"] | ||
| + | table.add_row([image_id,slug,distribution,name,image_type]) | ||
| + | |||
| + | print table | ||
| + | </pre> | ||
| + | |||
| + | Running the above script produces: | ||
| + | <pre> | ||
| + | +----------+------------------+--------------+----------------------+-----------+ | ||
| + | | ID | Slug | Distribution | Name | Type | | ||
| + | +----------+------------------+--------------+----------------------+-----------+ | ||
| + | | 11732785 | None | Debian | Maintenance Mode | snapshot | | ||
| + | | 11420434 | coreos-stable | CoreOS | 633.1.0 (stable) | snapshot | | ||
| + | | 11434448 | coreos-beta | CoreOS | 647.0.0 (beta) | snapshot | | ||
| + | | 11657005 | coreos-alpha | CoreOS | 668.2.0 (alpha) | snapshot | | ||
| + | | 11385199 | None | Debian | vum-easter-move | snapshot | | ||
| + | | 11594346 | None | Ubuntu | blushibiza.com final | temporary | | ||
| + | | 6370882 | fedora-20-x64 | Fedora | 20 x64 | snapshot | | ||
| + | | 6370885 | fedora-20-x32 | Fedora | 20 x32 | snapshot | | ||
| + | | 6372321 | centos-5-8-x64 | CentOS | 5.10 x64 | snapshot | | ||
| + | | 6372425 | centos-5-8-x32 | CentOS | 5.10 x32 | snapshot | | ||
| + | | 6372581 | debian-6-0-x64 | Debian | 6.0 x64 | snapshot | | ||
| + | | 6372662 | debian-6-0-x32 | Debian | 6.0 x32 | snapshot | | ||
| + | | 9640922 | fedora-21-x64 | Fedora | 21 x64 | snapshot | | ||
| + | | 9801948 | ubuntu-14-04-x32 | Ubuntu | 14.04 x32 | snapshot | | ||
| + | | 9801950 | ubuntu-14-04-x64 | Ubuntu | 14.04 x64 | snapshot | | ||
| + | | 9801951 | ubuntu-14-10-x32 | Ubuntu | 14.10 x32 | snapshot | | ||
| + | | 9801954 | ubuntu-14-10-x64 | Ubuntu | 14.10 x64 | snapshot | | ||
| + | | 10144573 | freebsd-10-1-x64 | FreeBSD | 10.1 | snapshot | | ||
| + | | 10321756 | ubuntu-12-04-x64 | Ubuntu | 12.04.5 x64 | snapshot | | ||
| + | | 10321777 | ubuntu-12-04-x32 | Ubuntu | 12.04.5 x32 | snapshot | | ||
| + | +----------+------------------+--------------+----------------------+-----------+ | ||
| + | </pre> | ||
==External links== | ==External links== | ||
Revision as of 23:04, 5 May 2015
This category will be all about using DigitalOcean's various Cloud products and services.
Contents
DigitalOcean API
Note: This category and associated articles will only cover version 2 (v2) of the DigitalOcean API.
Environment variables
$ API_URL="https://api.digitalocean.com/v2" $ TOKEN=<YOUR_API_TOKEN>
I will be using the above environment variables for the remainder of this article.
Account
- Get your DigitalOcean (basic) account information:
$ curl -sXGET "${API_URL}/account" \
-H "Authorization: Bearer ${TOKEN}" \
-H "Content-Type: application/json" | python -mjson.tool
{
"account": {
"droplet_limit": 25,
"email": "bob@example.com",
"email_verified": true,
"uuid": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
}
}
Regions
$ curl "${API_URL}/regions" \
-H "Authorization: Bearer ${TOKEN}" \
-H "Content-Type: application/json" | python -mjson.tool
- ams1 ("Amsterdam 1")
- ams2 ("Amsterdam 2")
- ams3 ("Amsterdam 3")
- fra1 ("Frankfurt 1")
- lon1 ("London 1")
- nyc1 ("New York 1")
- nyc2 ("New York 2")
- nyc3 ("New York 3")
- sfo1 ("San Francisco 1")
- sgp1 ("Singapore 1")
A quick-and-dirty way to get a pretty table output of the DigitalOcean regions available for Droplets (and the associated sizes and features) is with a Python script something like the following:
#!/usr/bin/env python
import json
from prettytable import PrettyTable
# Create the 'do_regions.json' file by saving the output of:
# $ curl "${API_URL}/regions" \
# -H "Authorization: Bearer ${TOKEN}" \
# -H "Content-Type: application/json" > do_regions.json
with open('do_regions.json') as json_regions:
data = json.load(json_regions)
table = PrettyTable(["Slug", "Name", "Sizes", "Features"])
table.align = "l"
for region in data["regions"]:
slug = region["slug"]
name = region["name"]
if region["available"]:
sizes = ', '.join(region["sizes"])
else:
sizes = "<unavailable>"
features = ', '.join(region["features"])
table.add_row([slug, name, sizes, features])
print table
Running the above script produces:
+------+-----------------+---------------------------------------------------+-----------------------------------------------------+ | Slug | Name | Sizes | Features | +------+-----------------+---------------------------------------------------+-----------------------------------------------------+ | nyc1 | New York 1 | <unavailable> | virtio, backups, metadata | | ams1 | Amsterdam 1 | <unavailable> | virtio, backups | | sfo1 | San Francisco 1 | 32gb, 16gb, 2gb, 1gb, 4gb, 8gb, 512mb, 64gb, 48gb | virtio, private_networking, backups, ipv6, metadata | | nyc2 | New York 2 | 32gb, 16gb, 2gb, 1gb, 4gb, 8gb, 512mb, 64gb, 48gb | virtio, private_networking, backups | | ams2 | Amsterdam 2 | 32gb, 16gb, 2gb, 1gb, 4gb, 8gb, 512mb, 64gb, 48gb | virtio, private_networking, backups, ipv6, metadata | | sgp1 | Singapore 1 | 32gb, 16gb, 2gb, 1gb, 4gb, 8gb, 512mb, 64gb, 48gb | virtio, private_networking, backups, ipv6, metadata | | lon1 | London 1 | 32gb, 16gb, 2gb, 1gb, 4gb, 8gb, 512mb, 64gb, 48gb | virtio, private_networking, backups, ipv6, metadata | | nyc3 | New York 3 | 32gb, 16gb, 2gb, 1gb, 4gb, 8gb, 512mb, 64gb, 48gb | virtio, private_networking, backups, ipv6, metadata | | ams3 | Amsterdam 3 | 32gb, 16gb, 2gb, 1gb, 4gb, 8gb, 512mb, 64gb, 48gb | virtio, private_networking, backups, ipv6, metadata | | fra1 | Frankfurt 1 | 32gb, 16gb, 2gb, 1gb, 4gb, 8gb, 512mb, 64gb, 48gb | virtio, private_networking, backups, ipv6, metadata | +------+-----------------+---------------------------------------------------+-----------------------------------------------------+
Droplets
- Create a Droplet:
$ curl -vXPOST "${API_URL}/droplets" \
-d'{"name":"my-test-droplet","region":"nyc3","size":"512mb","image":"ubuntu-14-04-x64"}' \
-H "Authorization: Bearer ${TOKEN}" \
-H "Content-Type: application/json"
# RESPONSE BODY:
{
"droplet": {
"backup_ids": [],
"created_at": "2015-05-05T20:26:24Z",
"disk": 20,
"features": [
"virtio"
],
"id": 1234567,
"image": {},
"kernel": {
"id": 2924,
"name": "Ubuntu 14.04 x64 vmlinuz-3.13.0-43-generic",
"version": "3.13.0-43-generic"
},
"locked": true,
"memory": 512,
"name": "my-test-droplet",
"networks": {},
"next_backup_window": null,
"region": {},
"size": {},
"size_slug": "512mb",
"snapshot_ids": [],
"status": "new",
"vcpus": 1
},
"links": {
"actions": [
{
"href": "https://api.digitalocean.com/v2/actions/87654321",
"id": 87654321,
"rel": "create"
}
]
}
}
- List Droplets on your account:
$ curl -XGET "${API_URL}/droplets" \
-H "Authorization: Bearer ${TOKEN}" \
-H "Content-Type: application/json" | python -mjson.tool
Or, pretty print the output:
$ curl -sXGET "${API_URL}/droplets" \
-H "Authorization: Bearer ${TOKEN}" \
-H "Content-Type: application/json" |\
python -c 'import sys,json;data=json.loads(sys.stdin.read());\
print "ID\tName\tRegion\n";\
print "\n".join(["%s\t%s\t%s"%(d["id"],d["name"],d["region"]["slug"])\
for d in data["droplets"]])'|column -t
ID Name Region 1234567 my-test-droplet-1 nyc3 2345678 my-test-droplet-2 ams1
- List the details of a given Droplet:
$ DROPLET_ID=1234567
$ curl -sXGET "${API_URL}/droplets/${DROPLET_ID}" -H "Authorization: Bearer ${TOKEN}" -H "Content-Type: application/json" | python -mjson.tool
Images
A quick-and-dirty way to get a pretty table output of the DigitalOcean images available for Droplets is with a Python script something like the following:
#!/usr/bin/env python
import json
from prettytable import PrettyTable
# Create the 'do_images.json' file by saving the output of:
# $ curl "${API_URL}/images" \
# -H "Authorization: Bearer ${TOKEN}" \
# -H "Content-Type: application/json" > do_images.json
with open('do_images.json') as json_data:
data = json.load(json_data)
table = PrettyTable(["ID","Slug","Distribution","Name","Type"])
table.align = "l"
for image in data["images"]:
image_id = image["id"]
slug = image["slug"]
distribution = image["distribution"]
name = image["name"]
image_type = image["type"]
table.add_row([image_id,slug,distribution,name,image_type])
print table
Running the above script produces:
+----------+------------------+--------------+----------------------+-----------+ | ID | Slug | Distribution | Name | Type | +----------+------------------+--------------+----------------------+-----------+ | 11732785 | None | Debian | Maintenance Mode | snapshot | | 11420434 | coreos-stable | CoreOS | 633.1.0 (stable) | snapshot | | 11434448 | coreos-beta | CoreOS | 647.0.0 (beta) | snapshot | | 11657005 | coreos-alpha | CoreOS | 668.2.0 (alpha) | snapshot | | 11385199 | None | Debian | vum-easter-move | snapshot | | 11594346 | None | Ubuntu | blushibiza.com final | temporary | | 6370882 | fedora-20-x64 | Fedora | 20 x64 | snapshot | | 6370885 | fedora-20-x32 | Fedora | 20 x32 | snapshot | | 6372321 | centos-5-8-x64 | CentOS | 5.10 x64 | snapshot | | 6372425 | centos-5-8-x32 | CentOS | 5.10 x32 | snapshot | | 6372581 | debian-6-0-x64 | Debian | 6.0 x64 | snapshot | | 6372662 | debian-6-0-x32 | Debian | 6.0 x32 | snapshot | | 9640922 | fedora-21-x64 | Fedora | 21 x64 | snapshot | | 9801948 | ubuntu-14-04-x32 | Ubuntu | 14.04 x32 | snapshot | | 9801950 | ubuntu-14-04-x64 | Ubuntu | 14.04 x64 | snapshot | | 9801951 | ubuntu-14-10-x32 | Ubuntu | 14.10 x32 | snapshot | | 9801954 | ubuntu-14-10-x64 | Ubuntu | 14.10 x64 | snapshot | | 10144573 | freebsd-10-1-x64 | FreeBSD | 10.1 | snapshot | | 10321756 | ubuntu-12-04-x64 | Ubuntu | 12.04.5 x64 | snapshot | | 10321777 | ubuntu-12-04-x32 | Ubuntu | 12.04.5 x32 | snapshot | +----------+------------------+--------------+----------------------+-----------+
External links
This category currently contains no pages or media.