Skip to main content

A library and command line interface for cloudscale.ch

Project description

license python versions status pypi version PyPI - Downloads

Cloudscale

A cloudscale.ch API client for Python3 and your command line.

Install / Update

pip3 install -U cloudscale --user
export PATH=$PATH:$HOME/.local/bin
cloudscale-cli version

Command Line Interface

Autocompletion

zsh:

eval "$(_CLOUDSCALE_CLI_COMPLETE=source_zsh cloudscale-cli)"

bash:

eval "$(_CLOUDSCALE_CLI_COMPLETE=source cloudscale-cli)"

Authentication

Using the ENV CLOUDSCALE_API_TOKEN variable:

export CLOUDSCALE_API_TOKEN=<your token>
cloudscale-cli flavor list

or by passing the --api-token parameter:

cloudscale-cli server --api-token <your_token> create ...

Help

See all options:

$ cloudscale-cli --help
Usage: cloudscale-cli [OPTIONS] COMMAND [ARGS]...

Options:
  -h, --help  Show this message and exit.

Commands:
  version
  server
  server-group
  floating-ip
  flavor
  image
  region
  network

Usage Examples

Create a Server

cloudscale-cli server create --flavor flex-2 --name my-server --image centos-7 --ssh-keys "$(cat ~/.ssh/id_rsa.pub)"

List all Servers

cloudscale-cli server list

Get Servers having the tag project=gemini

cloudscale-cli server list --filter-tag project=gemini

Usage in Python

List the slug of all flavors

import os
from cloudscale import Cloudscale, CloudscaleApiException

api_token = os.getenv('CLOUDSCALE_API_TOKEN')

cloudscale = Cloudscale(api_token=api_token)
flavors = cloudscale.flavor.get_all()
for flavor in flavors:
    print(flavor['slug'])

Print the server names of running servers

import os
from cloudscale import Cloudscale, CloudscaleApiException

api_token = os.getenv('CLOUDSCALE_API_TOKEN')

cloudscale = Cloudscale(api_token=api_token)
servers = cloudscale.server.get_all()
for server in servers:
    if server['status'] == "running":
        print(server['name'])

Get resource by UUID

import os
from cloudscale import Cloudscale, CloudscaleApiException

api_token = os.getenv('CLOUDSCALE_API_TOKEN')

try:
    cloudscale = Cloudscale(api_token=api_token)
    server_group = cloudscale.server_group.get_by_uuid(uuid="5a1e5b28-d354-47a8-bfb2-01b048c20204")
    print(server_group['name'])
except CloudscaleApiException as e:
    print(e)

Error handling

import os
from cloudscale import Cloudscale, CloudscaleApiException

api_token = os.getenv('CLOUDSCALE_API_TOKEN')

try:
    cloudscale = Cloudscale(api_token=api_token)
    server = cloudscale.server.get_by_uuid(uuid="does-not-exist")
    print(server['name'])
except CloudscaleApiException as e:
    # Prints "API Response Error (404): Not found."
    print(e)
    # Prints "404"
    print(e.status_code)
    # Prints raw API response
    print(e.response)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cloudscale-0.4.0.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cloudscale-0.4.0-py3-none-any.whl (19.6 kB view details)

Uploaded Python 3

File details

Details for the file cloudscale-0.4.0.tar.gz.

File metadata

  • Download URL: cloudscale-0.4.0.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.0.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.5

File hashes

Hashes for cloudscale-0.4.0.tar.gz
Algorithm Hash digest
SHA256 9e8097a9ef7f8074e81abd8fca1f130bccb98f1858603574c353afd1e111e0e0
MD5 15c45d4c4880e1ef17a0e080e7664e01
BLAKE2b-256 e38fb32f33d1b6495e956fd88954b4362d7e596105a7178817e171d6fc2dd106

See more details on using hashes here.

File details

Details for the file cloudscale-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: cloudscale-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 19.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.0.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.5

File hashes

Hashes for cloudscale-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ad9a9ab0bae912e2e7fcd43cee90db7a2ab2611aa6be9e19b23003e960d01d18
MD5 dc4be714ca75ab69bb19eade0d420f51
BLAKE2b-256 25484d64917021e386886781261463844f3b1e96318e3942dc47b9df97032b81

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page