Skip to content

moebiuseye/python-ovh

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python & OVH APIs

Lightweight wrapper around OVH's APIs. Handles all the hard work including credential creation and requests signing.

PyPi Version

Build Status

Coverage Status

Installation

The easiest way to get the latest stable release is to grab it from pypi using pip.

Alternatively, you may get latest development version directly from Git.

Example Usage

Use the API on behalf of a user

1. Create an application

To interact with the APIs, the SDK needs to identify itself using an application_key and an application_secret. To get them, you need to register your application. Depending the API you plan yo use, visit:

Once created, you will obtain an application key (AK) and an application secret (AS).

2. Configure your application

The easiest and safest way to use your application's credentials is create an ovh.conf configuration file in application's working directory. Here is how it looks like:

Depending on the API you want to use, you may set the endpoint to:

  • ovh-eu for OVH Europe API
  • ovh-ca for OVH North-America API
  • runabove-ca for RunAbove API

See Configuration for more inforamtions on available configuration mechanisms.

Note

When using a versioning system, make sure to add ovh.conf to ignored files. It contains confidential/security-sensitive informations!

3. Authorize your application to access a customer account

To allow your application to access a customer account using the API on your behalf, you need a consumer key (CK).

Here is a sample code you can use to allow your application to access a customer's informations:

Returned consumerKey should then be kept to avoid re-authenticating your end-user on each use.

Note

To request full and unlimited access to the API, you may use wildcards:

Grab bill list

Let's say you want to integrate OVH bills into your own billing system, you could just script around the /me/bills endpoints and even get the details of each bill lines using /me/bill/{billId}/details/{billDetailId}.

This example assumes an existing Configuration with valid application_key, application_secret and consumer_key.

Enable network burst in SBG1

'Network burst' is a free service but is opt-in. What if you have, say, 10 servers in SBG-1 datacenter? You certainely don't want to activate it manually for each servers. You could take advantage of a code like this.

This example assumes an existing Configuration with valid application_key, application_secret and consumer_key.

List application authorized to access your account

Thanks to the application key / consumer key mechanism, it is possible to finely track applications having access to your data and revoke this access. This examples lists validated applications. It could easily be adapted to manage revocation too.

This example assumes an existing Configuration with valid application_key, application_secret and consumer_key.

Before running this example, make sure you have the tabulate library installed. It's a pretty cool library to pretty print tabular data in a clean and easy way.

>>> pip install tabulate

List Runabove's instance

This example assumes an existing Configuration with valid application_key, application_secret and consumer_key.

Before running this example, make sure you have the tabulate library installed. It's a pretty cool library to pretty print tabular data in a clean and easy way.

>>> pip install tabulate

Configuration

The straightfoward way to use OVH's API keys is to embed them directly in the application code. While this is very convenient, it lacks of elegance and flexibility.

Alternatively it is suggested to use configuration files or environment variables so that the same code may run seamlessly in multiple environments. Production and development for instance.

This wrapper will first look for direct instanciation parameters then OVH_ENDPOINT, OVH_APPLICATION_KEY, OVH_APPLICATION_SECRET and OVH_CONSUMER_KEY environment variables. If either of these parameter is not provided, it will look for a configuration file of the form:

The client will successively attempt to locate this configuration file in

  1. Current working directory: ./ovh.conf
  2. Current user's home directory ~/.ovh.conf
  3. System wide configuration /etc/ovh.conf

This lookup mechanism makes it easy to overload credentials for a specific project or user.

Hacking

This wrapper uses standard Python tools, so you should feel at home with it. Here is a quick outline of what it may look like. A good practice is to run this from a virtualenv.

Get the sources

You've developed a new cool feature ? Fixed an annoying bug ? We'd be happy to hear from you !

Run the tests

Simply run nosetests. It will automatically load its configuration from setup.cfg and output full coverage status. Since we all love quality, please note that we do not accept contributions with test coverage under 100%.

Build the documentation

Documentation is managed using the excellent Sphinx system. For example, to build HTML documentation:

Supported APIs

OVH Europe

OVH North America

Runabove

Related links

About

Thin wrapper around OVH's APIs. Handles all the hard work including credential creation and requests signing.

Resources

License

Stars

Watchers

Forks

Packages

No packages published