Skip to content

Instantly share code, notes, and snippets.

@Kami
Created Jan 26, 2014
Embed
What would you like to do?
import os
import random
from pprint import pprint
from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver
from libcloud.compute.deployment import ScriptDeployment
API_KEY = 'exoscale api key'
API_SECRET_KEY = 'exoscale api secret key'
# Note: This example uses curl and bash installer for demonstration purposes only.
# On production, you should use a more secure method (e.g. directly using signed
# and verified Debian packages).
BOOTSTRAP_SCRIPT = '''#!/usr/bin/env bash
curl -L https://www.opscode.com/chef/install.sh | sudo bash
'''
PUBLIC_KEY_FILE = os.path.expanduser('~/.ssh/id_rsa.pub')
cls = get_driver(Provider.EXOSCALE)
driver = cls(API_KEY, API_SECRET_KEY)
size = [size for size in driver.list_sizes() if size.name == 'Micro'][0]
image = [image for image in driver.list_images() if 'Ubuntu 12.04 LTS 64-bit'
in image.name][0]
# 1. Import an existing public SSH key
key_pair = driver.import_key_pair_from_file(name='test-key-pair',
key_file_path=PUBLIC_KEY_FILE)
# 2. Bootstrap a node
name = 'exoscale-node-' + str(random.randint(0, 100))
script = ScriptDeployment(script=BOOTSTRAP_SCRIPT)
node = driver.deploy_node(name=name, image=image, size=size, deploy=script,
ex_keyname=key_pair.name,
ssh_key_file=PUBLIC_KEY_FILE)
pprint(node)
pprint(script.stdout)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment