DigitalOcean API Client in Java

com.myjeeva.digitalocean
Interface DigitalOcean

All Known Implementing Classes:
DigitalOceanClient

public interface DigitalOcean

DigitalOcean API client written in Java

A simple and meaningful wrapper methods for DigitalOcean's API. All of the RESTful that you find in DigitalOcean API's will be made available via simple java methods.

Sample Code:

 // Create a DigitalOcean client
 DigitalOcean apiClient = new DigitalOceanClient(clientId, apiKey);
 
 // Let's invoke the appropriate method as per need
 // Fetching all the available droplets from control panel 
 List<Droplet> droplets = apiClient.getAvailableDroplets();
 
 // Create a new droplet
 Droplet newDroplet = new Droplet();
 newDroplet.setName("api-cliet-test-host");
 newDroplet.setSizeId(66); // 66 => 512MB plan
 newDroplet.setRegionId(3); // 3 => San Francisco 1 Data center
 newDroplet.setImageId(473123); // 473123 => Ubuntu 12.10 x64 Image
 Droplet droplet = apiClient.createDroplet(newDroplet); 
 
 // Fetch droplet information 
 Droplet droplet = apiClient.getDropletInfo(dropletId);
 
 // Fetch Available Plans/Sizes supported by DigitalOcean
 List<DropletSize> sizes = apiClient.getAvailableSizes();
 
 and so on... simple to use and effective!
 

Author:
Jeevanandam M. ([email protected])

Method Summary
 SshKey addSshKey(String sshKeyName, String sshPublicKey)
          To be release in v1.2
 Domain createDomain(String domainName, String ipAddress)
          Method creates a new domain name with an A record for the specified [ip_address].
 DomainRecord createDomainRecord(DomainRecord domainRecord)
          Method creates a new domain record name with an given domain record values
 Droplet createDroplet(Droplet droplet)
           Method allows you to create a new droplet.
 Droplet createDroplet(Droplet droplet, String sshKeyIds)
           Method allows you to create a new droplet.
 Response deleteDomain(Integer domainId)
          Method deletes the specified domain from DNS control panel
 Response deleteDomainRecord(Integer domainId, Integer recordId)
          Method deletes the specified domain record from domain.
 Response deleteDroplet(Integer dropletId)
          Method destroys one of your droplets - this is irreversible.
 Response deleteImage(Integer imageId)
          Method allows you to deletes an image.
 Response deleteSshKey(Integer sshKeyId)
          To be release in v1.2
 Response disableDropletBackups(Integer dropletId)
          Method disables automatic backups from running to backup your droplet's data.
 DomainRecord editDomainRecord(DomainRecord domainRecord)
          method edits an existing domain record of the given domain.
 SshKey editSshKey(Integer sshKeyId, String sshPublicKey)
          To be release in v1.2
 Response enableDropletBackups(Integer dropletId)
          Method enables automatic backups which run in the background daily to backup your droplet's data.
 List<Domain> getAvailableDomains()
          Method returns all of your available domains from DNS control panel
 List<Droplet> getAvailableDroplets()
          Method returns all active droplets that are currently running in your account.
 List<DropletImage> getAvailableImages()
          Method returns all the available images that can be accessed by your client ID.
 List<Region> getAvailableRegions()
          Method will return all the available regions within the DigitalOcean cloud.
 List<DropletSize> getAvailableSizes()
          Method returns all the available sizes that can be used to create a droplet.
 List<SshKey> getAvailableSshKeys()
          To be release in v1.2
 Domain getDomainInfo(Integer domainId)
          Method returns the specified domain attributes and zone file info.
 DomainRecord getDomainRecordInfo(Integer domainId, Integer recordId)
          Method returns the specified domain record.
 List<DomainRecord> getDomainRecords(Integer domainId)
          Method returns all of your current domain records from DNS control panel for given domain.
 Droplet getDropletInfo(Integer dropletId)
          Method returns full information for a specific droplet ID that is passed in the URL.
 DropletImage getImageInfo(Integer imageId)
          Method retrieves the attributes of an image.
 SshKey getSshKeyInfo(Integer sshKeyId)
          To be release in v1.2
 Response powerCyleDroplet(Integer dropletId)
          Method allows you to power cycle a droplet.
 Response powerOffDroplet(Integer dropletId)
          Method allows you to poweroff a running droplet.
 Response powerOnDroplet(Integer dropletId)
          Method allows you to poweron a powered off droplet.
 Response rebootDroplet(Integer dropletId)
          Method allows you to reboot a droplet.
 Response rebuildDroplet(Integer dropletId, Integer imageId)
          Method allows you to reinstall a droplet with a default image.
 Response renameDroplet(Integer dropletId, String name)
          Method renames the droplet to the specified name.
 Response resetDropletPassword(Integer dropletId)
          Method will reset the root password for a droplet.
 Response resizeDroplet(Integer dropletId, Integer sizeId)
          Method allows you to resize a specific droplet to a different size.
 Response restoreDroplet(Integer dropletId, Integer imageId)
          Method allows you to restore a droplet with a previous image or snapshot.
 Response shutdownDroplet(Integer dropletId)
          Method allows you to shutdown a running droplet.
 Response takeDropletSnapshot(Integer dropletId)
          Method allows you to take a snapshot of the running droplet, which can later be restored or used to create a new droplet from the same image.
 Response takeDropletSnapshot(Integer dropletId, String snapshotName)
          Method allows you to take a snapshot of the running droplet, which can later be restored or used to create a new droplet from the same image.
 Response transerImage(Integer imageId, Integer regionId)
          Method allows you to transfer an image to a specified region.
 

