knitr::opts_chunk$set( comment = "#>", warning = FALSE, message = FALSE )
If you don't already have one, create a DO account. By using this link, you'll start with $10 in credits (enough for >600 hours of computing on a 1 gb machine), and if you become a digital ocean customer we'll get some DO credits for us to offset our costs for testing. Thanks :)
The best way to authenticate is to generate a personal access token
(https://cloud.digitalocean.com/settings/tokens/new) and save it in an
environment variable called DO_PAT
. If you don't do this, you'll be prompted
to authenticate in your browser the first time you use analogsea.
analogsea
allows you to interact with your droplet(s) from R via SSH. To do
this you need to setup SSH keys with Digital Ocean. Make sure you provide Digitial
Ocean your public key at https://cloud.digitalocean.com/ssh_keys. GitHub has
some good advice on creating a new public key if you don't already have one:
https://help.github.com/articles/generating-ssh-keys/.
Note that when using ssh, you'll likely get warnings like
The authenticity of host can't be established ...
This is normal, don't be worried about this.
Note that if you want to connect over SSH to a droplet you have to
create the droplet with an SSH key with the ssh_keys
parameter. If you
don't you can still interact with the droplet via the Digital Ocean API,
but you can't access the droplet over SSH.
droplet_create()
will create a droplet on your account. You can run it as
below without any inputs, and it will use sensible defaults:
You can set all of these options in your .Rprofile
file like
options(do_size = "8gb")
for a default of 8 GB.
The name given to the droplet is picked at random from a list of 1000 random names.
You can of course set any of these parameters.
droplet_create()
You can also create many droplets at once:
droplets_create()
Listing droplets can be done in singular or plural fashion. droplet()
accepts
a droplet ID, while droplets()
list all droplets.
If you don't have any droplets yet, you will get an empty list running
droplets()
, and you of course can't pass in a droplet ID number to droplet()
if you don't have any droplets yet.
library("analogsea")
droplets() #> named list()
Create a droplet
droplet_create()
After creating a droplet and running droplets()
again, we see a list of
our droplet(s)
drops <- droplets()[-1]
(drops <- droplets())
Or we can pass in a droplet id to droplet()
. There is a print.droplet()
method
that is used to print a brief summary of each droplet.
droplet(drops[[1]]$id)
Get more detailed information on your droplet with summary()
. This is a
summary.droplet()
method, that is just a little more verbose than the
print.droplet()
method
droplet(drops[[1]]$id) %>% summary
You can delete a droplet with droplet_delete()
. Be careful, as this completely
removes your droplet. Backup your droplet or make an image if you want to use
the droplet later.
droplet_create() %>% droplet_delete()
List actions on a droplet, newer ones at the top. Here, list actions
drops[[1]] %>% droplet_actions()
Then rename and list actions again
drops[[1]] %>% droplet_rename(name = "droppy") %>% droplet_wait() %>% droplet_actions() #> Waiting for rename ... #> [[1]] #> <action> rename (166715389) #> Status: completed #> Resource: droplet 31859471 #> #> [[2]] #> <action> create (166715005) #> Status: completed #> Resource: droplet 31859471
Making a snapshot of a droplet can be done with droplet_snapshot()
. This
action requires that you turn off the droplet first, then take the snapshot.
First, create a droplet
d <- droplet_create(size = "2gb")
Then power off, and take a snapshot, which gives an action object describing that the snapshot is in progress.
d %>% droplet_power_off() %>% droplet_wait() %>% droplet_snapshot(name = "mynewsnap") #> Waiting for power_off ................................................... #> <action> snapshot (166715834) #> Status: in-progress #> Resource: droplet 31859617
The regions()
function lists region slug names, full names, available sizes,
whether the region is available at all, and features.
This helps you get an overview of region details, which you can select from when creating droplets
regions()
The sizes()
function lists size slug names, associated memory, vcpus, disk
size, prices, and regions where the size is available.
This helps you get an overview of sizes, which you can select from when creating droplets
sizes()
We suggest you use SSH keys to interact with Digital Ocean from analogsea
.
There are a variety of functions for working with SSH keys.
List your keys
keys()
Get a key by id
key(keys()[[1]]$id)
You can also create a key, rename a key, and delete a key
k <- key_create("key", readLines("~/.ssh/id_rsa.pub")) k <- key_rename(k, "new_name") key_delete(k)
Note that if you're on Windows you may experience some problems connecting over SSH. We hope to resolve these problems as soon as possible.
The images()
function can list both your own private images, and public images.
If public=FALSE
only your private images are listed, while if public=TRUE
,
your private images are listed along with publicly avaialble images.
images(page = 4, per_page = 5)
You can also do various actions on images. First, you can pass in an image ID to
the image()
function to get an image object.
img <- images(per_page = 1)[[1]] image(img$id)
You can rename an image
img %>% image_rename(name = "analog")
You can transfer an image to another region
image(img$id) %>% image_transfer(region = "sfo3")
You can use domain names for your droplets on Digital Ocean. analogsea
has
a variety of functions to work with domain names.
List domain names
domains()
Create a new domain name
dom <- paste0(sample(words, 1), ".info") domain_create(name = dom, ip_address = "127.0.0.1")
Get a single domain by domain name
domain(dom)
Create a domain record, list records and delete the one just created
domain(dom) %>% domain_record_create(type = "TXT", name = "hello", data = "world") records <- domain(dom) %>% domain_records() domain_record_delete(records[[length(records)]])
List records
domain(dom) %>% domain_records()
Delete a domain name, returns nothing if delete is successful
domain(dom) %>% domain_delete()
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.