Wednesday 29 June 2016

Oracle Cloud: create Storage Containers via REST API

For this Oracle Cloud tutorial, two Storage Containers in the Oracle Storage Cloud Service are required. The Oracle Documentation describes, how this can be done via REST-Api and wget, see 'Authenticating Access When Using the REST API'. Two alternatives are described here: use the RESTClient Firefox-Extension or the Windows-Tool CloudBerry Explorer for OpenStack.


After login to the Oracle Cloud Services, start at the Dashboard where all subscribed services are listed.


Click on the Oracle Storage Cloud Service to get to the details.


Copy the URL of the REST endpoint shown here for further usage. The first call will be the authentication. The URL has to be modified for that as described in the documentation. For example, starting with

https://gse0nnnnnnn.storage.oraclecloud.com/v1/Storage-gse0nnnnnnn

remove everything from v1 on, so you get

https://gse0nnnnnnn.storage.oraclecloud.com/

Then append auth/v1.0 so the result looks like:

https://gse0nnnnnnn.storage.oraclecloud.com/auth/v1.0


Now open the Firefox browser, install and open the RESTClient Extension (or any other browser/extension combination that will do the trick). Create a GET request and paste the URL modified above. Before it can be called, it needs the information about username and password in a header each.


So click on Headers/Custom Header to create a header.


The first header gets the name X-Storage-User. In the value field, enter the username in the format 'Storage-'<identity domain>':'<username> eg.

Storage-asdf1234:john.dunbar

Save it as a favorite in RESTClient, we will need it several times. Then create a second header with the name 'X-Storage-Pass' and the users password as value.


The result should look as shown above. The URL with auth/v1.0 attached and both custom headers. Continue with the 'Send' button.


An authentication token will be returned, which needs to be copied for further usage.


To create a new container, simply write REST conform to a non-existent resource(= storage container). As this resource does not exist, a new one will be created. The name of the resource is the base URL, which we copied from above, and the name of the storage container attached (dbBackupContainer in this case).
It is important to remove both headers created above (also for the following requests). Instead create a new X-Auth-Token header. Use the authentication token from above as value, then click on 'Send'.


If everything is OK, the request will return with '201 Created'.


The REST-API can be used to query all existing storage containers in that instance. Just leave the X-Auth-Token header as it is, also for any further requests. In case of an 'unauthorized' error, probably the token has timed out, so just repeat the first step.
The URL for the query is:
https://gse0nnnnnn.storage.oraclecloud.com/v1/Storage-gse0nnnnnn?limit=15


In return comes a list of all existing storage containers, including the just created dbBackupContainer.

Additional to the REST-API, the Oracle Storage Cloud Service also speaks the OpenStack Swift API. So in the next part if this tutorial, the management of storage containers via OpenStack will be shown with the tool CloudBerry Explorer.

==> Storage Container verwalten per CloudBerry Explorer