libcloud.common package

Submodules

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)[source]

Bases: libcloud.common.base.ConnectionUserAndKey, libcloud.common.base.PollingConnection

A Connection to Abiquo API.

Basic ConnectionUserAndKey connection with PollingConnection features for asynchronous tasks.

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: libcloud.common.base.XmlResponse

Abiquo XML Response.

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

Parameters:
NODE_STATE_MAP = {'PAUSED': 3, 'ON': 0, 'OFF': 3, 'UNKNOWN': 4, 'NOT_ALLOCATED': 2, 'LOCKED': 3, 'ALLOCATED': 3, 'CONFIGURED': 3}
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 asyncronous 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: libcloud.common.types.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

libcloud.common.aws module

class libcloud.common.aws.AWSBaseResponse(response, connection)[source]

Bases: libcloud.common.base.XmlResponse

Parameters:
namespace = None
class libcloud.common.aws.AWSDriver(key, secret=None, secure=True, host=None, port=None, api_version=None, region=None, token=None, **kwargs)[source]

Bases: libcloud.common.base.BaseDriver

class libcloud.common.aws.AWSGenericResponse(response, connection)[source]

Bases: libcloud.common.aws.AWSBaseResponse

Parameters:
expections = {}
parse_error()[source]
success()[source]
xpath = None
class libcloud.common.aws.AWSTokenConnection(user_id, key, secure=True, host=None, port=None, url=None, timeout=None, token=None)[source]

Bases: libcloud.common.base.ConnectionUserAndKey

add_default_headers(headers)[source]
add_default_params(params)[source]
class libcloud.common.aws.SignedAWSConnection(user_id, key, secure=True, host=None, port=None, url=None, timeout=None, token=None)[source]

Bases: libcloud.common.aws.AWSTokenConnection

add_default_params(params)[source]

libcloud.common.azure module

class libcloud.common.azure.AzureConnection(user_id, key, secure=True, host=None, port=None, url=None, timeout=None, proxy_url=None)[source]

Bases: libcloud.common.base.ConnectionUserAndKey

Represents a single connection to Azure

add_default_params(params)[source]
pre_connect_hook(params, headers)[source]
rawResponseCls

alias of AzureRawResponse

responseCls

alias of AzureResponse

class libcloud.common.azure.AzureRawResponse(connection)[source]

Bases: libcloud.common.base.RawResponse

Parameters:connection (Connection) – Parent connection object.
class libcloud.common.azure.AzureResponse(response, connection)[source]

Bases: libcloud.common.base.XmlResponse

Parameters:
parse_error(msg=None)[source]
success()[source]
valid_response_codes = [404, 409, 400]

libcloud.common.base module

class libcloud.common.base.BaseDriver(key, secret=None, secure=True, host=None, port=None, api_version=None, region=None, **kwargs)[source]

Bases: object

Base driver class from which other classes can inherit from.

Parameters:
  • key (str) – API key or username to be used (required)
  • secret (str) – Secret password to be used (required)
  • secure (bool) – Weither to use HTTPS or HTTP. Note: Some providers only support HTTPS, and it is on by default.
  • host (str) – Override hostname used for connections.
  • port (int) – Override port used for connections.
  • api_version (str) – Optional API version. Only used by drivers which support multiple API versions.
  • region (str) – Optional driver region. Only used by drivers which support multiple regions.
Return type:

None

connectionCls

alias of ConnectionKey

class libcloud.common.base.Connection(secure=True, host=None, port=None, url=None, timeout=None, proxy_url=None)[source]

Bases: object

A Base Connection class to derive from.

action = None
add_default_headers(headers)[source]

Adds default headers (such as Authorization, X-Foo-Bar) to the passed headers

Should return a dictionary.

add_default_params(params)[source]

Adds default parameters (such as API key, version, etc.) to the passed params

Should return a dictionary.

allow_insecure = True
cache_busting = False
conn_classes = (<class 'libcloud.httplib_ssl.LibcloudHTTPConnection'>, <class 'libcloud.httplib_ssl.LibcloudHTTPSConnection'>)
connect(host=None, port=None, base_url=None)[source]

Establish a connection with the API server.

Parameters:
  • host (str) – Optional host to override our default
  • port (int) – Optional port to override our default
Returns:

A connection

connection = None
driver = None
encode_data(data)[source]

Encode body data.

Override in a provider’s subclass.

host = '127.0.0.1'
morph_action_hook(action)[source]
port = 443
pre_connect_hook(params, headers)[source]

A hook which is called before connecting to the remote server. This hook can perform a final manipulation on the params, headers and url parameters.

Parameters:
  • params (dict) – Request parameters.
  • headers (dict) – Request headers.
rawResponseCls

alias of RawResponse

request(action, params=None, data=None, headers=None, method='GET', raw=False)[source]

Request a given action.

Basically a wrapper around the connection object’s request that does some helpful pre-processing.

Parameters:
  • action (str) – A path. This can include arguments. If included, any extra parameters are appended to the existing ones.
  • params (dict) – Optional mapping of additional parameters to send. If None, leave as an empty dict.
  • data (unicode) – A body of data to send with the request.
  • headers (dict) – Extra headers to add to the request None, leave as an empty dict.
  • method (str) – An HTTP method such as “GET” or “POST”.
  • raw (bool) – True to perform a “raw” request aka only send the headers and use the rawResponseCls class. This is used with storage API when uploading a file.
Returns:

An Response instance.

Return type:

Response instance

reset_context()[source]
responseCls

alias of Response

secure = 1
set_context(context)[source]
set_http_proxy(proxy_url)[source]

Set a HTTP proxy which will be used with this connection.

Parameters:proxy_url (str) – Proxy URL (e.g. http://<hostname>:<port> without authentication and http://<username>:<password>@<hostname>:<port> for basic auth authentication information.
timeout = None
user_agent_append(token)[source]

Append a token to a user agent string.

Users of the library should call this to uniquely identify their requests to a provider.

Parameters:token (str) – Token to add to the user agent.
class libcloud.common.base.ConnectionKey(key, secure=True, host=None, port=None, url=None, timeout=None, proxy_url=None)[source]

Bases: libcloud.common.base.Connection

Base connection class which accepts a single key argument.

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

class libcloud.common.base.ConnectionUserAndKey(user_id, key, secure=True, host=None, port=None, url=None, timeout=None, proxy_url=None)[source]

Bases: libcloud.common.base.ConnectionKey

Base connection class which accepts a user_id and key argument.

user_id = None
class libcloud.common.base.HTTPResponse(sock, debuglevel=0, strict=0, method=None, buffering=False)[source]

Bases: httplib.HTTPResponse

read(amt=None)[source]
class libcloud.common.base.JsonResponse(response, connection)[source]

Bases: libcloud.common.base.Response

A Base JSON Response class to derive from.

Parameters:
parse_body()[source]
parse_error()
class libcloud.common.base.LoggingConnection[source]

Debug class to log all HTTP(s) requests as they could be made with the curl command.

Variables:log – file-like object that logs entries are written to.
http_proxy_used = False
log = None
class libcloud.common.base.LoggingHTTPConnection(*args, **kwargs)[source]

Bases: libcloud.common.base.LoggingConnection, libcloud.httplib_ssl.LibcloudHTTPConnection

Utility Class for logging HTTP connections

getresponse()[source]
protocol = 'http'
request(method, url, body=None, headers=None)[source]
class libcloud.common.base.LoggingHTTPSConnection(*args, **kwargs)[source]

Bases: libcloud.common.base.LoggingConnection, libcloud.httplib_ssl.LibcloudHTTPSConnection

Utility Class for logging HTTPS connections

Constructor

getresponse()[source]
protocol = 'https'
request(method, url, body=None, headers=None)[source]
class libcloud.common.base.PollingConnection(secure=True, host=None, port=None, url=None, timeout=None, proxy_url=None)[source]

Bases: libcloud.common.base.Connection

Connection class which can also work with the async APIs.

After initial requests, this class periodically polls for jobs status and waits until the job has finished. If job doesn’t finish in timeout seconds, an Exception thrown.

async_request(action, params=None, data=None, headers=None, method='GET', context=None)[source]

Perform an ‘async’ request to the specified path. Keep in mind that this function is blocking and ‘async’ in this case means that the hit URL only returns a job ID which is the periodically polled until the job has completed.

This function works like this:

  • Perform a request to the specified path. Response should contain a ‘job_id’.
  • Returned ‘job_id’ is then used to construct a URL which is used for retrieving job status. Constructed URL is then periodically polled until the response indicates that the job has completed or the timeout of ‘self.timeout’ seconds has been reached.
Parameters:
  • action (str) – A path
  • params (dict) – Optional mapping of additional parameters to send. If None, leave as an empty dict.
  • data (unicode) – A body of data to send with the request.
  • headers (dict) – Extra headers to add to the request None, leave as an empty dict.
  • method (str) – An HTTP method such as “GET” or “POST”.
  • context (dict) – Context dictionary which is passed to the functions which construct initial and poll URL.
Returns:

An Response instance.

Return type:

Response instance

get_poll_request_kwargs(response, context, request_kwargs)[source]

Return keyword arguments which are passed to the request() method when polling for the job status.

Parameters:
  • response (dict) – Response object returned by poll request.
  • request_kwargs – Kwargs previously used to initiate the poll request.

:return dict Keyword arguments

get_request_kwargs(action, params=None, data=None, headers=None, method='GET', context=None)[source]

Arguments which are passed to the initial request() call inside async_request.

has_completed(response)[source]

Return job completion status.

Parameters:response (HTTPResponse) – Response object returned by poll request.

:return bool True if the job has completed, False otherwise.

poll_interval = 0.5
request_method = 'request'
timeout = 200
class libcloud.common.base.RawResponse(connection)[source]

Bases: libcloud.common.base.Response

Parameters:connection (Connection) – Parent connection object.
headers[source]
reason[source]
response[source]
status[source]
class libcloud.common.base.Response(response, connection)[source]

Bases: object

A base Response class to derive from.

Parameters:
body = None
connection = None
error = None
headers = {}
object = None
parse_body()[source]

Parse response body.

Override in a provider’s subclass.

Returns:Parsed body.
Return type:str
parse_error()[source]

Parse the error messages.

Override in a provider’s subclass.

Returns:Parsed error.
Return type:str
parse_zero_length_body = False
status = 200
success()[source]

Determine if our request was successful.

The meaning of this can be arbitrary; did we receive OK status? Did the node get created? Were we authenticated?

Return type:bool
Returns:True or False
class libcloud.common.base.XmlResponse(response, connection)[source]

Bases: libcloud.common.base.Response

A Base XML Response class to derive from.

Parameters:
parse_body()[source]
parse_error()

libcloud.common.brightbox module

class libcloud.common.brightbox.BrightboxConnection(user_id, key, secure=True, host=None, port=None, url=None, timeout=None, proxy_url=None)[source]

Bases: libcloud.common.base.ConnectionUserAndKey

Connection class for the Brightbox driver

add_default_headers(headers)[source]
encode_data(data)[source]
host = 'api.gb1.brightbox.com'
responseCls

alias of BrightboxResponse

class libcloud.common.brightbox.BrightboxResponse(response, connection)[source]

Bases: libcloud.common.base.JsonResponse

Parameters:
parse_body()[source]
parse_error()[source]
success()[source]

libcloud.common.cloudsigma module

libcloud.common.cloudstack module

class libcloud.common.cloudstack.CloudStackConnection(user_id, key, secure=True, host=None, port=None, url=None, timeout=None, proxy_url=None)[source]

Bases: libcloud.common.base.ConnectionUserAndKey, libcloud.common.base.PollingConnection

ASYNC_FAILURE = 2
ASYNC_PENDING = 0
ASYNC_SUCCESS = 1
add_default_params(params)[source]
encode_data(data)[source]

Must of the data is sent as part of query params (eeww), but in newer versions, userdata argument can be sent as a urlencoded data in the request body.

get_poll_request_kwargs(response, context, request_kwargs)[source]
get_request_kwargs(action, params=None, data='', headers=None, method='GET', context=None)[source]
has_completed(response)[source]
poll_interval = 1
pre_connect_hook(params, headers)[source]
request_method = '_sync_request'
responseCls

alias of CloudStackResponse

timeout = 600
class libcloud.common.cloudstack.CloudStackDriverMixIn(key, secret=None, secure=True, host=None, port=None)[source]

Bases: object

connectionCls

alias of CloudStackConnection

host = None
path = None
class libcloud.common.cloudstack.CloudStackResponse(response, connection)[source]

Bases: libcloud.common.base.JsonResponse

Parameters:
parse_error()[source]

libcloud.common.gandi module

Gandi driver base classes

class libcloud.common.gandi.BaseGandiDriver[source]

Bases: object

Gandi base driver

connectionCls

alias of GandiConnection

name = 'Gandi'
class libcloud.common.gandi.BaseObject(id, state, driver)[source]

Bases: object

Base class for objects not conventional

get_uuid()[source]

Unique hash for this object

Returns:str

The hash is a function of an SHA1 hash of prefix, the object’s ID and its driver which means that it should be unique between all interfaces. TODO : to review >>> from libcloud.compute.drivers.dummy import DummyNodeDriver >>> driver = DummyNodeDriver(0) >>> vif = driver.create_interface() >>> vif.get_uuid() ‘d3748461511d8b9b0e0bfa0d4d3383a619a2bb9f’

Note, for example, that this example will always produce the same UUID!

uuid_prefix = ''
class libcloud.common.gandi.Disk(id, state, name, driver, size, extra=None)[source]

Bases: libcloud.common.gandi.BaseObject

Gandi disk component

class libcloud.common.gandi.GandiConnection(key, secure=True)[source]

Bases: libcloud.common.xmlrpc.XMLRPCConnection, libcloud.common.base.ConnectionKey

Connection class for the Gandi driver

endpoint = '/xmlrpc/'
host = 'rpc.gandi.net'
request(method, *args)[source]
responseCls

alias of GandiResponse

exception libcloud.common.gandi.GandiException[source]

Bases: exceptions.Exception

Exception class for Gandi driver

class libcloud.common.gandi.GandiResponse(response, connection)[source]

Bases: libcloud.common.xmlrpc.XMLRPCResponse

A Base Gandi Response class to derive from.

Parameters:
class libcloud.common.gandi.IPAddress(id, state, inet, driver, version=4, extra=None)[source]

Bases: libcloud.common.gandi.BaseObject

Provide a common interface for ip addresses

uuid_prefix = 'inet:'
class libcloud.common.gandi.NetworkInterface(id, state, mac_address, driver, ips=None, node_id=None, extra=None)[source]

Bases: libcloud.common.gandi.BaseObject

Provide a common interface for network interfaces

uuid_prefix = 'if:'

libcloud.common.gogrid module

class libcloud.common.gogrid.GoGridResponse(*args, **kwargs)[source]

Bases: libcloud.common.base.JsonResponse

parse_error()[source]
success()[source]
class libcloud.common.gogrid.GoGridConnection(user_id, key, secure=True, host=None, port=None, url=None, timeout=None, proxy_url=None)[source]

Bases: libcloud.common.base.ConnectionUserAndKey

Connection class for the GoGrid driver

add_default_params(params)[source]
get_signature(key, secret)[source]

create sig from md5 of key + secret + time

host = 'api.gogrid.com'
request(action, params=None, data='', headers=None, method='GET', raw=False)[source]
responseCls

alias of GoGridResponse

class libcloud.common.gogrid.GoGridIpAddress(id, ip, public, state, subnet)[source]

Bases: object

IP Address

class libcloud.common.gogrid.BaseGoGridDriver[source]

Bases: object

GoGrid has common object model for services they provide, like locations and IP, so keep handling of these things in a single place.

ex_list_ips(**kwargs)[source]

Return list of IP addresses assigned to the account.

Parameters:
  • public (bool) – set to True to list only public IPs or False to list only private IPs. Set to None or not specify at all not to filter by type
  • assigned (bool) – set to True to list only addresses assigned to servers, False to list unassigned addresses and set to None or don’t set at all not no filter by state
  • location (NodeLocation) – filter IP addresses by location
Return type:

list of GoGridIpAddress

name = 'GoGrid'

libcloud.common.google module

Module for Google Connection and Authentication classes.

Information about setting up your Google OAUTH2 credentials:

For libcloud, there are two basic methods for authenticating to Google using OAUTH2: Service Accounts and Client IDs for Installed Applications.

Both are initially set up from the Cloud Console_ _Console: https://cloud.google.com/console

Setting up Service Account authentication (note that you need the PyCrypto package installed to use this):

  • Go to the Console
  • Go to your project and then to “APIs & auth” on the left
  • Click on “Credentials”
  • Click on “Create New Client ID...”
  • Select “Service account” and click on “Create Client ID”
  • Download the Private Key (should happen automatically).
  • The key that you download is a PKCS12 key. It needs to be converted to the PEM format.
  • Convert the key using OpenSSL (the default password is ‘notasecret’): openssl pkcs12 -in YOURPRIVKEY.p12 -nodes -nocerts -passin pass:notasecret | openssl rsa -out PRIV.pem
  • Move the .pem file to a safe location.
  • To Authenticate, you will need to pass the Service Account’s “Email address” in as the user_id and the path to the .pem file as the key.

Setting up Installed Application authentication:

  • Go to the Console
  • Go to your project and then to “APIs & auth” on the left
  • Click on “Credentials”
  • Select “Installed application” and “Other” then click on “Create Client ID”
  • To Authenticate, pass in the “Client ID” as the user_id and the “Client secret” as the key
  • The first time that you do this, the libcloud will give you a URL to visit. Copy and paste the URL into a browser.
  • When you go to the URL it will ask you to log in (if you aren’t already) and ask you if you want to allow the project access to your account.
  • Click on Accept and you will be given a code.
  • Paste that code at the prompt given to you by the Google libcloud connection.
  • At that point, a token & refresh token will be stored in your home directory and will be used for authentication.

Please remember to secure your keys and access tokens.

exception libcloud.common.google.GoogleAuthError(value)[source]

Bases: libcloud.common.types.LibcloudError

Generic Error class for various authentication errors.

class libcloud.common.google.GoogleBaseAuthConnection(user_id, key=None, scopes=None, redirect_uri='urn:ietf:wg:oauth:2.0:oob', login_hint=None, **kwargs)[source]

Bases: libcloud.common.base.ConnectionUserAndKey

Base class for Google Authentication. Should be subclassed for specific types of authentication.

Parameters:
  • user_id (str) – The email address (for service accounts) or Client ID (for installed apps) to be used for authentication.
  • key (str) – The RSA Key (for service accounts) or file path containing key or Client Secret (for installed apps) to be used for authentication.
  • scopes (list) – A list of urls defining the scope of authentication to grant.
  • redirect_uri (str) – The Redirect URI for the authentication request. See Google OAUTH2 documentation for more info.
  • login_hint (str) – Login hint for authentication request. Useful for Installed Application authentication.
add_default_headers(headers)[source]
auth_path = '/o/oauth2/auth'
driver

alias of GoogleBaseDriver

host = 'accounts.google.com'
name = 'Google Auth'
refresh_token(token_info)[source]

Refresh the current token.

Fetch an updated refresh token from internal metadata service.

Parameters:token_info (dict) – Dictionary containing token information. (Not used, but here for compatibility)
Returns:A dictionary containing updated token information.
Return type:dict
responseCls

alias of GoogleResponse

class libcloud.common.google.GoogleBaseConnection(user_id, key=None, auth_type=None, credential_file=None, scopes=None, **kwargs)[source]

Bases: libcloud.common.base.ConnectionUserAndKey, libcloud.common.base.PollingConnection

Base connection class for interacting with Google APIs.

Determine authentication type, set up appropriate authentication connection and get initial authentication information.

Parameters:
  • user_id (str) – The email address (for service accounts) or Client ID (for installed apps) to be used for authentication.
  • key (str) – The RSA Key (for service accounts) or file path containing key or Client Secret (for installed apps) to be used for authentication.
  • auth_type (str) – Accepted values are “SA” or “IA” or “GCE” (“Service Account” or “Installed Application” or “GCE” if libcloud is being used on a GCE instance with service account enabled). If not supplied, auth_type will be guessed based on value of user_id or if the code is being executed in a GCE instance.). If not supplied, auth_type will be guessed based on value of user_id or if the code is running on a GCE instance.
  • credential_file (str) – Path to file for caching authentication information.
  • scopes (list) – List of OAuth2 scope URLs. The empty default sets read/write access to Compute, Storage, and DNS.