Method Detail

getAvailableDroplets

List<Droplet> getAvailableDroplets()
                                   throws AccessDeniedException,
                                          ResourceNotFoundException,
                                          RequestUnsuccessfulException
Method returns all active droplets that are currently running in your account. All available API information is presented for each droplet.

Returns:
List<Droplet>
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException
Since:
v1.0

createDroplet

Droplet createDroplet(Droplet droplet)
                      throws AccessDeniedException,
                             ResourceNotFoundException,
                             RequestUnsuccessfulException

Method allows you to create a new droplet. See the required parameters section below for an explanation of the variables that are needed to create a new droplet.

Create a instance of Droplet object and populate following values

Parameters:
droplet - - the id of the droplet
Returns:
Droplet
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException
Since:
v1.0

createDroplet

Droplet createDroplet(Droplet droplet,
                      String sshKeyIds)
                      throws AccessDeniedException,
                             ResourceNotFoundException,
                             RequestUnsuccessfulException

Method allows you to create a new droplet. See the required parameters section below for an explanation of the variables that are needed to create a new droplet.

Create a instance of Droplet object and populate following values

Parameters:
droplet - - the id of the droplet
sshKeyIds - - Numeric CSV, comma separated list of ssh_key_ids that you would like to be added to the server
Returns:
Droplet
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException
Since:
v1.0

getDropletInfo

Droplet getDropletInfo(Integer dropletId)
                       throws AccessDeniedException,
                              ResourceNotFoundException,
                              RequestUnsuccessfulException
Method returns full information for a specific droplet ID that is passed in the URL.

Parameters:
dropletId - - the id of the droplet
Returns:
Droplet
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException
Since:
v1.0

rebootDroplet

Response rebootDroplet(Integer dropletId)
                       throws AccessDeniedException,
                              ResourceNotFoundException,
                              RequestUnsuccessfulException
Method allows you to reboot a droplet. This is the preferred method to use if a server is not responding.

Parameters:
dropletId - - the id of the droplet
Returns:
Response
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException
Since:
v1.0

powerCyleDroplet

Response powerCyleDroplet(Integer dropletId)
                          throws AccessDeniedException,
                                 ResourceNotFoundException,
                                 RequestUnsuccessfulException
Method allows you to power cycle a droplet. This will turn off the droplet and then turn it back on.

Parameters:
dropletId - - the id of the droplet
Returns:
Response
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException
Since:
v1.0

shutdownDroplet

Response shutdownDroplet(Integer dropletId)
                         throws AccessDeniedException,
                                ResourceNotFoundException,
                                RequestUnsuccessfulException
Method allows you to shutdown a running droplet. The droplet will remain in your account.

Parameters:
dropletId - - the id of the droplet
Returns:
Response
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException
Since:
v1.0

powerOffDroplet

Response powerOffDroplet(Integer dropletId)
                         throws AccessDeniedException,
                                ResourceNotFoundException,
                                RequestUnsuccessfulException
Method allows you to poweroff a running droplet. The droplet will remain in your account.

Parameters:
dropletId - - the id of the droplet
Returns:
Response
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException
Since:
v1.0

powerOnDroplet

Response powerOnDroplet(Integer dropletId)
                        throws AccessDeniedException,
                               ResourceNotFoundException,
                               RequestUnsuccessfulException
Method allows you to poweron a powered off droplet.

Parameters:
dropletId - - the id of the droplet
Returns:
Response
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException
Since:
v1.0

resetDropletPassword

Response resetDropletPassword(Integer dropletId)
                              throws AccessDeniedException,
                                     ResourceNotFoundException,
                                     RequestUnsuccessfulException
Method will reset the root password for a droplet. Please be aware that this will reboot the droplet to allow resetting the password.

Parameters:
dropletId - - the id of the droplet
Returns:
Response
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException
Since:
v1.0

resizeDroplet

Response resizeDroplet(Integer dropletId,
                       Integer sizeId)
                       throws AccessDeniedException,
                              ResourceNotFoundException,
                              RequestUnsuccessfulException
Method allows you to resize a specific droplet to a different size. This will affect the number of processors and memory allocated to the droplet.

Parameters:
dropletId - - the id of the droplet
Returns:
Response
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException
Since:
v1.0

takeDropletSnapshot

Response takeDropletSnapshot(Integer dropletId)
                             throws AccessDeniedException,
                                    ResourceNotFoundException,
                                    RequestUnsuccessfulException
Method allows you to take a snapshot of the running droplet, which can later be restored or used to create a new droplet from the same image. Please be aware this may cause a reboot.

Parameters:
dropletId - - the id of the droplet
Returns:
Response
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException
Since:
v1.0

takeDropletSnapshot

Response takeDropletSnapshot(Integer dropletId,
                             String snapshotName)
                             throws AccessDeniedException,
                                    ResourceNotFoundException,
                                    RequestUnsuccessfulException
Method allows you to take a snapshot of the running droplet, which can later be restored or used to create a new droplet from the same image. Please be aware this may cause a reboot.

Parameters:
dropletId - - the id of the droplet
snapshotName - - the name the snapshot to be created
Returns:
Response
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException
Since:
v1.0

restoreDroplet

Response restoreDroplet(Integer dropletId,
                        Integer imageId)
                        throws AccessDeniedException,
                               ResourceNotFoundException,
                               RequestUnsuccessfulException
Method allows you to restore a droplet with a previous image or snapshot. This will be a mirror copy of the image or snapshot to your droplet. Be sure you have backed up any necessary information prior to restore.

Parameters:
dropletId - - the id of the droplet
Returns:
Response
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException
Since:
v1.0

rebuildDroplet

Response rebuildDroplet(Integer dropletId,
                        Integer imageId)
                        throws AccessDeniedException,
                               ResourceNotFoundException,
                               RequestUnsuccessfulException
Method allows you to reinstall a droplet with a default image. This is useful if you want to start again but retain the same IP address for your droplet.

