OnApp Compute Driver Documentation

OnApp software enables Infrastructure-as-a-Service for hosts, telcos and other service providers. It’s a turnkey platform for selling cloud, VPS, dedicated servers, CDN and more through a “single pane of glass” control panel, and now supports Xen, KVM, VMware and Amazon EC2.

../../_images/onapp.png

OnApp has its own non-standard API , libcloud provides a Python wrapper on top of this API with common methods with other IaaS solutions and Public cloud providers. Therefore, you can use the OnApp libcloud driver to communicate with OnApp public clouds.

Instantiating a driver

When you instantiate a driver you need to pass the following arguments to the driver constructor:

  • key - Your OnApp username

  • secret - Your OnApp password

  • host - The host of your OnApp endpoint

  • path - The path to your OnApp endpoint (e.g /client/api for http://onapp.test/client/api)

  • url - The url to your OnApp endpoint, mutually exclusive with host and path

  • secure - True or False. True by default

To authenticate using API key, put your account email as key and the API key to the server as secret.

Example

from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver

#
# Instantiate driver
#
username = "your account username"
password = "your account password"
host = "onapp.test"

cls = get_driver(Provider.ONAPP)
driver = cls(key=username, secret=password, host=host)

#
# Create node
#
name = "virtual_servers_name"  # user-friendly VS description
memory = 2 * 1024  # amount of RAM assigned to the VS in MB
cpus = 2  # number of CPUs assigned to the VS
cpu_shares = 100
# For KVM hypervisor the CPU priority value is always 100. For XEN, set a
# custom value. The default value for XEN is 1
hostname = "vshostname"  # set the host name for this VS
template_id = 8  # the ID of a template from which a VS should be built
primary_disk_size = 100  # set the disk space for this VS
swap_disk_size = None  # set swap space

# optional parameter, but recommended
rate_limit = None
# set max port speed. If none set, the system sets port speed to unlimited

node = driver.create_node(
    name=name,
    ex_memory=memory,
    ex_cpus=cpus,
    ex_cpu_shares=cpu_shares,
    ex_hostname=hostname,
    ex_template_id=template_id,
    ex_primary_disk_size=primary_disk_size,
    ex_swap_disk_size=swap_disk_size,
    ex_rate_limit=rate_limit,
)

#
# List nodes
#
for node in driver.list_nodes():
    print(node)

#
# Destroy node
#
identifier = "nodesidentifier"

(node,) = (n for n in driver.list_nodes() if n.id == identifier)

driver.destroy_node(node)

#
# List images
#
for image in driver.list_images():
    print(image)

#
# List key pairs
#
for key_pair in driver.list_key_pairs():
    print(key_pair)

#
# Get key pair
#
id = 2  # ID of key pair
key_pair = driver.get_key_pair(id)
print(key_pair)

#
# Import key pair from string
#
name = "example"  # this param is unused
key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC8uuUq..."
key_pair = driver.import_key_pair_from_string(name, key)

#
# Import key pair from file
#
driver.import_key_pair_from_file("example", "~/.ssh/id_rsa.pub")

#
# Delete key pair
#
key_pair = driver.list_key_pairs()[0]
driver.delete_key_pair(key_pair)

API Docs

class libcloud.compute.drivers.onapp.OnAppNodeDriver(key, secret=None, secure=True, host=None, port=None, api_version=None, region=None, **kwargs)[source]

Base OnApp node driver.

Parameters:
  • key (str) – API key or username to be used (required)

  • secret (str) – Secret password to be used (required)

  • secure (bool) – Whether to use HTTPS or HTTP. Note: Some providers only support HTTPS, and it is on by default.

  • host (str) – Override hostname used for connections.

  • port (int) – Override port used for connections.

  • api_version (str) – Optional API version. Only used by drivers which support multiple API versions.

  • region (str) – Optional driver region. Only used by drivers which support multiple regions.

Return type:

None

attach_volume(node: Node, volume: StorageVolume, device: Optional[str] = None) bool

Attaches volume to node.

Parameters:
  • node (Node) – Node to attach volume to.

  • volume (StorageVolume) – Volume to attach.

  • device (str) – Where the device is exposed, e.g. ‘/dev/sdb’

Rytpe:

bool

connectionCls

alias of OnAppConnection

copy_image(source_region: str, node_image: NodeImage, name: str, description: Optional[str] = None) NodeImage

Copies an image from a source region to the current region.

Parameters:
  • source_region (str) – Region to copy the node from.

  • node_image (NodeImage:) – NodeImage to copy.

  • name (str) – name for new image.

  • description – description for new image.

Return type:

NodeImage:

Returns:

NodeImage instance on success.

create_image(node: Node, name: str, description: Optional[str] = None) List[NodeImage]

Creates an image from a node object.

Parameters:
  • node (Node) – Node to run the task on.

  • name (description) – name for new image.

  • description – description for new image.

Return type:

NodeImage:

Returns:

NodeImage instance on success.

create_key_pair(name: str) KeyPair

Create a new key pair object.

Parameters:

name (str) – Key pair name.

Return type:

KeyPair object

create_node(name, ex_memory, ex_cpus, ex_cpu_shares, ex_hostname, ex_template_id, ex_primary_disk_size, ex_swap_disk_size, ex_required_virtual_machine_build=1, ex_required_ip_address_assignment=1, **kwargs)[source]

Add a VS

Parameters:

kwargs (dict) – All keyword arguments to create a VS

Return type:

OnAppNode

create_volume(size: int, name: str, location=None, snapshot=None) StorageVolume

Create a new volume.

Parameters:
  • size (int) – Size of volume in gigabytes (required)

  • name (str) – Name of the volume to be created

  • location (NodeLocation) – Which data center to create a volume in. If empty, undefined behavior will be selected. (optional)

  • snapshot (VolumeSnapshot) – Snapshot from which to create the new volume. (optional)

Returns:

The newly created volume.

Return type:

StorageVolume

create_volume_snapshot(volume: StorageVolume, name: Optional[str] = None) VolumeSnapshot

Creates a snapshot of the storage volume.

Parameters:
  • volume (StorageVolume) – The StorageVolume to create a VolumeSnapshot from

  • name (str) – Name of created snapshot (optional)

Return type:

VolumeSnapshot

delete_image(node_image: NodeImage) bool

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)[source]

