libcloud.common.abiquo module

Abiquo Utilities Module for the Abiquo Driver.

Common utilities needed by the AbiquoNodeDriver.

class libcloud.common.abiquo.AbiquoConnection(user_id, key, secure=True, host=None, port=None, url=None, timeout=None, retry_delay=None, backoff=None, proxy_url=None)[source]

Bases: ConnectionUserAndKey, PollingConnection

A Connection to Abiquo API.

Basic ConnectionUserAndKey connection with PollingConnection features for asynchronous tasks.

Initialize user_id and key; set secure to an int based on passed value.

add_default_headers(headers)[source]

Add Basic Authentication header to all the requests.

It injects the ‘Authorization: Basic Base64String===’ header in each request

Parameters:

headers (dict) – Default input headers

Return type:

dict

Returns:

Default input headers with the ‘Authorization’ header

get_poll_request_kwargs(response, context, request_kwargs)[source]

Manage polling request arguments.

Return keyword arguments which are passed to the NodeDriver.request method when polling for the job status. The Abiquo Asynchronous Response returns and ‘acceptedrequest’ XmlElement as the following:

<acceptedrequest>
    <link href="http://uri/to/task" rel="status"/>
    <message>You can follow the progress in the link</message>
</acceptedrequest>

We need to extract the href URI to poll.

Parameters:
  • response (xml.etree.ElementTree) – Object returned by poll request.

  • request_kwargs (dict) – Default request arguments and headers

Return type:

dict

Returns:

Modified keyword arguments

has_completed(response)[source]

Decide if the asynchronous job has ended.

Parameters:

response (xml.etree.ElementTree) – Response object returned by poll request

Return type:

bool

Returns:

Whether the job has completed

responseCls

alias of AbiquoResponse

class libcloud.common.abiquo.AbiquoResponse(response, connection)[source]

Bases: XmlResponse

Abiquo XML Response.

Wraps the response in XML bodies or extract the error data in case of error.

Parameters:
  • response (httplib.HTTPResponse) – HTTP response object. (optional)

  • connection (Connection) – Parent connection object.

NODE_STATE_MAP = {'ALLOCATED': NodeState.PENDING, 'CONFIGURED': NodeState.PENDING, 'LOCKED': NodeState.PENDING, 'NOT_ALLOCATED': NodeState.TERMINATED, 'OFF': NodeState.PENDING, 'ON': NodeState.RUNNING, 'PAUSED': NodeState.PENDING, 'UNKNOWN': NodeState.UNKNOWN}
async_success()[source]

Determinate if async request was successful.

An async_request retrieves for a task object that can be successfully retrieved (self.status == OK), but the asynchronous task (the body of the HTTP response) which we are asking for has finished with an error. So this method checks if the status code is ‘OK’ and if the task has finished successfully.

Return type:

bool

Returns:

successful asynchronous request or not

parse_error()[source]

Parse the error messages.

Response body can easily be handled by this class parent XmlResponse, but there are use cases which Abiquo API does not respond an XML but an HTML. So we need to handle these special cases.

success()[source]

Determine if the request was successful.

Any of the 2XX HTTP response codes are accepted as successful requests

Return type:

bool

Returns:

successful request or not.

exception libcloud.common.abiquo.ForbiddenError(driver)[source]

Bases: LibcloudError

Exception used when credentials are ok but user has not permissions.

libcloud.common.abiquo.get_href(element, rel)[source]

Search a RESTLink element in the AbiquoResponse.

Abiquo, as a REST API, it offers self-discovering functionality. That means that you could walk through the whole API only navigating from the links offered by the entities.

This is a basic method to find the ‘relations’ of an entity searching into its links.

For instance, a Rack entity serialized as XML as the following:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<rack>
 <link href="http://host/api/admin/datacenters/1"
    type="application/vnd.abiquo.datacenter+xml" rel="datacenter"/>
 <link href="http://host/api/admin/datacenters/1/racks/1"
    type="application/vnd.abiquo.rack+xml" rel="edit"/>
 <link href="http://host/api/admin/datacenters/1/racks/1/machines"
    type="application/vnd.abiquo.machines+xml" rel="machines"/>
 <haEnabled>false</haEnabled>
 <id>1</id>
 <longDescription></longDescription>
 <name>racacaca</name>
 <nrsq>10</nrsq>
 <shortDescription></shortDescription>
 <vlanIdMax>4094</vlanIdMax>
 <vlanIdMin>2</vlanIdMin>
 <vlanPerVdcReserved>1</vlanPerVdcReserved>
 <vlansIdAvoided></vlansIdAvoided>
</rack>

offers link to datacenters (rel=’datacenter’), to itself (rel=’edit’) and to the machines defined in it (rel=’machines’)

A call to this method with the ‘rack’ element using ‘datacenter’ as ‘rel’ will return:

http://10.60.12.7:80/api/admin/datacenters/1

Parameters:
  • element (xml.etree.ElementTree) – Xml Entity returned by Abiquo API (required)

  • rel (str) – relation link name

Return type:

str

Returns:

the ‘href’ value according to the ‘rel’ input parameter