Getting started with HP OneView and REST

Now that HP OneView evolves (1.10 was released with 3PAR support) I want to highlight also some other features which I think they will become more and more important in the near future.

One of them is scripting. For that HP enables the use of REST API’s aka “REpresentational State Transfer Application Programming Interface”.

It is an architectural style defined by Roy Fielding, principal author of the HTTP specification, that describes the characteristics and constraints of a well-designed Web application.

It is a client/server based interface that uses URI’s (Uniform Resource Identifier) to represent any physical devices or logical constructs within OneView.
The REST API uses a relatively simple Create, Read, Update and Delete operations by using HTTP POST, GET, PUT and DELETE commands.

So a possible basic process would look like this:

–          Retrieve the current resource: GET /rest/servers/<server-id>to get resource data
–          Set the desired state of the resource: “Server.powerState”:”On”
–          Update the resource with the new state: PUT /rest/servers/<server-id> to apply the change

Further it operates in a complete stateless mode of operation. This means that no client context is stored on the server between requests which enhances server reliability and scalability.

You will also see the use of JSON or JavaScript Object Notification which is an open standard format that uses human-readable text to transmit data objects consisting of attribute-value pairs. It is used primarily to transmit data between a server and web applications, as an alternative to XML. Code to create JSON data is available in many programming languages like PowerShell or Python.

Know also about the existence of API versioning control. Most HP OneView releases introduce a new “API version” supporting new functionality delivered in that release. For instance OneView 1.10 the API version is 101, initial OneView version 1.0 and 1.01 had API version 3 and 1.05 has API version 4.
It is obvious that newer versions of HP OneView support the older versions of API’s as well.

 

Although I am a true Windows user, I was curious for the additional functionality of all this.
So let’s get started with the basics.

1 – Install the REST client

I will use the REST client plug-in in Mozilla Firefox since a plug-in for IE does not exist at this moment. Also for Chrome is a REST client available.

Find the plug-in here: https://addons.mozilla.org/en-US/firefox/addon/restclient/

OneViewREST1

OneViewREST2

You can confirm by clicking Install Now

 

2 – Obtain the required HTTP headers

First you have to define some HTTP headers before connecting to HP OneView. Do this by starting the REST client by clicking on the red square at the upper right corner of your browser.

OneViewREST3.jpg

OneViewREST4.jpg

Select in the menu to create a Custom Header

OneViewREST5.jpg

Create a header to set the API version to 101

OneViewREST6.jpg

Create another header to set the Content Type to JSON

 

3 – Connect to HP OneView using the REST client

First obtain a Session ID when connecting to the OneView appliance

OneViewREST7.jpg

Know that the BODY text is case sensitive and 10.110.232.21 is the IP address of my OneView appliance.

By clicking SEND you should get a similar response

OneViewREST8.jpg

Status Code should be 200 OK, if not some data entry mistake was made. Like I said watch out for case-sensitive commands.

OneViewREST9.jpg

Copy&Paste the obtained Session ID and add it as an additional header in the REST client

OneViewREST10.jpg

Your Headers section should be similar like this. The AUTH values will be different of course.

OneViewREST11.jpg

 

4 – Retrieve Resource Information using the REST client

To retrieve the HP OneView appliance version, use following command

OneViewREST12

By clicking SEND you should get a response similar like displayed below

OneViewREST13.jpg

 

5 – Create a Resource using the REST client

By using following instruction you can create quite easily an Ethernet Network resource in HP OneView

OneViewREST14.jpg

OneViewREST15.jpg

In the HP OneView console it will look like this

OneViewREST16.jpg

Cool, rather easy! Now you just have to get familiar with all the possible REST instructions. The list is long and will get longer with every new API version…

Be sure to check out the REST API reference which can be found (with plenty of other interesting documents) on
www.hp.com/go/oneview/docs

OneViewREST17

Author: Bart Heungens

Share This Post On
%d bloggers like this: