OpenNebula OCCI User Guide 4.2
The OpenNebula OCCI API is a RESTful service to create, control and monitor cloud resources using an implementation of the OGF OCCI API specification based on the draft 0.8. This implementation also includes some extensions, requested by the community, to support OpenNebula specific functionality. Interactions with the resources are done through HTTP verbs (GET, POST, PUT and DELETE).
There are four kind of resources, listed below with their implemented actions:
occi-storage list [–verbose]
occi-storage create xml_template
occi-storage update xml_template
occi-storage show resource_id
occi-storage delete resource_id
occi-network list [–verbose]
occi-network create xml_template
occi-network update xml_template
occi-network show resource_id
occi-network delete resource_id
occi-compute list [–verbose]
occi-compute create xml_template
occi-compute update xml_template
occi-compute show resource_id
occi-compute delete resource_id
occi-compute attachdisk resource_id storage_id
occi-compute detachdisk resource_id storage_id
occi-instance-type list [–verbose]
occi-instance-type show resource_id
An account is needed in order to use the OpenNebula OCCI cloud. The cloud administrator will be responsible for assigning these accounts, which have a one to one correspondence with OpenNebula accounts, so all the cloud administrator has to do is check the managing users guide to setup accounts, and automatically the OpenNebula OCCI cloud account will be created.
In order to use such an account, the end user can make use of clients programmed to access the services described in the previous section. For this, she has to set up her environment, particularly the following aspects:
Lets take a walk through a typical usage scenario. In this brief scenario it will be shown how to upload an image to the OCCI OpenNebula Storage repository, how to create a Network in the OpenNebula OCCI cloud and how to create Compute resource using the image and the network previously created.
Assuming we have a working Ubuntu installation residing in an .img file, we can upload it into the OpenNebula OCCI cloud using the following OCCI representation of the image:
<STORAGE> <NAME>Ubuntu Desktop</NAME> <DESCRIPTION>Ubuntu 10.04 desktop for students.</DESCRIPTION> <TYPE>OS</TYPE> <URL>file:///images/ubuntu/jaunty.img</URL> </STORAGE>
Next, using the occi-storage command we will create the Storage resource:
<xterm> $ occi-storage --url http://cloud.server:4567 --username oneadmin --password opennebula create image.xml <STORAGE href='http://cloud.server:4567/storage/0'> <ID>3</ID> <NAME>Ubuntu Desktop</NAME> <TYPE>OS</TYPE> <DESCRIPTION>Ubuntu 10.04 desktop for students.</DESCRIPTION> <PUBLIC>NO</PUBLIC> <PERSISTENT>NO</PERSISTENT> <SIZE>41943040</SIZE> </STORAGE> </xterm>
The user should take note of this ID, as it will be needed to add it to the Compute resource.
The next step would be to create a Network resource
<NETWORK> <NAME>MyServiceNetwork</NAME> <ADDRESS>192.168.1.1</ADDRESS> <SIZE>200</SIZE> <PUBLIC>NO</PUBLIC> </NETWORK>
Next, using the occi-network command we will create the Network resource:
<xterm> $ occi-network --url http://cloud.server:4567 --username oneadmin --password opennebula create vnet.xml <NETWORK href='http://cloud.server:4567/network/0'> <ID>0</ID> <NAME>MyServiceNetwork</NAME> <ADDRESS>192.168.1.1/ADDRESS> <SIZE>200/SIZE> <PUBLIC>NO</PUBLIC> </NETWORK> </xterm>
The last step would be to create a Compute resource referencing the Storage and Networks resource previously created by means of their ID, using a representation like the following:
<COMPUTE> <NAME>MyCompute</NAME> <INSTANCE_TYPE href="http://www.opennebula.org/instance_type/small"/> <DISK> <STORAGE href="http://www.opennebula.org/storage/0"/> </DISK> <NIC> <NETWORK href="http://www.opennebula.org/network/0"/> <IP>192.168.1.12</IP> </NIC> <CONTEXT> <HOSTNAME>MAINHOST</HOSTNAME> <DATA>DATA1</DATA> </CONTEXT> </COMPUTE>
Next, using the occi-compute command we will create the Compute resource:
<xterm> $ occi-compute --url http://cloud.server:4567 --username oneadmin --password opennebula create vm.xml <COMPUTE href='http://cloud.server:4567/compute/0'> <ID>0</ID> <CPU>1</CPU> <MEMORY>1024</MEMORY> <NAME>MyCompute</NAME> <INSTANCE_TYPE href="http://www.opennebula.org/instance_type/small"/> <STATE>PENDING</STATE> <DISK id='0'> <STORAGE href='http://cloud.server:4567/storage/3' name='Ubuntu Desktop'/> <TYPE>DISK</TYPE> <TARGET>hda</TARGET> </DISK> <NIC> <NETWORK href='http://cloud.server:4567/network/0' name='MyServiceNetwork'/> <IP>192.168.1.12</IP> <MAC>02:00:c0:a8:01:0c</MAC> </NIC> <CONTEXT> <DATA>DATA1</DATA> <HOSTNAME>MAINHOST</HOSTNAME> <TARGET>hdb</TARGET> </CONTEXT> </COMPUTE> </xterm>
Some of the characteristics of an storage entity can be modified using the occi-storage update command:
In order to make a storage entity persistent we can update the resource using the following xml:
<STORAGE href='http://cloud.server:4567/storage/0'> <ID>3</ID> <PERSISTENT>YES</PERSISTENT> </STORAGE>
Next, using the occi-storage command we will create the Storage resource:
<xterm> $ occi-storage --url http://cloud.server:4567 --username oneadmin --password opennebula update image.xml <STORAGE href='http://cloud.server:4567/storage/0'> <ID>3</ID> <NAME>Ubuntu Desktop</NAME> <TYPE>OS</TYPE> <DESCRIPTION>Ubuntu 10.04 desktop for students.</DESCRIPTION> <PUBLIC>NO</PUBLIC> <PERSISTENT>YES</PERSISTENT> <SIZE>41943040</SIZE> </STORAGE> </xterm>
In order to publish a storage entity so that other users can use it, we can update the resource using the following xml:
<STORAGE href='http://cloud.server:4567/storage/0'> <ID>3</ID> <PUBLIC>YES</PUBLIC> </STORAGE>
Next, using the occi-storage command we will create the Storage resource:
<xterm> $ occi-storage --url http://cloud.server:4567 --username oneadmin --password opennebula update image.xml <STORAGE href='http://cloud.server:4567/storage/0'> <ID>3</ID> <NAME>Ubuntu Desktop</NAME> <TYPE>OS</TYPE> <DESCRIPTION>Ubuntu 10.04 desktop for students.</DESCRIPTION> <PUBLIC>YES</PUBLIC> <PERSISTENT>YES</PERSISTENT> <SIZE>41943040</SIZE> </STORAGE> </xterm>
Some of the characteristics of an network entity can be modified using the occi-network update command:
In order to publish a network entity so that other users can use it, we can update the resource using the following xml:
<NETWORK href='http://cloud.server:4567/network/0'> <ID>0</ID> <PUBLIC>YES</PUBLIC> </NETWORK>
Next, using the occi-network command we will update the Network resource:
<xterm> $ occi-network --url http://cloud.server:4567 --username oneadmin --password opennebula update vnet.xml <NETWORK href='http://cloud.server:4567/network/0'> <ID>0</ID> <NAME>MyServiceNetwork</NAME> <ADDRESS>192.168.1.1/ADDRESS> <SIZE>200/SIZE> <PUBLIC>YES</PUBLIC> </NETWORK> </xterm>
Some of the characteristics of a compute entity can be modified using the occi-compute update command:
In order to change the Compute state, we can update the resource using the following xml:
<COMPUTE href='http://cloud.server:4567/compute/0'> <ID>0</ID> <STATE>STOPPED</STATE> </COMPUTE>
Next, using the occi-compute command we will update the Compute resource:
The available states to update a Compute resource are:
In order to save a Compute disk in a new image, we can update the resource using the following xml. The disk will be saved after shutting down the Compute.
<COMPUTE href='http://cloud.server:4567/compute/0'> <ID>0</ID> <DISK id="0"> <STORAGE href="http://cloud.server:4567/storage/0" name="first_image"/> <SAVE_AS name="save_as1"/> </DISK> </COMPUTE>
Next, using the occi-compute command we will update the Compute resource:
<xterm> $ occi-compute --url http://cloud.server:4567 --username oneadmin --password opennebula update vm.xml <COMPUTE href='http://cloud.server:4567/compute/0'> <ID>0</ID> <CPU>1</CPU> <MEMORY>1024</MEMORY> <NAME>MyCompute</NAME> <INSTANCE_TYPE>small</INSTANCE_TYPE> <STATE>STOPPED</STATE> <DISK id='0'> <STORAGE href='http://cloud.server:4567/storage/3' name='Ubuntu Desktop'/> <SAVE_AS href="http://cloud.server:4567/storage/7"/> <TYPE>DISK</TYPE> <TARGET>hda</TARGET> </DISK> <NIC> <NETWORK href='http://cloud.server:4567/network/0' name='MyServiceNetwork'/> <IP>192.168.1.12</IP> <MAC>02:00:c0:a8:01:0c</MAC> </NIC> <CONTEXT> <DATA>DATA1</DATA> <HOSTNAME>MAINHOST</HOSTNAME> <TARGET>hdb</TARGET> </CONTEXT> </COMPUTE> </xterm>
In this example we will show how to create a new volume using the following template and attach it to a running compute resource.
<STORAGE> <NAME>Volume1</NAME> <TYPE>DATABLOCK</TYPE> <DESCRIPTION>Volume to be hotplugged</DESCRIPTION> <PUBLIC>NO</PUBLIC> <PERSISTENT>NO</PERSISTENT> <FSTYPE>ext3</FSTYPE> <SIZE>10</SIZE> </STORAGE>
<xterm> $ cat /tmp/storage <STORAGE> <NAME>Volume1</NAME> <TYPE>DATABLOCK</TYPE> <DESCRIPTION>Volume to be hotplugged</DESCRIPTION> <PUBLIC>NO</PUBLIC> <PERSISTENT>NO</PERSISTENT> <FSTYPE>ext3</FSTYPE> <SIZE>10</SIZE> </STORAGE> $ occi-storage create /tmp/storage <STORAGE href='http://127.0.0.1:4567/storage/5'> <ID>5</ID> <NAME>Volume1</NAME> <USER href='http://127.0.0.1:4567/user/0' name='oneadmin'/> <GROUP>oneadmin</GROUP> <STATE>READY</STATE> <TYPE>DATABLOCK</TYPE> <DESCRIPTION>Volume to be hotplugged</DESCRIPTION> <SIZE>10</SIZE> <FSTYPE>ext3</FSTYPE> <PUBLIC>NO</PUBLIC> <PERSISTENT>NO</PERSISTENT> </STORAGE> $ occi-compute list <COMPUTE_COLLECTION> <COMPUTE href='http://127.0.0.1:4567/compute/4' name='one-4'/> <COMPUTE href='http://127.0.0.1:4567/compute/6' name='one-6'/> </COMPUTE_COLLECTION> $ occi-storage list <STORAGE_COLLECTION> <STORAGE name='ttylinux - kvm' href='http://127.0.0.1:4567/storage/1'/> <STORAGE name='Ubuntu Server 12.04 (Precise Pangolin) - kvm' href='http://127.0.0.1:4567/storage/2'/> <STORAGE name='Volume1' href='http://127.0.0.1:4567/storage/5'/> </STORAGE_COLLECTION> $ occi-compute attachdisk 6 5 <COMPUTE href='http://127.0.0.1:4567/compute/6'> <ID>6</ID> <USER name='oneadmin' href='http://127.0.0.1:4567/user/0'/> <GROUP>oneadmin</GROUP> <CPU>1</CPU> <MEMORY>512</MEMORY> <NAME>one-6</NAME> <STATE>ACTIVE</STATE> <DISK id='0'> <STORAGE name='Ubuntu Server 12.04 (Precise Pangolin) - kvm' href='http://127.0.0.1:4567/storage/2'/> <TYPE>FILE</TYPE> <TARGET>hda</TARGET> </DISK> <DISK id='1'> <STORAGE name='Volume1' href='http://127.0.0.1:4567/storage/5'/> <TYPE>FILE</TYPE> <TARGET>sda</TARGET> </DISK> <NIC> <NETWORK name='local-net' href='http://127.0.0.1:4567/network/0'/> <IP>192.168.122.6</IP> <MAC>02:00:c0:a8:7a:06</MAC> </NIC> </COMPUTE> </xterm>