add_default_headers(headers)[source]

@inherits: Connection.add_default_headers

driver

alias of GoogleBaseDriver

encode_data(data)[source]

Encode data to JSON

get_poll_request_kwargs(response, context, request_kwargs)[source]

@inherits: PollingConnection.get_poll_request_kwargs

has_completed(response)[source]

Determine if operation has completed based on response.

Parameters:response (I{responseCls}) – JSON response
Returns:True if complete, False otherwise
Return type:bool
host = 'www.googleapis.com'
morph_action_hook(action)[source]

Update action to correct request path.

In many places, the Google API returns a full URL to a resource. This will strip the scheme and host off of the path and just return the request. Otherwise, it will prepend the base request_path to the action.

Parameters:action (str) – The action to be called in the http request
Returns:The modified request based on the action
Return type:str
poll_interval = 2.0
pre_connect_hook(params, headers)[source]

Check to make sure that token hasn’t expired. If it has, get an updated token. Also, add the token to the headers.

@inherits: Connection.pre_connect_hook

request(*args, **kwargs)[source]

@inherits: Connection.request

responseCls

alias of GoogleResponse

timeout = 180
class libcloud.common.google.GoogleBaseDriver[source]

Bases: object

name = 'Google API'
exception libcloud.common.google.GoogleBaseError(value, http_code, code, driver=None)[source]

