Welcome to SlipStream Libcloud driver’s documentation!¶
Libcloud compute driver for SlipStream (http://sixsq.com/slipstream).
Install¶
Latest release from pypi¶
$ pip install slipstream-libcloud-driver
Most recent version from source code¶
$ pip install 'https://github.com/slipstream/slipstream-libcloud-driver/archive/master.zip'
Usage¶
To use this driver please import this file and then use the usual libcloud get_driver function.:
import slipstream.libcloud.compute_driver
from libcloud.compute.providers import get_driver
slipstream_driver = get_driver('slipstream')
Examples¶
Login on Nuvla with username and password¶
ss = slipstream_driver('username', 'password')
Login on Nuvla with key and secret¶
ss = slipstream_driver('credential/ce02ef40-1342-4e68-838d-e1b2a75adb1e',
'the-secret-key',
ex_login_method='api-key')
List Images from the App Store¶
from pprint import pprint as pp
pp(ss.list_images())
List base Images¶
from pprint import pprint as pp
pp(ss.list_images(ex_path='examples/images'))
Simple node creation (WordPress server)¶
# Get the WordPress image
image = ss.get_image('apps/WordPress/wordpress')
# Create the Node
node = ss.create_node(image=image)
Complete application (node) deployment (WordPress server)¶
# Get the WordPress image
image = ss.get_image('apps/WordPress/wordpress')
# WordPress Title
wordpress_title = 'WordPress deployed by SlipStream through Libcloud'
# Create the dict of parameters to (re)define
parameters = dict(wordpress_title=wordpress_title)
# Create the Node
node = ss.create_node(image=image, ex_parameters=parameters)
# Wait the node to be ready
ss.ex_wait_node_in_state(node)
# Update the node
node = ss.ex_get_node(node.id)
# Print the WordPress URL
print node.extra.get('service_url')
Destroy a node (terminate a deployment)¶
# Destroy the node
ss.destroy_node(node)
API documentation¶
Note
Returned nodes will not contain IP addresses.
To obtain them, please use the function ex_list_virtual_machines
or ex_get_node_parameter
as shown below:
# Get the machine:hostname parameter of the node
ip = ss.ex_get_node_parameter(node, 'machine:hostname')
# List all virtual machines for a node
vms = ss.ex_list_virtual_machines(node=node)
# List of IPs per VM
ips = [vm.public_ips + vm.private_ips for vm in vms]
-
class
slipstream.libcloud.compute_driver.
VirtualMachine
(id, name, state, public_ips, private_ips, driver, size=None, image=None, extra=None)[source]¶ A SlipStream Virtual Machine
Parameters: - id (
str
) – Node ID. - name (
str
) – Node name. - state (
libcloud.compute.types.NodeState
) – Node state. - public_ips (
list
) – Public IP addresses associated with this node. - private_ips (
list
) – Private IP addresses associated with this node. - driver (
NodeDriver
) – Driver this node belongs to. - size (
NodeImage
) – Size of this node. (optional) - image – Image of this node. (optional)
- extra (
dict
) – Optional provider specific attributes associated with this node.
- id (
-
class
slipstream.libcloud.compute_driver.
SlipStreamNodeDriver
(key, secret=None, secure=True, host='nuv.la', port=None, api_version=None, **kwargs)[source]¶ SlipStream node driver
- Note: This driver manage KeyPair in a slighty different way than others.
- All configured key pairs are added to VMs at the creation of VMs.
Instanciate a SlipStream node driver.
Parameters: - key (
str
) – Username or API key - secret (
str
) – Password or Secret key - secure (
bool
) – Use secure (HTTPS) connection - host (
str
) – Hostname of the SlipStream endpoint (default: nuv.la) - port (
int
) – Port of the SlipStream endpoint (default: 443 if secure else 80) - api_version (
str
) – [Unused] - ex_endpoint (
str
) – The SlipStream endpoint (example: https://nuv.la) - ex_cookie_file (
str
) – Path to a existing cookie file to use instead of key and secret - ex_login_method (
str
) – Login method (internal for username/password and api-key for key/secret) - ex_login_parameters (
dict
) – Extra parameters to provide to the login method
-
create_key_pair
(name)[source]¶ Create a new key pair object.
This operation require a working PyCrypto installation with RSA object
Parameters: name ( str
) – Key pair name.
-
create_node
(**kwargs)[source]¶ Create a new Node (deploy an application or a component)
Parameters: - name (
str
) – Name of the node (set as a SlipStream Tag). (optional) - size (
NodeSize
) – Size of Cloud resources (SlipStream serviec offer). (optional) If not provided the default of each VM will be used. If provided the size will be applied to all VM. - image (
NodeImage
) – Image to deploy (SlipStream application or component). (required) - location (
NodeLocation
) – Location where to create the node (SlipStream cloud). (optional) If provided all VM will be started in the specified location. If not provided the default location will be used. - ex_tags (
str
orlist
) – List of tags that can be used to identify or annotate a node. - ex_cloud (
str
ordict
) – To be used instead of location to specify the Cloud name on which to start VMs. To deploy a component simply specify the Cloud name as a string. To deploy a deployment specify a dict with the nodenames as keys and Cloud names as values. - ex_parameters (
dict
) – Parameters to (re)define for this image. To redefine a parameter of a SlipStream application’s node use “<nodename>” as keys and dict of parameters as values. To redefine a parameter of a SlipStream component or a global parameter use “<parametername>” as the key. - ex_keep_running ('always' or 'never' or 'on-success' or 'on-error') – [Only applies to SlipStream applications] Define when to terminate or not a deployment when it reach the ‘Ready’ state. If scalable is set to True, this value is ignored and it will behave as if it was set to ‘always’.
- ex_multiplicity (
dict
) – [Only applies to SlipStream applications] A dict to specify how many instances to start per application’s node. Application’s nodenames as keys and number of instances to start as values. - ex_tolerate_failures (
dict
) – [Only applies to SlipStream applications] A dict to specify how many failures to tolerate per application’s node. Nodenames as keys and number of failure to tolerate as values. - ex_check_ssh_key (
bool
) – Set it to True if you want the SlipStream server to check if you have a public ssh key defined. Useful if you want to ensure you will have access to VMs. - ex_scalable (True to start a scalable deployment. (default: False)) – [Only applies to SlipStream applications]
Returns: The newly created node.
Return type: Node
- name (
-
delete_image
(node_image)[source]¶ Deletes a node image from a provider.
Parameters: node_image ( NodeImage
) – Node image object.Returns: True
if delete_image was successful,False
otherwise.Return type: bool
-
delete_key_pair
(key_pair)[source]¶ Delete an existing key pair.
Parameters: key_pair ( KeyPair
) – Key pair object.
-
destroy_node
(node)[source]¶ ” Destroy a node.
Parameters: node ( Node
) – The node to be destroyedReturns: True if the destroy was successful, False otherwise. Return type: bool
-
ex_get_node
(node_id)[source]¶ Get a node from it’s ID
Parameters: node_id ( str
orUUID
) – ID of the node to retrieveReturns: The requested node Return type: Node
-
ex_get_node_parameter
(node, parameter_name, ignore_abort=True)[source]¶ Get the value of a parameter for a node
Parameters: - node (
Node
) – The node from which to get the parameter - parameter_name (str) – The name of the parameter to retrieve
- ignore_abort (
bool
) – If False, raise an exception if the node has failed (default: True)
- node (
-
ex_list_virtual_machines
(location=None, node=None)[source]¶ List Virtual Machines (SlipStream virtual machines)
Parameters: - location (
NodeLocation
) – Return only virtual machines for the specified location - node (
Node
) – List VM belonging to the specified node
Returns: List of virtualmachine objects
Return type: list
ofVirtualMachine
- location (
-
ex_wait_node_in_state
(node, states='Ready', wait_period=10, timeout=600, ignore_abort=False)[source]¶ Wait a node to be in one of the specified states (default: Ready)
Parameters: - states (
str
orlist
) – The names of the states to wait for. (default: Ready) - wait_period (
int
) – How many seconds to wait between each loop iteration. (default: 10) - timeout (
int
) – How many seconds to wait before giving up. (default: 600) - ignore_abort (
bool
) – If False, raise an exception if the node has failed (default: False)
Returns: The state that was reached or raise a LibcloudError if timeout
Return type: str
- states (
-
get_image
(image_id)[source]¶ Get an image from it’s image_id
Parameters: image_id ( str
) – Image ID (SlipStream path)Returns: NodeImage instance on success. Return type: NodeImage
:
-
get_key_pair
(name)[source]¶ Retrieve a single key pair.
Parameters: name ( str
) – Name of the key pair to retrieve.Returns: A key pair Return type: KeyPair
-
import_key_pair_from_file
(name, key_file_path)[source]¶ Import a new public key from string.
Parameters: - name (
str
) – Key pair name. - key_file_path (
str
) – Path to the public key file.
Returns: The key pair
Return type: KeyPair
object- name (
-
import_key_pair_from_string
(name, key_material)[source]¶ Import a new public key from string.
Parameters: - name (
str
) – Key pair name. - key_material (
str
) – Public key material.
Returns: The key pair
Return type: KeyPair
object- name (
-
list_images
(location=None, ex_path=None, ex_recurse=False)[source]¶ List images (SlipStream components and applications)
Parameters: - location (
NodeLocation
) – [NOT IMPLEMENTED] Return only images for the specified location - ex_path (
str
) – Path on which to search for images. (optional) If not provided it will list the content of the App Store. - ex_recurse – Recurse into subprojects. (default: False) Setting this value to True can be expensive.
Returns: list of node image objects.
Return type: list
ofNodeImage
- location (
-
list_key_pairs
()[source]¶ List all the available key pair objects.
Returns: List of configured key pairs Return type: list
ofKeyPair
objects
-
list_locations
()[source]¶ List Locations (SlipStream cloud connectors)
Returns: List of node location objects Return type: list
ofNodeLocation