Scala wrapper around Digital Ocean's API, version 2
Scala wrapper around Digital Ocean's API, version 2
This API is entirely asynchronous, so you'll want to know how to use Futures. Some classes have a "complete" method that perform several operations for you so that you can know if an operation such as Droplet.create or an action have completed. "complete" methods also return futures.
http://www.jeffshaw.me/digitalocean/
This project is now in Maven Central for Scala 2.10, 2.11, 2.12, and 2.13. You can add it to your dependencies in your project's sbt file.
libraryDependencies += "me.jeffshaw" %% "digitalocean" % "6.2"
Or, for a maven project:
<dependency>
<groupId>me.jeffshaw</groupId>
<artifactId>digitalocean_2.13</artifactId>
<version>6.2</version>
</dependency>
Install SBT, clone this repository, and cd to it.
sbt
console
//use :paste if you want to copy-paste the following, but be sure to set your api token first.
import scala.concurrent._, duration._, ExecutionContext.Implicits._
import me.jeffshaw.digitalocean._
import org.asynchttpclient.DefaultAsyncHttpClient
implicit val httpClient = new DefaultAsyncHttpClient()
implicit val client = DigitalOceanClient(
token = "",
maxWaitPerRequest = 5 seconds,
//The following is used for polling action completion.
actionCheckInterval = 15 seconds
)
//List all the regions.
val regions = Await.result(Region.list(), 5 seconds).toVector
//Create a small CentOS 6 32-bit droplet.
val droplet =
Await.result(
Droplet.create(
name = "test",
region = NewYork1,
size = `512mb`,
image = "centos-6-x32",
sshKeys = Seq.empty,
backups = false,
ipv6 = false,
privateNetworking = false,
userData = None
),
atMost = 10 seconds
)
//Wait for the droplet to become active.
Await.result(droplet.complete(), 2 minutes)
//Do stuff with the droplet.
//Run the delete the command, and then wait for the droplet to stop existing.
Await.result(droplet.delete().flatMap(_.complete()), 2 minutes)
httpClient.close()
//CTRL-D if you used :paste.
To run tests, set your api token in src/test/resources/application.conf, and then run test in the sbt console. WARNING: Digital Ocean might lock your account if you run the tests too often. You will want to notify them of what you are doing to prevent that. Also be aware that the floating ip tests don't clean up their test IPs if they fail.
assign
and unassign
methodsDroplet creation has changed to return less information about the droplet. My solution is to just read the ID, and then ask for all the information in a second request.
Metadata functionality added to the metadata package.
DNS functionality added to the dns package.
List functions now return iterators that support paged responses.