Bases: libcloud.common.types.ProviderError

class libcloud.common.google.GoogleGCEServiceAcctAuthConnection(user_id, key=None, scopes=None, redirect_uri='urn:ietf:wg:oauth:2.0:oob', login_hint=None, **kwargs)[source]

Bases: libcloud.common.google.GoogleBaseAuthConnection

Authentication class for self-authentication when used with a GCE istance that supports serviceAccounts.

Parameters:
  • user_id (str) – The email address (for service accounts) or Client ID (for installed apps) to be used for authentication.
  • key (str) – The RSA Key (for service accounts) or file path containing key or Client Secret (for installed apps) to be used for authentication.
  • scopes (list) – A list of urls defining the scope of authentication to grant.
  • redirect_uri (str) – The Redirect URI for the authentication request. See Google OAUTH2 documentation for more info.
  • login_hint (str) – Login hint for authentication request. Useful for Installed Application authentication.
get_new_token()[source]

Get a new token from the internal metadata service.

Returns:Dictionary containing token information
Return type:dict
class libcloud.common.google.GoogleInstalledAppAuthConnection(user_id, key=None, scopes=None, redirect_uri='urn:ietf:wg:oauth:2.0:oob', login_hint=None, **kwargs)[source]

Bases: libcloud.common.google.GoogleBaseAuthConnection

