Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CloudSigma's Python Library

CloudSigma's Python Library

A quick introduction to CloudSigma's API and Python library. A presentation for for Hack4Europe.

Viktor Petersson

March 17, 2015
Tweet

More Decks by Viktor Petersson

Other Decks in Technology

Transcript

  1. $ pip install cloudsigma $ wget http://goo.gl/fjdtQL -O ~/.cloudsigma.conf $

    chmod 600 ~/.cloudsigma.conf $ vim ~/.cloudsigma.conf Add your credentials and the DC. Step 1: Installation
  2. Let’s make it easier to work with bytes $ pip

    install bitmath Step 1: Installation (cont’d)
  3. Import the library >>> import cloudsigma Import bitmath as well

    >>> import bitmath Access drive and server objects easier >>> drive = cloudsigma.resource.Drive() >>> server = cloudsigma.resource.Server() Step 2: The basics
  4. Let’s create a 10GiB drive template >>> disk_template = {

    'name': ‘Test Drive', 'size': bitmath.GiB(10).bytes, 'media': 'disk' } And then create it… >>> my_disk = drive.create(disk_template) Step 2: Create a drive API section: https://cloudsigma-docs.readthedocs.org/en/latest/drives.html
  5. Let’s create a server template with the drive attached >>>

    server_template = { 'name': 'Test Server', 'cpu': 2000, 'mem': bitmath.GiB(2).bytes, 'vnc_password': 'test_server', 'drive': [{ 'boot_order': 1, 'dev_channel': '0:0', 'device': 'virtio', 'drive': my_disk['uuid'] }], 'nics': [{ 'ip_v4_conf': { 'conf': 'dhcp', 'ip': None }, 'model': 'virtio', 'vlan': None }] } Step 2: Create a server API section: https://cloudsigma-docs.readthedocs.org/en/latest/servers.html
  6. Now create the server >>> test_server = server.create(server_template) Step 2:

    Create a server (cont’d) API section: https://cloudsigma-docs.readthedocs.org/en/latest/servers.html
  7. Starting the server is a breeze >>> server.start(test_server[‘uuid’]) Please note

    that this server won’t get very far, since we’re booting off of an empty drive. You probably want to clone an existing marketplace drive (next slide) for your OS partition. Step 3: Start the server API section: https://cloudsigma-docs.readthedocs.org/en/latest/servers.html
  8. Clone a drive >>> my_clone = drive.clone(uuid {'name': ‘Foobar’}) Resize

    a the clone to 20GiB >>> my_clone[‘size’] = bitmath.GiB(20).bytes >>> drive.update(my_clone[‘uuid’], my_clone) What’s next?
  9. Documentation for the Python library can be found here: https://github.com/cloudsigma/pycloudsigma

    More examples are available here: https://gist.github.com/vpetersson/26472c0a78e78234bad0 The full API documentation is available here: https://cloudsigma-docs.readthedocs.org/en/latest/ More resources