gridscale / gridscale_api_client_python

The official gridscale API client written in Python
MIT License
5 stars 1 forks source link
api gridscale python

gridscale_api_client_python

This the official Python wrapper for gridscale's API. Allowing you to manage your own infrastructure from your own applications.

Prerequisites

First, the Python programming language needs to be installed. This can be done by using the official downloads page.

Once done, download and install via PyPI

$ pip3 install gs_api_client

Introduction

First, you will need your API credentials.

In the examples.py replace the AUTH_TOKEN & USER_UUID with your credentials.

Authentication

These imports and configs need to be setup before other commands can be run. If you do not need synchronous or asynchronous requests, you can leave out SyncGridscaleApiClient & GridscaleApiClient respectively.

from gs_api_client import Configuration
from gs_api_client import SyncGridscaleApiClient, GridscaleApiClient

# Initiate the configuration
config = Configuration()
config.api_key['X-Auth-Token'] = "AUTH_TOKEN"
config.api_key['X-Auth-UserId'] = "USER_UUID"

# Setup the client
sync_api = SyncGridscaleApiClient(configuration=config)
async_api = GridscaleApiClient(configuration=config)

Async vs. sync client

We provide two clients SyncGridscaleApiClient and GridscaleApiClient. gridscale's API performs long running operations asynchronously in the background while returning a 202 response code, with the request identifier in the x-request-id response header.

The main differences are:

Debugging

Adding this line below, will output further information for debugging

config.debug = True

Access response header

Adding http_info=True when instantiating the client, return value will be a tuple of response, response code and response headers (dict).

sync_api = SyncGridscaleApiClient(http_info=True)
async_api = GridscaleApiClient(http_info=True)

Basic request examples

from pprint import pprint

# Get all servers
pprint(async_api.get_servers())

# Create a server
pprint(async_api.create_server({'name':'test', 'cores': 1, 'memory': 2}))

# Update a server
pprint(async_api.update_server('<UUID>', {
    'name':'windows production Server',
    'cores': 2,
    'memory': 4
    }))

# Delete a server
pprint(client.delete_storage('<UUID>'))

Exhaustive list of all functions

Inside the examples.py file, you can see some example requests to get your started. All endpoints are fully documented in our API

Requests

Locations

Servers

Server relations

Storages

Backups

Storage Backup Schedule

Snapshots

Templates

Marketplace applications

Networks

IP addresses

Load balancers

PaaS

Firewalls

ISO images

Labels

SSH keys

Events

Object storage

Certificates

Usages

Development

Create a virtual environment with all necessary dependencies and run the tests as follows:

$ python -m venv .venv
$ source .venv/bin/activate
$ python -m pip install -r dev-requirements.txt
$ pytest

Have fun!