Delete an existing key pair.

Parameters:

key_pair (KeyPair) – Key pair object.

Returns:

True on success

Return type:

bool

deploy_node(deploy: Deployment, ssh_username: str = 'root', ssh_alternate_usernames: Optional[List[str]] = None, ssh_port: int = 22, ssh_timeout: int = 10, ssh_key: Optional[T_Ssh_key] = None, ssh_key_password: Optional[str] = None, auth: T_Auth = None, timeout: int = 300, max_tries: int = 3, ssh_interface: str = 'public_ips', at_exit_func: Callable = None, wait_period: int = 5, **create_node_kwargs) Node

Create a new node, and start deployment.

In order to be able to SSH into a created node access credentials are required.

A user can pass either a NodeAuthPassword or NodeAuthSSHKey to the auth argument. If the create_node implementation supports that kind if credential (as declared in self.features['create_node']) then it is passed on to create_node. Otherwise it is not passed on to create_node and it is only used for authentication.

If the auth parameter is not supplied but the driver declares it supports generates_password then the password returned by create_node will be used to SSH into the server.

Finally, if the ssh_key_file is supplied that key will be used to SSH into the server.

This function may raise a DeploymentException, if a create_node call was successful, but there is a later error (like SSH failing or timing out). This exception includes a Node object which you may want to destroy if incomplete deployments are not desirable.

>>> from libcloud.compute.drivers.dummy import DummyNodeDriver
>>> from libcloud.compute.deployment import ScriptDeployment
>>> from libcloud.compute.deployment import MultiStepDeployment
>>> from libcloud.compute.base import NodeAuthSSHKey
>>> driver = DummyNodeDriver(0)
>>> key = NodeAuthSSHKey('...') # read from file
>>> script = ScriptDeployment("yum -y install emacs strace tcpdump")
>>> msd = MultiStepDeployment([key, script])
>>> def d():
...     try:
...         driver.deploy_node(deploy=msd)
...     except NotImplementedError:
...         print ("not implemented for dummy driver")
>>> d()
not implemented for dummy driver

Deploy node is typically not overridden in subclasses. The existing implementation should be able to handle most such.

Parameters:
  • deploy (Deployment) – Deployment to run once machine is online and available to SSH.

  • ssh_username (str) – Optional name of the account which is used when connecting to SSH server (default is root)

  • ssh_alternate_usernames (list) – Optional list of ssh usernames to try to connect with if using the default one fails

  • ssh_port (int) – Optional SSH server port (default is 22)

  • ssh_timeout (float) – Optional SSH connection timeout in seconds (default is 10)

  • auth (NodeAuthSSHKey or NodeAuthPassword) – Initial authentication information for the node (optional)

  • ssh_key (str or list of str) – A path (or paths) to an SSH private key with which to attempt to authenticate. (optional)

  • ssh_key_password (str) – Optional password used for encrypted keys.

  • timeout (int) – How many seconds to wait before timing out. (default is 600)

  • max_tries (int) – How many times to retry if a deployment fails before giving up (default is 3)

  • ssh_interface (str) – The interface to wait for. Default is ‘public_ips’, other option is ‘private_ips’.

  • at_exit_func (func) –

    Optional atexit handler function which will be registered and called with created node if user cancels the deploy process (e.g. CTRL+C), after the node has been created, but before the deploy process has finished.

    This method gets passed in two keyword arguments:

    • driver -> node driver in question

    • node -> created Node object

    Keep in mind that this function will only be called in such scenario. In case the method finishes (this includes throwing an exception), at exit handler function won’t be called.

  • wait_period (int) – How many seconds to wait between each iteration while waiting for node to transition into running state and have IP assigned. (default is 5)