Parameters:
dropletId - - the id of the droplet
Returns:
Response
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException
Since:
v1.0

enableDropletBackups

Response enableDropletBackups(Integer dropletId)
                              throws AccessDeniedException,
                                     ResourceNotFoundException,
                                     RequestUnsuccessfulException
Method enables automatic backups which run in the background daily to backup your droplet's data.

Parameters:
dropletId - - the id of the droplet
Returns:
Response
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException
Since:
v1.0

disableDropletBackups

Response disableDropletBackups(Integer dropletId)
                               throws AccessDeniedException,
                                      ResourceNotFoundException,
                                      RequestUnsuccessfulException
Method disables automatic backups from running to backup your droplet's data.

Parameters:
dropletId - - the id of the droplet
Returns:
Response
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException
Since:
v1.0

renameDroplet

Response renameDroplet(Integer dropletId,
                       String name)
                       throws AccessDeniedException,
                              ResourceNotFoundException,
                              RequestUnsuccessfulException
Method renames the droplet to the specified name.

Parameters:
dropletId - - the id of the droplet
Returns:
Response
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException
Since:
v1.0

deleteDroplet

Response deleteDroplet(Integer dropletId)
                       throws AccessDeniedException,
                              ResourceNotFoundException,
                              RequestUnsuccessfulException
Method destroys one of your droplets - this is irreversible.

Parameters:
dropletId - - the id of the droplet
Returns:
Response
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException
Since:
v1.0

getAvailableRegions

List<Region> getAvailableRegions()
                                 throws AccessDeniedException,
                                        ResourceNotFoundException,
                                        RequestUnsuccessfulException
Method will return all the available regions within the DigitalOcean cloud.

Returns:
List<Region>
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException
Since:
v1.0

getAvailableImages

List<DropletImage> getAvailableImages()
                                      throws AccessDeniedException,
                                             ResourceNotFoundException,
                                             RequestUnsuccessfulException
Method returns all the available images that can be accessed by your client ID. You will have access to all public images by default, and any snapshots or backups that you have created in your own account.

Returns:
List<DropletImage>
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException
Since:
v1.0

getImageInfo

DropletImage getImageInfo(Integer imageId)
                          throws AccessDeniedException,
                                 ResourceNotFoundException,
                                 RequestUnsuccessfulException
Method retrieves the attributes of an image.

Parameters:
imageId - - the image Id of the droplet/snapshot/backup images
Returns:
DropletImage
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException
Since:
v1.0

deleteImage

Response deleteImage(Integer imageId)
                     throws AccessDeniedException,
                            ResourceNotFoundException,
                            RequestUnsuccessfulException
Method allows you to deletes an image. There is no way to restore a deleted image so be careful and ensure your data is properly backed up.

Parameters:
imageId - - the image Id of the droplet/snapshot/backup images
Returns:
Response
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException
Since:
v1.0

transerImage

Response transerImage(Integer imageId,
                      Integer regionId)
                      throws AccessDeniedException,
                             ResourceNotFoundException,
                             RequestUnsuccessfulException
Method allows you to transfer an image to a specified region.

Parameters:
imageId - - the image Id of the droplet/snapshot/backup images
regionId - - the region Id of the digitalocean data centers
Returns:
Response
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException
Since:
v1.0

getAvailableSshKeys

List<SshKey> getAvailableSshKeys()
To be release in v1.2


getSshKeyInfo

SshKey getSshKeyInfo(Integer sshKeyId)
To be release in v1.2


addSshKey

SshKey addSshKey(String sshKeyName,
                 String sshPublicKey)
To be release in v1.2


editSshKey

SshKey editSshKey(Integer sshKeyId,
                  String sshPublicKey)
To be release in v1.2


deleteSshKey

Response deleteSshKey(Integer sshKeyId)
To be release in v1.2


getAvailableSizes