Authentication connection for “Installed Application” authentication.

Parameters:
  • user_id (str) – The email address (for service accounts) or Client ID (for installed apps) to be used for authentication.
  • key (str) – The RSA Key (for service accounts) or file path containing key or Client Secret (for installed apps) to be used for authentication.
  • scopes (list) – A list of urls defining the scope of authentication to grant.
  • redirect_uri (str) – The Redirect URI for the authentication request. See Google OAUTH2 documentation for more info.
  • login_hint (str) – Login hint for authentication request. Useful for Installed Application authentication.
get_code()[source]

Give the user a URL that they can visit to authenticate and obtain a code. This method will ask for that code that the user can paste in.

Returns:Code supplied by the user after authenticating
Return type:str
get_new_token()[source]

Get a new token. Generally used when no previous token exists or there is no refresh token

Returns:Dictionary containing token information
Return type:dict
refresh_token(token_info)[source]

Use the refresh token supplied in the token info to get a new token.

Parameters:token_info (dict) – Dictionary containing current token information
Returns:A dictionary containing updated token information.
Return type:dict
class libcloud.common.google.GoogleResponse(response, connection)[source]

Bases: libcloud.common.base.JsonResponse

Google Base Response class.

Parameters:
parse_body()[source]

Parse the JSON response body, or raise exceptions as appropriate.

Returns:JSON dictionary
Return type:dict
success()[source]

Determine if the request was successful.

For the Google response class, tag all responses as successful and raise appropriate Exceptions from parse_body.

Returns:C{True}
class libcloud.common.google.GoogleServiceAcctAuthConnection(user_id, key, *args, **kwargs)[source]

Bases: libcloud.common.google.GoogleBaseAuthConnection

Authentication class for “Service Account” authentication.

Check to see if PyCrypto is available, and convert key file path into a key string if the key is in a file.

Parameters:
  • user_id (str) – Email address to be used for Service Account authentication.
  • key (str) – The RSA Key or path to file containing the key.
get_new_token()[source]

Get a new token using the email address and RSA Key.

Returns:Dictionary containing token information
Return type:dict
exception libcloud.common.google.InvalidRequestError(value, http_code, code, driver=None)[source]

Bases: libcloud.common.google.GoogleBaseError

exception libcloud.common.google.JsonParseError(value, http_code, code, driver=None)[source]

Bases: libcloud.common.google.GoogleBaseError

exception libcloud.common.google.QuotaExceededError(value, http_code, code, driver=None)[source]

Bases: libcloud.common.google.GoogleBaseError

exception libcloud.common.google.ResourceExistsError(value, http_code, code, driver=None)[source]

Bases: libcloud.common.google.GoogleBaseError

exception libcloud.common.google.ResourceInUseError(value, http_code, code, driver=None)[source]

Bases: libcloud.common.google.GoogleBaseError

exception libcloud.common.google.ResourceNotFoundError(value, http_code, code, driver=None)[source]

Bases: libcloud.common.google.GoogleBaseError

libcloud.common.hostvirtual module

class libcloud.common.hostvirtual.HostVirtualConnection(key, secure=True, host=None, port=None, url=None, timeout=None, proxy_url=None)[source]

Bases: libcloud.common.base.ConnectionKey

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

add_default_params(params)[source]
allow_insecure = False
host = 'vapi.vr.org'
exception libcloud.common.hostvirtual.HostVirtualException(code, message)[source]

Bases: libcloud.common.types.LibcloudError

class libcloud.common.hostvirtual.HostVirtualResponse(response, connection)[source]

Bases: libcloud.common.base.JsonResponse

Parameters:
parse_body()[source]
parse_error()[source]
success()[source]
valid_response_codes = [200, 202, 201, 204]

libcloud.common.linode module

exception libcloud.common.linode.LinodeException(code, message)[source]

Bases: exceptions.Exception

Error originating from the Linode API

This class wraps a Linode API error, a list of which is available in the API documentation. All Linode API errors are a numeric code and a human-readable description.

class libcloud.common.linode.LinodeResponse(response, connection)[source]

Bases: libcloud.common.base.JsonResponse

Linode API response

Wraps the HTTP response returned by the Linode API.

libcloud does not take advantage of batching, so a response will always reflect the above format. A few weird quirks are caught here as well.

Instantiate a LinodeResponse from the HTTP response

Parameters:response – The raw response returned by urllib
Returns:parsed LinodeResponse
objects = None
parse_body()[source]

Parse the body of the response into JSON objects

If the response chokes the parser, action and data will be returned as None and errorarray will indicate an invalid JSON exception.

Returns:list of objects and list of errors
success()[source]

Check the response for success

