Abiquo API Python Client
This is a Python client for the Abiquo API. It allows to consume the API in a dynamic way and to navigate its resources using its built-in linking features.
The project depends on requests and optionally on requests_oauthlib, if you prefer to use OAuth instead of Basic Authentication.
Installation
You can easily install the module with:
pip install abiquo-api
Usage
Using the client is pretty straightforward. Here are some examples:
Using HTTP Basic Authentication
This example shows how to get the list of existing datacenters and how to navigate its links to create a rack in each of them:
import json
from abiquo.client import Abiquo
from abiquo.client import check_response
api = Abiquo(API_URL, auth=(username, password))
code, datacenters = api.admin.datacenters.get(
headers={'Accept':'application/vnd.abiquo.datacenters+json'})
print "Response code is: %s" % code
for dc in datacenters:
print "Creating rack in datacenter %s [%s]" % (dc.name, dc.location)
code, rack = dc.follow('racks').post(
data=json.dumps({'name': 'New rack'}),
headers={'accept':'application/vnd.abiquo.rack+json',
'content-type':'application/vnd.abiquo.rack+json'})
check_response(201, code, rack)
print "Response code is: %s" % code
print "Created Rack: %s" % rack.name
Note that you don't need to care about pagination, the client handles it internally for you.
Using an OpenID Bearer access token
If your platform uses OpenID and you have a Bearer access token, you can configure the client as follows:
import json
from abiquo.client import Abiquo
from abiquo.auth import BearerTokenAuth
api = Abiquo(API_URL, auth=BearerTokenAuth(token))
Using a token authentication
import json
from abiquo.client import Abiquo
from abiquo.auth import TokenAuth
api = Abiquo(API_URL, auth=TokenAuth(token))
Using OAuth
To use OAuth first you have to register your client application in the Abiquo API. To do that, you can
use the register.py script as follows, and it will register the application and generate the access
tokens:
$ python register.py
Abiquo API endpoint: http://localhost/api
Username or OpenID access_token (prefixed with "openid:"): your-username
Password: your-password
Application name: My Cool App
App key: 54e00f27-6995-40e8-aefe-75f76f514d89
App secret: eayP6ll3G02ypBhQBmg0398HYBldkf3B5Jqti73Z
Access token: c9c9bd44-6812-4ddf-b39d-a27f86bf03da
Access token secret: MifYOffkoPkhk33ZTiGOYnIg8irRjw7BlUCR2GUh7IQKv4omfENlMi/tr+gUdt5L8eRCSYKFQVhI4Npga6mXIVl1tCMHqTldYfqUJZdHr0c=
If your Abiquo platform uses OpenID, then you can register your application using the Access Token as follows:
$ python register.py
Abiquo API endpoint: http://localhost/api
Username or OpenID access_token (prefixed with "openid:"): openid:bac4564c-4522-450e-985b-5f880f02a3dd
Application name: My Cool App
App key: 685df603-cb51-4ffa-bd7e-8b0235f5ac70
App secret: HtoICXYr2WENp5D1g7UjbifNizTFh1I3AW3ylEjm
Access token: b1b2856e-5098-4a54-ae3c-d99b739f6770
Access token secret: pBioSC7SNv/0lPRQWBiOr9uSXf8bIs6D2jVVAy2WkBq3Vr37efMKv3mTugk9+TlTAtrWPsPoPdHDGjEtbb5PBHKb2JKWUC9y+OZ44I4v9kk=
Once you have the tokens, you just have to create the authentication object and pass it to the Abiquo client as follows:
from requests_oauthlib import OAuth1
from abiquo.client import Abiquo
APP_KEY = '54e00f27-6995-40e8-aefe-75f76f514d89'
APP_SECRET = 'eayP6ll3G02ypBhQBmg0398HYBldkf3B5Jqti73Z'
ACCESS_TOKEN = 'c9c9bd44-6812-4ddf-b39d-a27f86bf03da'
ACCESS_TOKEN_SECRET = 'MifYOffkoPkhk33ZTiGOYnIg8irRjw7BlUCR2GUh7IQKv4omfENlMi/tr+gUdt5L8eRCSYKFQVhI4Npga6mXIVl1tCMHqTldYfqUJZdHr0c='
oauth=OAuth1(APP_KEY,
client_secret=APP_SECRET,
resource_owner_key=ACCESS_TOKEN,
resource_owner_secret=ACCESS_TOKEN_SECRET)
api = Abiquo(API_URL, auth=oauth)
And that's it! Now you can use the Abiquo client as shown in the Basic Authentication examples.
Running the tests
You can run the unit tests as follows:
pip install requests requests_oauthlib httpretty
python -m unittest discover -v
Contributing
This project is still in an early development stage and is still incomplete. All contributions are welcome, so feel free to raise a pull request.
License
The Abiquo API Java Client is licensed under the Apache License version 2. For further details, see the LICENSE file.
Metadata
Release files for abiquo-api 0.1.16
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| abiquo-api-0.1.16.tar.gz | 5.9 kB | Without provenance | Details |
Release files / abiquo-api-0.1.16.tar.gz
| Download URL | abiquo-api-0.1.16.tar.gz |
|---|---|
| Size | 5.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
55e781d5cb936983f9ff218441d91c5a687c5a6155fdf8d754042408f5510eff
|
|
BLAKE2b-256 checksum How to use checksums |
328d3648ffc547375ec3c26cea867cc8b94712aab2c278c00e206cbeeddd8ba7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.15.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/44.1.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/2.7.15
|
Security for abiquo-api 0.1.16
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.