List<DropletSize> getAvailableSizes()
                                    throws AccessDeniedException,
                                           ResourceNotFoundException,
                                           RequestUnsuccessfulException
Method returns all the available sizes that can be used to create a droplet.

Returns:
List<DropletSize>
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException
Since:
v1.0

getAvailableDomains

List<Domain> getAvailableDomains()
                                 throws AccessDeniedException,
                                        ResourceNotFoundException,
                                        RequestUnsuccessfulException
Method returns all of your available domains from DNS control panel

Returns:
List<Domain>
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException
Since:
v1.1

createDomain

Domain createDomain(String domainName,
                    String ipAddress)
                    throws AccessDeniedException,
                           ResourceNotFoundException,
                           RequestUnsuccessfulException
Method creates a new domain name with an A record for the specified [ip_address].

Parameters:
domainName - - the name of the domain
ipAddress - - the IP Address for the domain
Returns:
Domain
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException
Since:
v1.1

getDomainInfo

Domain getDomainInfo(Integer domainId)
                     throws AccessDeniedException,
                            ResourceNotFoundException,
                            RequestUnsuccessfulException
Method returns the specified domain attributes and zone file info.

Parameters:
domainId - - the Id of the domain
Returns:
Domain
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException
Since:
v1.1

deleteDomain

Response deleteDomain(Integer domainId)
                      throws AccessDeniedException,
                             ResourceNotFoundException,
                             RequestUnsuccessfulException
Method deletes the specified domain from DNS control panel

Parameters:
domainId - - the Id of the domain
Returns:
Response
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException
Since:
v1.1

getDomainRecords

List<DomainRecord> getDomainRecords(Integer domainId)
                                    throws AccessDeniedException,
                                           ResourceNotFoundException,
                                           RequestUnsuccessfulException
Method returns all of your current domain records from DNS control panel for given domain.

Parameters:
domainId - - the Id of the domain
Returns:
List<DomainRecord>
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException
Since:
v1.1

createDomainRecord

DomainRecord createDomainRecord(DomainRecord domainRecord)
                                throws AccessDeniedException,
                                       ResourceNotFoundException,
                                       RequestUnsuccessfulException
Method creates a new domain record name with an given domain record values

Parameters:
domainRecord - - the domain record values domain Id, record type, data, name, priority, port, weight
Returns:
DomainRecord
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException
Since:
v1.1

getDomainRecordInfo

DomainRecord getDomainRecordInfo(Integer domainId,
                                 Integer recordId)
                                 throws AccessDeniedException,
                                        ResourceNotFoundException,
                                        RequestUnsuccessfulException
Method returns the specified domain record.

Parameters:
domainId - - the Id of the domain
recordId - - the record Id of the domain
Returns:
DomainRecord
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException
Since:
v1.1

editDomainRecord

DomainRecord editDomainRecord(DomainRecord domainRecord)
                              throws AccessDeniedException,
                                     ResourceNotFoundException,
                                     RequestUnsuccessfulException
method edits an existing domain record of the given domain.

Parameters:
domainRecord - - the domain record values domain Id, record type, data, name, priority, port, weight
Returns:
DomainRecord
Throws:
AccessDeniedException
ResourceNotFoundException
RequestUnsuccessfulException
Since:
v1.1

deleteDomainRecord

Response deleteDomainRecord(Integer domainId,
                            Integer recordId)
                            throws AccessDeniedException,
                                   ResourceNotFoundException,
                                   RequestUnsuccessfulException
Method deletes the specified domain record from domain.

Throws:
RequestUnsuccessfulException
ResourceNotFoundException
AccessDeniedException
Since:
v1.1

DigitalOcean API Client in Java

Copyright © 2013 myjeeva blog, All rights reserved.

The copyright of the pages and contents on this website is with myjeeva.com and the content is licensed under Creative Commons Attribution-Share Alike 3.0 Unported License. Libraries and code snippets on myjeeva blog has license information.