The way we determine success is by the presence of an error in ERRORARRAY. If one is there, we assume the whole request failed.

Returns:bool indicating a successful request
class libcloud.common.linode.LinodeConnection(key, secure=True, host=None, port=None, url=None, timeout=None, proxy_url=None)[source]

Bases: libcloud.common.base.ConnectionKey

A connection to the Linode API

Wraps SSL connections to the Linode API, automagically injecting the parameters that the API needs for each request.

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

add_default_params(params)[source]

Add parameters that are necessary for every request

This method adds api_key and api_responseFormat to the request.

host = 'api.linode.com'
responseCls

alias of LinodeResponse

libcloud.common.openstack module

Common utilities for OpenStack

class libcloud.common.openstack.OpenStackBaseConnection(user_id, key, secure=True, host=None, port=None, timeout=None, ex_force_base_url=None, ex_force_auth_url=None, ex_force_auth_version=None, ex_force_auth_token=None, ex_tenant_name=None, ex_force_service_type=None, ex_force_service_name=None, ex_force_service_region=None)[source]

Bases: libcloud.common.base.ConnectionUserAndKey

Base class for OpenStack connections.

Parameters:
  • user_id (str) – User name to use when authenticating
  • key (str) – Secret to use when authenticating.
  • secure (bool) – Use HTTPS? (True by default.)
  • ex_force_base_url – Base URL for connection requests. If

not specified, this will be determined by authenticating. :type ex_force_base_url: str

Parameters:
  • ex_force_auth_url (str) – Base URL for authentication requests.
  • ex_force_auth_version – Authentication version to use. If

not specified, defaults to AUTH_API_VERSION. :type ex_force_auth_version: str

Parameters:ex_force_auth_token – Authentication token to use for

connection requests. If specified, the connection will not attempt to authenticate, and the value of ex_force_base_url will be used to determine the base request URL. If ex_force_auth_token is passed in, ex_force_base_url must also be provided. :type ex_force_auth_token: str

Parameters:ex_tenant_name – When authenticating, provide this tenant

name to the identity service. A scoped token will be returned. Some cloud providers require the tenant name to be provided at authentication time. Others will use a default tenant if none is provided. :type ex_tenant_name: str

Parameters:ex_force_service_type – Service type to use when selecting an

service. If not specified, a provider specific default will be used. :type ex_force_service_type: str

Parameters:ex_force_service_name – Service name to use when selecting an

service. If not specified, a provider specific default will be used. :type ex_force_service_name: str

Parameters:ex_force_service_region – Region to use when selecting an

service. If not specified, a provider specific default will be used. :type ex_force_service_region: str

add_default_headers(headers)[source]
auth_token = None
auth_token_expires = None
auth_url = None
auth_user_info = None
get_auth_class()[source]

Retrieve identity / authentication class instance.

Return type:OpenStackIdentityConnection
get_endpoint()[source]

Selects the endpoint to use based on provider specific values, or overrides passed in by the user when setting up the driver.

Returns:url of the relevant endpoint for the driver
get_service_catalog()[source]
morph_action_hook(action)[source]
request(action, params=None, data='', headers=None, method='GET', raw=False)[source]
service_catalog = None
service_name = None
service_region = None
service_type = None
class libcloud.common.openstack.OpenStackResponse(response, connection)[source]

Bases: libcloud.common.base.Response

Parameters:
has_content_type(content_type)[source]
node_driver = None
parse_body()[source]
parse_error()[source]
success()[source]
exception libcloud.common.openstack.OpenStackException(value, http_code, driver=None)[source]

Bases: libcloud.common.types.ProviderError

class libcloud.common.openstack.OpenStackDriverMixin(*args, **kwargs)[source]

Bases: object

openstack_connection_kwargs()[source]
Return type:dict

libcloud.common.openstack_identity module

Common / shared code for handling authentication against OpenStack identity service (Keystone).

class libcloud.common.openstack_identity.OpenStackIdentityVersion(version, status, updated, url)[source]

Bases: object

class libcloud.common.openstack_identity.OpenStackIdentityDomain(id, name, enabled)[source]

Bases: object

class libcloud.common.openstack_identity.OpenStackIdentityProject(id, name, description, enabled, domain_id=None)[source]

Bases: object

class libcloud.common.openstack_identity.OpenStackIdentityUser(id, domain_id, name, email, description, enabled)[source]

Bases: object

class libcloud.common.openstack_identity.OpenStackIdentityRole(id, name, description, enabled)[source]

Bases: object

class libcloud.common.openstack_identity.OpenStackServiceCatalog(service_catalog, auth_version='1.1')[source]

Bases: object

http://docs.openstack.org/api/openstack-identity-service/2.0/content/

This class should be instanciated with the contents of the ‘serviceCatalog’ in the auth response. This will do the work of figuring out which services actually exist in the catalog as well as split them up by type, name, and region if available

get_catalog()[source]

Deprecated in the favor of get_entries method.

get_endpoint(service_type=None, name=None, region=None, endpoint_type='external')[source]

Retrieve a single endpoint using the provided criteria.

Note: If no or more than one matching endpoint is found, an exception is thrown.

get_endpoints(service_type=None, name=None)[source]

Retrieve all the endpoints for the provided service type and name.

Return type:list of OpenStackServiceCatalogEntryEndpoint
get_entries()[source]

Return all the entries for this service catalog.

Return type:list of OpenStackServiceCatalogEntry
get_public_urls(service_type=None, name=None)[source]

Retrieve all the available public (external) URLs for the provided service type and name.

get_regions(service_type=None)[source]

Retrieve a list of all the available regions.

Parameters:service_type (str) – If specified, only return regions for this service type.
Return type:list of str
get_service_names(service_type=None, region=None)[source]