destroy_node(node, ex_convert_last_backup=0, ex_destroy_all_backups=0)[source]

Delete a VS

Parameters:
  • node – OnApp node

  • convert_last_backup (int) – set 1 to convert the last VS’s backup to template, otherwise set 0

  • destroy_all_backups (int) – set 1 to destroy all existing backups of this VS, otherwise set 0

destroy_volume(volume: StorageVolume) bool

Destroys a storage volume.

Parameters:

volume (StorageVolume) – Volume to be destroyed

Return type:

bool

destroy_volume_snapshot(snapshot: VolumeSnapshot) bool

Destroys a snapshot.

Parameters:

snapshot (VolumeSnapshot) – The snapshot to delete

Return type:

bool

detach_volume(volume: StorageVolume) bool

Detaches a volume from a node.

Parameters:

volume (StorageVolume) – Volume to be detached

Return type:

bool

features: Dict[str, List[str]] = {'create_node': []}
List of available features for a driver.
get_image(image_id: str) NodeImage

Returns a single node image from a provider.

Parameters:

image_id (str) – Node to run the task on.

:rtype NodeImage: :return: NodeImage instance on success.

get_key_pair(name)[source]

Retrieve a single key pair.

Parameters:

name (str) – ID of the key pair to retrieve.

Return type:

KeyPair object

import_key_pair_from_file(name: str, key_file_path: str) KeyPair

Import a new public key from string.

Parameters:
  • name (str) – Key pair name.

  • key_file_path (str) – Path to the public key file.

Return type:

KeyPair object

import_key_pair_from_string(name, key_material)[source]

Import a new public key from string.

Parameters:
  • name (str) – Key pair name (unused).

  • key_material (str) – Public key material.

Return type:

KeyPair object

list_images()[source]

List all images

Return type:

list of NodeImage

list_key_pairs()[source]

List all the available key pair objects.

Return type:

list of KeyPair objects

list_locations() List[NodeLocation]

List data centers for a provider

Returns:

list of node location objects

Return type:

list of NodeLocation

list_nodes()[source]

List all VS

Return type:

list of OnAppNode

list_sizes(location: Optional[NodeLocation] = None) List[NodeSize]

List sizes on a provider

Parameters:

location (NodeLocation) – The location at which to list sizes

Returns:

list of node size objects

Return type:

list of NodeSize

list_volume_snapshots(volume: StorageVolume) List[VolumeSnapshot]

List snapshots for a storage volume.

Return type:

list of VolumeSnapshot

list_volumes() List[StorageVolume]

List storage volumes.

Return type:

list of StorageVolume

reboot_node(node: Node) bool

Reboot a node.

Parameters:

node (Node) – The node to be rebooted

Returns:

True if the reboot was successful, otherwise False

Return type:

bool

start_node(node: Node) bool

Start a node.

Parameters:

node (Node) – The node to be started

Returns:

True if the start was successful, otherwise False

Return type:

bool

stop_node(node: Node) bool

Stop a node

Parameters:

node (Node) – The node to be stopped.

Returns:

True if the stop was successful, otherwise False

Return type:

bool

wait_until_running(nodes: List[Node], wait_period: float = 5, timeout: int = 600, ssh_interface: str = 'public_ips', force_ipv4: bool = True, ex_list_nodes_kwargs: Optional[Dict] = None) List[Tuple[Node, List[str]]]

Block until the provided nodes are considered running.

Node is considered running when it’s state is “running” and when it has at least one IP address assigned.

Parameters:
  • nodes (list of Node) – List of nodes to wait for.

  • wait_period (int) – How many seconds to wait between each loop iteration. (default is 3)

  • timeout (int) – How many seconds to wait before giving up. (default is 600)

  • ssh_interface (str) – Which attribute on the node to use to obtain an IP address. Valid options: public_ips, private_ips. Default is public_ips.

  • force_ipv4 (bool) – Ignore IPv6 addresses (default is True).

  • ex_list_nodes_kwargs (dict) – Optional driver-specific keyword arguments which are passed to the list_nodes method.

Returns:

[(Node, ip_addresses)] list of tuple of Node instance and list of ip_address on success.

Return type:

list of tuple