Retrieve list of service names that match service type and region.

Return type:list of str
get_service_types(region=None)[source]

Retrieve all the available service types.

Parameters:region (str) – Optional region to retrieve service types for.
Return type:list of str
class libcloud.common.openstack_identity.OpenStackServiceCatalogEntry(service_type, endpoints=None, service_name=None)[source]

Bases: object

Parameters:
  • service_type (str) – Service type.
  • endpoints (list) – Endpoints belonging to this entry.
  • service_name (str) – Optional service name.
class libcloud.common.openstack_identity.OpenStackServiceCatalogEntryEndpoint(region, url, endpoint_type='external')[source]

Bases: object

Parameters:
  • region (str) – Endpoint region.
  • url (str) – Endpoint URL.
  • endpoint_type (str) – Endpoint type (external / internal / admin).
VALID_ENDPOINT_TYPES = ['internal', 'external', 'admin']
class libcloud.common.openstack_identity.OpenStackIdentityEndpointType[source]

Bases: object

Enum class for openstack identity endpoint type.

ADMIN = 'admin'
EXTERNAL = 'external'
INTERNAL = 'internal'
class libcloud.common.openstack_identity.OpenStackIdentityConnection(auth_url, user_id, key, tenant_name=None, timeout=None, parent_conn=None)[source]

Bases: libcloud.common.base.ConnectionUserAndKey

Base identity connection class which contains common / shared logic.

Note: This class shouldn’t be instantiated directly.

add_default_headers(headers)[source]
authenticate(force=False)[source]

Authenticate against the identity API.

Parameters:force (bool) – Forcefully update the token even if it’s already cached and still valid.
authenticated_request(action, params=None, data=None, headers=None, method='GET', raw=False)[source]

Perform an authenticated request against the identity API.

is_token_valid()[source]

Return True if the current auth token is already cached and hasn’t expired yet.

Returns:True if the token is still valid, False otherwise.
Return type:bool
list_supported_versions()[source]

Retrieve a list of all the identity versions which are supported by this installation.

Return type:list of OpenStackIdentityVersion
morph_action_hook(action)[source]
responseCls

alias of OpenStackAuthResponse

timeout = None
class libcloud.common.openstack_identity.OpenStackIdentity_1_0_Connection(auth_url, user_id, key, tenant_name=None, timeout=None, parent_conn=None)[source]

Bases: libcloud.common.openstack_identity.OpenStackIdentityConnection

Connection class for Keystone API v1.0.

auth_version = '1.0'
authenticate(force=False)[source]
name = 'OpenStack Identity API v1.0'
responseCls

alias of OpenStackAuthResponse

class libcloud.common.openstack_identity.OpenStackIdentity_1_1_Connection(auth_url, user_id, key, tenant_name=None, timeout=None, parent_conn=None)[source]

Bases: libcloud.common.openstack_identity.OpenStackIdentityConnection

Connection class for Keystone API v1.1.

auth_version = '1.1'
authenticate(force=False)[source]
name = 'OpenStack Identity API v1.1'
responseCls

alias of OpenStackAuthResponse

class libcloud.common.openstack_identity.OpenStackIdentity_2_0_Connection(auth_url, user_id, key, tenant_name=None, timeout=None, parent_conn=None)[source]

Bases: libcloud.common.openstack_identity.OpenStackIdentityConnection

Connection class for Keystone API v2.0.

auth_version = '2.0'
authenticate(auth_type='api_key', force=False)[source]
list_projects()[source]
list_tenants()[source]
name = 'OpenStack Identity API v1.0'
responseCls

alias of OpenStackAuthResponse

class libcloud.common.openstack_identity.OpenStackIdentity_3_0_Connection(auth_url, user_id, key, tenant_name=None, domain_name='Default', token_scope='project', timeout=None, parent_conn=None)[source]

Bases: libcloud.common.openstack_identity.OpenStackIdentityConnection

Connection class for Keystone API v3.x.

Parameters:
  • tenant_name (str) – Name of the project this user belongs to. Note: When token_scope is set to project, this argument control to which project to scope the token to.
  • domain_name (str) – Domain the user belongs to. Note: Then token_scope is set to token, this argument controls to which domain to scope the token to.
  • token_scope (str) – Whether to scope a token to a “project” or a “domain”
VALID_TOKEN_SCOPES = ['project', 'domain', 'unscoped']
auth_version = '3.0'
authenticate(force=False)[source]

Perform authentication.

create_user(email, password, name, description=None, domain_id=None, default_project_id=None, enabled=True)[source]

Create a new user account.

Parameters:
  • email (str) – User’s mail address.
  • password (str) – User’s password.
  • name (str) – User’s name.
  • description (str) – Optional description.
  • domain_id (str) – ID of the domain to add the user to (optional).
  • default_project_id (str) – ID of the default user project (optional).
  • enabled (bool) – True to enable user after creation.
Returns:

Created user.

Return type:

OpenStackIdentityUser

disable_user(user)[source]

Disable user account.

Note: This operation appears to be idempotent.

Parameters:user (OpenStackIdentityUser) – User to disable.
Returns:User account which has been disabled.
Return type:OpenStackIdentityUser
enable_user(user)[source]

Enable user account.

Note: This operation appears to be idempotent.

Parameters:user (OpenStackIdentityUser) – User to enable.
Returns:User account which has been enabled.
Return type:OpenStackIdentityUser
get_domain(domain_id)[source]

Retrieve information about a single domain.

Parameters:domain_id (str) – ID of domain to retrieve information for.
Rtyle:OpenStackIdentityDomain
grant_domain_role_to_user(domain, role, user)[source]

Grant domain role to a user.

Note: This function appears to be idempodent.

Parameters:
Returns:

True on success.

Return type:

bool

grant_project_role_to_user(project, role, user)[source]

Grant project role to a user.

Note: This function appeats to be idempodent.

Parameters:
Returns:

True on success.

Return type:

bool

list_domains()[source]

List the available domains.

Return type:list of OpenStackIdentityDomain
list_projects()[source]

List the available projects.

Note: To perform this action, user you are currently authenticated with needs to be an admin.

Return type:list of OpenStackIdentityProject
list_roles()[source]

List the available roles.

Return type:list of OpenStackIdentityRole
list_user_domain_roles(domain, user)[source]

Retrieve all the roles for a particular user on a domain.

Return type:list of OpenStackIdentityRole
list_user_projects(user)[source]

Retrieve all the projects user belongs to.

Return type:list of OpenStackIdentityProject
list_users()[source]

List the available users.

Return type:list of OpenStackIdentityUser
name = 'OpenStack Identity API v3.x'
responseCls

alias of OpenStackAuthResponse

revoke_domain_role_from_user(domain, user, role)[source]

Revoke domain role from a user.

Parameters:
Returns:

True on success.

Return type:

bool

revoke_project_role_from_user(project, role, user)[source]

Revoke project role from a user.

Parameters:
Returns:

True on success.

Return type:

bool

libcloud.common.openstack_identity.get_class_for_auth_version(auth_version)[source]

Retrieve class for the provided auth version.

libcloud.common.rackspace module

Common settings for Rackspace Cloud Servers and Cloud Files

libcloud.common.softlayer module

Softlayer connection

class libcloud.common.softlayer.SoftLayerConnection(user_id, key, secure=True, host=None, port=None, url=None, timeout=None, proxy_url=None)[source]

Bases: libcloud.common.xmlrpc.XMLRPCConnection, libcloud.common.base.ConnectionUserAndKey

endpoint = '/xmlrpc/v3'
host = 'api.softlayer.com'
request(service, method, *args, **kwargs)[source]
responseCls

alias of SoftLayerResponse

exception libcloud.common.softlayer.SoftLayerException(value, driver=None)[source]

Bases: libcloud.common.types.LibcloudError

Exception class for SoftLayer driver

exception libcloud.common.softlayer.SoftLayerObjectDoesntExist(value, driver=None)[source]

Bases: libcloud.common.types.LibcloudError

Exception class for SoftLayer driver object doesnt exist

class libcloud.common.softlayer.SoftLayerResponse(response, connection)[source]

Bases: libcloud.common.xmlrpc.XMLRPCResponse

Parameters:
defaultExceptionCls

alias of SoftLayerException

exceptions = {'SoftLayer_Account': <class 'libcloud.common.types.InvalidCredsError'>, 'SoftLayer_Exception_ObjectNotFound': <class 'libcloud.common.softlayer.SoftLayerObjectDoesntExist'>}

libcloud.common.types module

exception libcloud.common.types.LibcloudError(value, driver=None)[source]

Bases: exceptions.Exception

The base class for other libcloud exceptions

exception libcloud.common.types.MalformedResponseError(value, body=None, driver=None)[source]

Bases: libcloud.common.types.LibcloudError

Exception for the cases when a provider returns a malformed response, e.g. you request JSON and provider returns ‘<h3>something</h3>’ due to some error on their side.

exception libcloud.common.types.ProviderError(value, http_code, driver=None)[source]

Bases: libcloud.common.types.LibcloudError

Exception used when provider gives back error response (HTTP 4xx, 5xx) for a request.

Specific sub types can be derieved for errors like HTTP 401 : InvalidCredsError HTTP 404 : NodeNotFoundError, ContainerDoesNotExistError

exception libcloud.common.types.InvalidCredsError(value='Invalid credentials with the provider', driver=None)[source]

Bases: libcloud.common.types.ProviderError

Exception used when invalid credentials are used on a provider.

libcloud.common.types.InvalidCredsException

alias of InvalidCredsError

class libcloud.common.types.LazyList(get_more, value_dict=None)[source]

Bases: object

libcloud.common.xmlrpc module

Base classes for working with xmlrpc APIs

class libcloud.common.xmlrpc.ErrorCodeMixin[source]

Bases: object

This is a helper for API’s that have a well defined collection of error codes that are easily parsed out of error messages. It acts as a factory: it finds the right exception for the error code, fetches any parameters it needs from the context and raises it.

exceptions = {}
raise_exception_for_error(error_code, message)[source]
exception libcloud.common.xmlrpc.ProtocolError[source]

Bases: exceptions.Exception

class libcloud.common.xmlrpc.XMLRPCConnection(secure=True, host=None, port=None, url=None, timeout=None, proxy_url=None)[source]

Bases: libcloud.common.base.Connection

Connection class which can call XMLRPC based API’s.

This class uses the xmlrpclib marshalling and demarshalling code but uses the http transports provided by libcloud giving it better certificate validation and debugging helpers than the core client library.

add_default_headers(headers)[source]
request(method_name, *args, **kwargs)[source]

Call a given method_name.

Parameters:
  • method_name (str) – A method exposed by the xmlrpc endpoint that you are connecting to.
  • args (tuple) – Arguments to invoke with method with.
responseCls

alias of XMLRPCResponse

class libcloud.common.xmlrpc.XMLRPCResponse(response, connection)[source]

Bases: libcloud.common.xmlrpc.ErrorCodeMixin, libcloud.common.base.Response

Parameters:
defaultExceptionCls

alias of Exception

parse_body()[source]
parse_error()[source]
success()[source]

Module contents