OpenStack Compute Driver Documentation

OpenStack is an open-source project which allows you to build and run your own public or private cloud.

../../_images/openstack.png

Among many other private clouds, it also powers Rackspace’s Public Cloud.

Selecting the Nova API version

Along with your connection criteria, you can specify the Nova version with api_version, currently supported versions of Nova are:

  • 1.0

  • 1.1

  • 2.0

  • 2.1 (v12)

  • 2.2 (v13)

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

Openstack = get_driver(Provider.OPENSTACK)

con = Openstack(
    'admin', 'password',
    ex_force_base_url='http://23.12.198.36:8774/v2.1',
    api_version='2.0',
    ex_tenant_name='demo')

Connecting to the OpenStack installation

OpenStack driver constructor takes different arguments with which you describe your OpenStack installation. Those arguments describe things such as the authentication service API URL, authentication service API version and so on.

Keep in mind that the majority of those arguments are optional and in the most common scenario with a default installation, you will only need to provide ex_force_auth_url argument.

Available arguments:

  • ex_force_auth_url - Authentication service (Keystone) API URL. It can either be a full URL with a path (e.g. https://192.168.1.101:5000/v2.0/tokens/) or a base URL without a path (e.g. https://192.168.1.1). If no path is provided, default path for the provided auth version is appended to the base URL.

  • ex_force_auth_version - API version of the authentication service. This argument determines how authentication is performed. Valid and supported versions are:

    • 1.0 - authenticate against the keystone using the provided username and API key (old and deprecated version which was used by Rackspace in the past)

    • 1.1 - authenticate against the keystone using the provided username and API key (old and deprecated version which was used by Rackspace in the past)

    • 2.0 or 2.0_apikey - authenticate against keystone with a username and API key

    • 2.0_password - authenticate against keystone with a username and password

    • 2.0_voms - 2.0 VOMS key

    • 3.x_password - 3.x keystone password

    • 3.x_appcred - 3.x keystone with application credential

    • 3.x_oidc_access_token - OIDC access token

    Unless you are working with a very old version of OpenStack you will either want to use 2.0_apikey or 2.0_password.

  • ex_tenant_name - tenant / project name

  • ex_force_auth_token - token which is used for authentication. If this argument is provided, normal authentication flow is skipped and the OpenStack API endpoint is directly hit with the provided token. Normal authentication flow involves hitting the auth service (Keystone) with the provided username and either password or API key and requesting an authentication token.

  • ex_force_service_type

  • ex_force_service_name

  • ex_force_service_region

  • ex_force_base_url - Base URL to the OpenStack nova API endpoint. By default, driver obtains API endpoint URL from the server catalog, but if this argument is provided, this step is skipped and the provided value is used directly.

  • ex_force_network_url - Base URL to the OpenStack neutron API endpoint. By default, driver obtains API endpoint URL from the server catalog, but if this argument is provided, this step is skipped and the provided value is used directly. Only valid in case of api_version >= 2.0.

  • ex_force_image_url - Base URL to the OpenStack glance API endpoint. By default, driver obtains API endpoint URL from the server catalog, but if this argument is provided, this step is skipped and the provided value is used directly. Only valid in case of api_version >= 2.0.

  • ex_force_volume_url - Base URL to the OpenStack cinder API endpoint. By default, driver obtains API endpoint URL from the server catalog, but if this argument is provided, this step is skipped and the provided value is used directly. Only valid in case of api_version >= 2.0.

Some examples which show how to use this arguments can be found in the section below.

Examples

1. Most common use case - specifying only authentication service endpoint URL and API version

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

import libcloud.security

# This assumes you don't have SSL set up.
# Note: Code like this poses a security risk (MITM attack) and
# that's the reason why you should never use it for anything else
# besides testing. You have been warned.
libcloud.security.VERIFY_SSL_CERT = False

OpenStack = get_driver(Provider.OPENSTACK)
driver = OpenStack(
    "your_auth_username",
    "your_auth_password",
    ex_force_auth_url="http://192.168.1.101:5000",
    ex_force_auth_version="2.0_password",
)

2. Specifying which entry to select in the service catalog using service_type service_name and service_region arguments

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

import libcloud.security

# This assumes you don't have SSL set up.
# Note: Code like this poses a security risk (MITM attack) and
# that's the reason why you should never use it for anything else
# besides testing. You have been warned.
libcloud.security.VERIFY_SSL_CERT = False

OpenStack = get_driver(Provider.OPENSTACK)
driver = OpenStack(
    "your_auth_username",
    "your_auth_password",
    ex_force_auth_url="http://192.168.1.101:5000",
    ex_force_auth_version="2.0_password",
    ex_force_service_type="compute",
    ex_force_service_name="novaCompute",
    ex_force_service_region="MyRegion",
)

3. Skipping the endpoint selection using service catalog by providing ex_force_base_url argument

Keep in mind that the base url must also contain tenant id as the last component of the URL (12345 in the example below).

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

import libcloud.security

# This assumes you don't have SSL set up.
# Note: Code like this poses a security risk (MITM attack) and
# that's the reason why you should never use it for anything else
# besides testing. You have been warned.
libcloud.security.VERIFY_SSL_CERT = False

OpenStack = get_driver(Provider.OPENSTACK)
driver = OpenStack(
    "your_auth_username",
    "your_auth_password",
    ex_force_auth_url="http://192.168.1.101:5000",
    ex_force_auth_version="2.0_password",
    ex_force_base_url="http://192.168.1.101:3000/v1/12345",
)

4. Skipping normal authentication flow and hitting the API endpoint directly using the ex_force_auth_token argument

This is an advanced use cases which assumes you manage authentication and token retrieval yourself.

If you use this argument, the driver won’t hit authentication service and as such, won’t be aware of the token expiration time.

This means auth token will be considered valid for the whole life time of the driver instance and you will need to manually re-instantiate a driver with a new token before the currently used one is about to expire.

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

import libcloud.security

# This assumes you don't have SSL set up.
# Note: Code like this poses a security risk (MITM attack) and
# that's the reason why you should never use it for anything else
# besides testing. You have been warned.
libcloud.security.VERIFY_SSL_CERT = False

OpenStack = get_driver(Provider.OPENSTACK)
driver = OpenStack(
    "your_auth_username",
    "your_auth_password",
    ex_force_auth_url="http://192.168.1.101:5000",
    ex_force_auth_version="2.0_password",
    ex_force_auth_token="authtoken",
)

5. Connecting and specifying a tenant

This example shows how to connect to OpenStack installation which requires you to specify a tenant (ex_tenant_name argument).

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


OpenStack = get_driver(Provider.OPENSTACK)
driver = OpenStack(
    "your_auth_username",
    "your_auth_password",
    ex_tenant_name="mytenant",
    ex_force_auth_url="http://192.168.1.101:5000",
    ex_force_auth_version="2.0_password",
)

6. HP Cloud (www.hpcloud.com)

Connecting to HP Cloud US West and US East (OpenStack Havana).

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

HPCLOUD_AUTH_URL_USWEST = (
    "https://region-a.geo-1.identity.hpcloudsvc.com:35357/v2.0/tokens"
)
HPCLOUD_AUTH_URL_USEAST = (
    "https://region-b.geo-1.identity.hpcloudsvc.com:35357/v2.0/tokens"
)

OpenStack = get_driver(Provider.OPENSTACK)

# HP Cloud US West
driver = OpenStack(
    "your_auth_username",
    "your_auth_password",
    ex_force_auth_version="2.0_password",
    ex_force_auth_url=HPCLOUD_AUTH_URL_USWEST,
    ex_tenant_name="your_tenant_name",
    ex_force_service_region="region-a.geo-1",
    ex_force_service_name="Compute",
)

# HP Cloud US East
driver = OpenStack(
    "your_auth_username",
    "your_auth_password",
    ex_force_auth_version="2.0_password",
    ex_force_auth_url=HPCLOUD_AUTH_URL_USEAST,
    ex_tenant_name="your_tenant_name",
    ex_force_service_region="region-b.geo-1",
    ex_force_service_name="Compute",
)

7. Using Cloud-Init with OpenStack

This example shows how to use cloud-init using the ex_config_drive and ex_userdata arguments to create_node. This example just installs nginx and starts it. More Cloud-Init examples.

Note: You will need to use a cloud-init enabled image. Most Openstack based public cloud providers support it.

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


cloud_init_config = """
#cloud-config

packages:

 - nginx

runcmd:

 - service nginx start

"""


OpenStack = get_driver(Provider.OPENSTACK)
driver = OpenStack(
    "your_auth_username",
    "your_auth_password",
    ex_force_auth_url="http://192.168.1.101:5000",
    ex_force_auth_version="2.0_password",
)

image = driver.get_image("image_id")
size = driver.list_sizes()[0]

node = driver.create_node(
    name="cloud_init",
    image=image,
    size=size,
    ex_userdata=cloud_init_config,
    ex_config_drive=True,
)

8. Authentication token cache

Since version ???, authentication tokens can be stored in an external cache. This enables multiple processes to reuse the tokens, reducing the number of token allocations in the OpenStack authentication service.

from libcloud.common.openstack_identity import OpenStackAuthenticationCache
from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver


class MyAuthenticationCache(OpenStackAuthenticationCache):
    pass  # implement...


auth_cache = MyAuthenticationCache(...)

OpenStack = get_driver(Provider.OPENSTACK)
driver = OpenStack(
    "your_auth_username",
    "your_auth_password",
    ex_force_auth_url="http://192.168.1.101:5000",
    ex_force_auth_version="3.x_password",
    ex_auth_cache=auth_cache,
)

driver.list_sizes()

If the cache implementation stores tokens somewhere outside the process - for instance, to disk or a remote system - running this program twice will allocate a token from OpenStack, store it in the cache, then reuse that token on the second run.

Non-standard functionality and extension methods

OpenStack driver exposes a bunch of non-standard functionality through extension methods and arguments.

This functionality includes:

  • server image management

  • network management

  • floating IP management

  • key-pair management

For information on how to use this functionality please see the method docstrings below.

Other Information

Authentication token re-use

Since version 0.13.0, the driver caches auth token in memory and re-uses it between different requests.

This means that driver will only hit authentication service and obtain auth token on the first request or if the auth token is about to expire.

As noted in the example 4 above, this doesn’t hold true if you use ex_force_auth_token argument.

Tokens can also be stored in an external cache for shared use among multiple processes; see example 8 above.

Troubleshooting

I get Could not find specified endpoint error

This error indicates that the driver couldn’t find a specified API endpoint in the service catalog returned by the authentication service.

There are many different things which could cause this error:

  1. Service catalog is empty

  2. You have not specified a value for one of the following arguments ex_force_service_type, ex_force_service_name, ex_force_service_region and the driver is using the default values which don’t match your installation.

  3. You have specified invalid value for one or all of the following arguments: ex_force_service_type, ex_force_service_name, ex_force_service_region

The best way to troubleshoot this issue is to use LIBCLOUD_DEBUG functionality which is documented in the debugging section. This functionality allows you to introspect the response from the authentication service and you can make sure that ex_force_service_type, ex_force_service_name, ex_force_service_region arguments match values returned in the service catalog.

If the service catalog is empty, you have two options:

  1. Populate the service catalog and makes sure the ex_force_service_type, ex_force_service_name and ex_force_service_region arguments match the values defined in the service catalog.

  2. Provide the API endpoint url using ex_force_base_url argument and skip the “endpoint selection using the service catalog” step all together

I get Resource not found error

This error most likely indicates that you have used an invalid value for the ex_force_base_url argument.

Keep in mind that this argument should point to the OpenStack API endpoint and not to the authentication service API endpoint. API service and authentication service are two different services which listen on different ports.

API Docs

Please note that there are two API versions of the OpenStack Compute API, which are supported by two different subclasses of the OpenStackNodeDriver. The default is the 1.1 API. The 1.0 API is supported to be able to connect to OpenStack instances which do not yet support the version 1.1 API.

Compute 2.0 API version (current)

class libcloud.compute.drivers.openstack.OpenStack_2_NodeDriver(key, secret=None, secure=True, host=None, port=None, api_version='1.1', **kwargs)[source]

OpenStack 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, volume, device='auto')

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 libcloud.compute.drivers.openstack.OpenStack_2_Connection

copy_image(source_region, node_image, name, description=None)

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, name, metadata=None)

Creates a new image.

Parameters
  • node (Node) – Node

  • name (str) – The name for the new image.

  • metadata (dict) – Key and value pairs for metadata.

Return type

NodeImage

create_key_pair(name)

Create a new key pair object.

Parameters

name (str) – Key pair name.

Return type

KeyPair object

create_node(name, size, image=None, ex_keyname=None, ex_userdata=None, ex_config_drive=None, ex_security_groups=None, ex_metadata=None, ex_files=None, networks=None, ex_disk_config=None, ex_admin_pass=None, ex_availability_zone=None, ex_blockdevicemappings=None, ex_os_scheduler_hints=None)

Create a new node

@inherits: NodeDriver.create_node

Parameters
  • ex_keyname (str) – The name of the key pair

  • ex_userdata (str) – String containing user data see https://help.ubuntu.com/community/CloudInit

  • ex_config_drive (bool) – Enable config drive see http://docs.openstack.org/grizzly/openstack-compute/admin/content/config-drive.html

  • ex_security_groups (list of OpenStackSecurityGroup) – List of security groups to assign to the node

  • ex_metadata (dict) – Key/Value metadata to associate with a node

  • ex_files (dict) – File Path => File contents to create on the node

  • networks (list of OpenStackNetwork) – The server is launched into a set of Networks.

  • ex_disk_config (str) – Name of the disk configuration. Can be either AUTO or MANUAL.

  • ex_config_drive – If True enables metadata injection in a server through a configuration drive.

  • ex_admin_pass (str) – The root password for the node

  • ex_availability_zone (str) – Nova availability zone for the node

  • ex_blockdevicemappings (dict) – Enables fine grained control of the block device mapping for an instance.

  • ex_os_scheduler_hints (dict) – The dictionary of data to send to the scheduler.

create_volume(size, name, location=None, snapshot=None, ex_volume_type=None, ex_image_ref=None)[source]

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)

  • ex_volume_type (str) – What kind of volume to create. (optional)

  • ex_image_ref (str) – The image to create the volume from when creating a bootable volume (optional)

Returns

The newly created volume.

Return type

StorageVolume

create_volume_snapshot(volume, name=None, ex_description=None, ex_force=True)[source]

Create snapshot from volume

Parameters
  • volume (StorageVolume) – Instance of StorageVolume

  • name (str | NoneType) – Name of snapshot (optional)

  • ex_description (str | NoneType) – Description of the snapshot (optional)

  • ex_force (bool) – Specifies if we create a snapshot that is not in state available. For example in-use. Defaults to True. (optional)

Return type

VolumeSnapshot

delete_image(image)

Delete a NodeImage

@inherits: NodeDriver.delete_image

Parameters

image (NodeImage) – image witch should be used

Return type

bool

delete_key_pair(key_pair)

Delete a KeyPair.

Parameters

keypair (OpenStackKeyPair) – KeyPair to delete

Return type

bool

deploy_node(deploy, ssh_username='root', ssh_alternate_usernames=None, ssh_port=22, ssh_timeout=10, ssh_key=None, ssh_key_password=None, auth=None, timeout=300, max_tries=3, ssh_interface='public_ips', at_exit_func=None, wait_period=5, **create_node_kwargs)

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)

Destroy a node.

Depending upon the provider, this may destroy all data associated with the node, including backups.

Parameters

node (Node) – The node to be destroyed

Returns

True if the destroy was successful, False otherwise.

Return type

bool

destroy_volume(volume)[source]

Delete a Volume.

Parameters

volume (StorageVolume) – Volume to be deleted

Return type

bool

destroy_volume_snapshot(snapshot)[source]

Delete a Volume Snapshot.

Parameters

snapshot (VolumeSnapshot) – Snapshot to be deleted

Return type

bool

detach_volume(volume, ex_node=None)

Detaches a volume from a node.

Parameters

volume (StorageVolume) – Volume to be detached

Return type

bool

ex_accept_image_member(image_id, member_id)[source]

Accept a pending image as a member.

This call is idempotent unlike ex_create_image_member, you can accept the same image many times.

Parameters
  • image_id (str) – ID of the image to accept

  • project – ID of the project to accept the image as

Return type

bool

ex_add_router_port(router, port)[source]

Add port to a router

Parameters
  • router (OpenStack_2_Router) – Router to add the port

  • port (OpenStack_2_PortInterface) – Port object to be added to the router

Return type

bool

ex_add_router_subnet(router, subnet)[source]

Add subnet to a router

Parameters
  • router (OpenStack_2_Router) – Router to add the subnet

  • subnet (OpenStack_2_SubNet) – Subnet object to be added to the router

Return type

bool

ex_add_server_group(name, policy, rules=[])[source]

Add a Server Group

Parameters
  • name (str) – Server Group Name.

  • policy (str) – Server Group policy.

  • rules (list) – Server Group rules.

Return type

bool

ex_attach_floating_ip_to_node(node, ip)

Attach the floating IP to the node

Parameters
Return type

bool

ex_attach_port_interface(node, port)[source]

Attaches an OpenStack_2_PortInterface to a Node.

Parameters
Return type

bool

ex_confirm_resize(node)

Confirms a pending resize action.

Parameters

node (Node) – Node to resize.

Return type

bool

ex_create_floating_ip(ip_pool=None)

Create new floating IP. The ip_pool attribute is optional only if your infrastructure has only one IP pool available.

Parameters

ip_pool (str) – name of the floating IP pool

Return type

OpenStack_1_1_FloatingIpAddress

ex_create_image_member(image_id, member_id)[source]

Give a project access to an image.

The image should have visibility status ‘shared’.

Note that this is not an idempotent operation. If this action is attempted using a tenant that is already in the image members group the API will throw a Conflict (409). See the ‘create-image-member’ section on https://developer.openstack.org/api-ref/image/v2/index.html

Parameters

image_id (str) – The ID of the image to share with the specified

tenant :param str member_id: The ID of the project / tenant (the image member) Note that this is the Keystone project ID and not the project name, so something like e2151b1fe02d4a8a2d1f5fc331522c0a :return None:

Parameters
  • image_id (str) – ID of the image to share

  • project – ID of the project to give access to the image

Return type

list of NodeImageMember

ex_create_keypair(name)

Create a new KeyPair

Parameters

name (str) – Name of the new KeyPair

Return type

OpenStackKeyPair

ex_create_network(name, **kwargs)[source]

Create a new Network

Parameters

name (str) – Name of network which should be used

Return type

OpenStackNetwork

ex_create_port(network, description=None, admin_state_up=True, name=None)[source]

Creates a new OpenStack_2_PortInterface

Parameters
  • network (OpenStackNetwork) – ID of the network where the newly created port should be attached to

  • description (str) – Description of the port

  • admin_state_up (bool) – The administrative state of the resource, which is up or down

  • name (str) – Human-readable name of the resource

Return type

OpenStack_2_PortInterface

ex_create_router(name, description='', admin_state_up=True, external_gateway_info=None)[source]

Create a new Router

Parameters
  • name (str) – Name of router which should be used

  • description (str) – Description of the port

  • admin_state_up (bool) – The administrative state of the resource, which is up or down

  • external_gateway_info (dict) – The external gateway information

Return type

OpenStack_2_Router

ex_create_security_group(name, description)[source]

Create a new Security Group

Parameters
  • name (str) – Name of the new Security Group

  • description (str) – Description of the new Security Group

Return type

OpenStackSecurityGroup

ex_create_security_group_rule(security_group, ip_protocol, from_port, to_port, cidr=None, source_security_group=None)[source]

Create a new Rule in a Security Group

Parameters
  • security_group (OpenStackSecurityGroup) – Security Group in which to add the rule

  • ip_protocol (str) – Protocol to which this rule applies Examples: tcp, udp, …

  • from_port (int) – First port of the port range

  • to_port (int) – Last port of the port range

  • cidr (str) – CIDR notation of the source IP range for this rule

  • source_security_group (L{OpenStackSecurityGroup) – Existing Security Group to use as the source (instead of CIDR)

Return type

OpenStackSecurityGroupRule

ex_create_snapshot(volume, name, description=None, force=False)

Create a snapshot based off of a volume.

Parameters
  • volume (StorageVolume) – volume

  • name (str) – New name for the volume snapshot

  • description (str) – Description of the snapshot (optional)

  • force (bool) – Whether to force creation (optional)

Return type

VolumeSnapshot

ex_create_subnet(name, network, cidr, ip_version=4, description='', dns_nameservers=None, host_routes=None)[source]

Create a new Subnet

Parameters
  • name (str) – Name of subnet which should be used

  • network (OpenStackNetwork) – Parent network of the subnet

  • cidr (str) – cidr of network which should be used

  • ip_version (int) – ip_version of subnet which should be used

  • description (str) – Description for the resource.

  • dns_nameservers (list of str) – List of dns name servers.

  • host_routes (list of str) – Additional routes for the subnet.

Return type

OpenStack_2_SubNet

ex_del_router_port(router, port)[source]

Remove port from a router

Parameters
  • router (OpenStack_2_Router) – Router to remove the port

  • port (OpenStack_2_PortInterface) – Port object to be added to the router

Return type

bool

ex_del_router_subnet(router, subnet)[source]

Remove subnet to a router

Parameters
  • router (OpenStack_2_Router) – Router to remove the subnet

  • subnet (OpenStack_2_SubNet) – Subnet object to be added to the router

Return type

bool

ex_del_server_group(server_group)[source]

Delete a Server Group

Parameters

server_group (OpenStack_2_ServerGroup) – Server Group which should be deleted

Return type

bool

ex_delete_floating_ip(ip)

Delete specified floating IP

Parameters

ip (OpenStack_1_1_FloatingIpAddress) – floating IP to remove

Return type

bool

ex_delete_keypair(keypair)

Delete a KeyPair.

Parameters

keypair (OpenStackKeyPair) – KeyPair to delete

Return type

bool

ex_delete_network(network)[source]

Delete a Network

Parameters

network (OpenStackNetwork) – Network which should be used

Return type

bool

ex_delete_port(port)[source]

Delete an OpenStack_2_PortInterface

https://developer.openstack.org/api-ref/network/v2/#delete-port

Parameters

port (OpenStack_2_PortInterface) – port interface to remove

Return type

bool

ex_delete_router(router)[source]

Delete a Router

Parameters

router (OpenStack_2_Router) – Router which should be deleted

Return type

bool

ex_delete_security_group(security_group)[source]

Delete a Security Group.

Parameters

security_group (OpenStackSecurityGroup) – Security Group should be deleted

Return type

bool

ex_delete_security_group_rule(rule)[source]

Delete a Rule from a Security Group.

Parameters

rule (OpenStackSecurityGroupRule) – Rule should be deleted

Return type

bool

ex_delete_snapshot(snapshot)

Delete a VolumeSnapshot

Parameters

snapshot (VolumeSnapshot) – snapshot

Return type

bool

ex_delete_subnet(subnet)[source]

Delete a Subnet

Parameters

subnet (OpenStack_2_SubNet) – Subnet which should be deleted

Return type

bool

ex_detach_floating_ip_from_node(node, ip)

Detach the floating IP from the node

Parameters
Return type

bool

ex_detach_port_interface(node, port)[source]

Detaches an OpenStack_2_PortInterface interface from a Node. :param node: node :type node: Node

Parameters

port (OpenStack_2_PortInterface) – port interface to detach

Return type

bool

ex_get_console_output(node, length=None)

Get console output

Parameters
  • node (Node) – node

  • length (int) – Optional number of lines to fetch from the console log

Returns

Dictionary with the output

Return type

dict

ex_get_floating_ip(ip)

Get specified floating IP

Parameters

ip (str) – floating IP to get

Return type

OpenStack_1_1_FloatingIpAddress

ex_get_image_member(image_id, member_id)[source]

Get a member of an image by id

Parameters

image_id – ID of the image of which the member should

be listed :type image_id: str

Parameters

member_id – ID of the member to list

Return type

list of NodeImageMember

ex_get_metadata(node)

Get a Node’s metadata.

Parameters

node (Node) – Node

Returns

Key/Value metadata associated with node.

Return type

dict

ex_get_metadata_for_node(node)

Return the metadata associated with the node.

Parameters

node (Node) – Node instance

Returns

A dictionary or other mapping of strings to strings, associating tag names with tag values.

ex_get_network(network_id)[source]

Retrieve the Network with the given ID

Parameters

networkId (str) – ID of the network

:rtype OpenStackNetwork

ex_get_network_quotas(project_id)[source]

Get the network quotas for a project

Parameters

project_id (str) – The ID of the project.

Return type

OpenStack_2_NetworkQuota

ex_get_node_details(node_id)

Lists details of the specified server.

Parameters

node_id (str) – ID of the node which should be used

Return type

Node

ex_get_node_security_groups(node)

Get Security Groups of the specified server.

Return type

list of OpenStackSecurityGroup

ex_get_port(port_interface_id)[source]

Retrieve the OpenStack_2_PortInterface with the given ID

Parameters

port_interface_id (str) – ID of the requested port

Returns

OpenStack_2_PortInterface

ex_get_quota_set(tenant_id, user_id=None)[source]

Get the quota for a project or a project and a user.

Parameters
  • tenant_id (str) – The UUID of the tenant in a multi-tenancy cloud

  • user_id (str) – ID of user to list the quotas for.

Return type

OpenStack_2_QuotaSet

ex_get_server_group(server_group_id)[source]

Get Server Group

Return type

OpenStack_2_ServerGroup

ex_get_size(size_id)

Get a NodeSize

Parameters

size_id (str) – ID of the size which should be used

Return type

NodeSize

ex_get_size_extra_specs(size_id)

Get the extra_specs field of a NodeSize

Parameters

size_id (str) – ID of the size which should be used

Return type

dict

ex_get_volume(volumeId)[source]

Retrieve the StorageVolume with the given ID

Parameters

volumeId (string) – ID of the volume

Returns

StorageVolume

ex_get_volume_quotas(project_id)[source]

Get the volume quotas for a project

Parameters

project_id (str) – The ID of the project.

Return type

OpenStack_2_VolumeQuota

ex_hard_reboot_node(node)

Hard reboots the specified server

Parameters

node (Node) – node

Return type

bool

ex_import_keypair(name, keyfile)

Import a KeyPair from a file

Parameters
  • name (str) – Name of the new KeyPair

  • keyfile (str) – Path to the public key file (in OpenSSH format)

Return type

OpenStackKeyPair

ex_import_keypair_from_string(name, key_material)

Import a KeyPair from a string

Parameters
  • name (str) – Name of the new KeyPair

  • key_material (str) – Public key (in OpenSSH format)

Return type

OpenStackKeyPair

ex_list_floating_ip_pools()[source]

List available floating IP pools

Return type

list of OpenStack_2_FloatingIpPool

ex_list_floating_ips()

List floating IPs

Return type

list of OpenStack_1_1_FloatingIpAddress

ex_list_image_members(image_id)[source]

List all members of an image. See https://developer.openstack.org/api-ref/image/v2/index.html#sharing

Parameters

image_id – ID of the image of which the members should

be listed :type image_id: str

Return type

list of NodeImageMember

ex_list_keypairs()

Get a list of KeyPairs that are available.

Return type

list of OpenStackKeyPair

ex_list_networks()[source]

Get a list of Networks that are available.

Return type

list of OpenStackNetwork

ex_list_ports()[source]

List all OpenStack_2_PortInterfaces

https://developer.openstack.org/api-ref/network/v2/#list-ports

Return type

list of OpenStack_2_PortInterface

ex_list_routers()[source]

Get a list of Routers that are available.

Return type

list of OpenStack_2_Router

ex_list_security_groups()[source]

Get a list of Security Groups that are available.

Return type

list of OpenStackSecurityGroup

ex_list_server_groups()[source]

List Server Groups

Return type

list of OpenStack_2_ServerGroup

ex_list_snapshots()[source]

Get a list of Snapshot that are available.

Return type

list of VolumeSnapshot

ex_list_subnets()[source]

Get a list of Subnet that are available.

Return type

list of OpenStack_2_SubNet

ex_rebuild(node, image, **kwargs)

Rebuild a Node.

Parameters
  • node (Node) – Node to rebuild.

  • image (NodeImage) – New image to use.

  • ex_metadata (dict) – Key/Value metadata to associate with a node

  • ex_files (dict) – File Path => File contents to create on the node

  • ex_keyname (str) – Name of existing public key to inject into instance

  • ex_userdata (str) – String containing user data see https://help.ubuntu.com/community/CloudInit

  • ex_security_groups (list of OpenStackSecurityGroup) – List of security groups to assign to the node

  • ex_disk_config (str) – Name of the disk configuration. Can be either AUTO or MANUAL.

  • ex_config_drive (bool) – If True enables metadata injection in a server through a configuration drive.

Return type

bool

ex_remove_security_group_from_node(security_group, node)[source]

Remove a Security Group from a node.

Parameters
  • security_group (OpenStackSecurityGroup) – Security Group to remove from node.

  • node (Node) – Node to remove the Security Group.

Return type

bool

ex_rescue(node, password=None)

Rescue a node

Parameters
  • node (Node) – node

  • password (str) – password

Return type

Node

ex_resize(node, size)

Change a node size.

Parameters
  • node (Node) – Node to resize.

  • size (NodeSize) – New size to use.

Return type

bool

ex_revert_resize(node)

Cancels and reverts a pending resize action.

Parameters

node (Node) – Node to resize.

Return type

bool

ex_set_metadata(node, metadata)

Sets the Node’s metadata.

Parameters
  • node (Node) – Node

  • metadata (dict) – Key/Value metadata to associate with a node

Return type

dict

ex_set_password(node, password)

Changes the administrator password for a specified server.

Parameters
  • node (Node) – Node to rebuild.

  • password (str) – The administrator password.

Return type

bool

ex_set_server_name(node, name)

Sets the Node’s name.

Parameters
  • node (Node) – Node

  • name (str) – The name of the server.

Return type

Node

ex_soft_reboot_node(node)

Soft reboots the specified server

Parameters

node (Node) – node

Return type

bool

ex_unrescue(node)

Unrescue a node

Parameters

node (Node) – node

Return type

bool

ex_update_image(image_id, data)[source]

Patch a NodeImage. Can be used to set visibility

Parameters
  • image_id (str) – ID of the image which should be used

  • data – The data to PATCH, either a dict or a list

for example: [

{‘op’: ‘replace’, ‘path’: ‘/visibility’, ‘value’: ‘shared’}

] :type data: dict|list

Return type

NodeImage

ex_update_node(node, **node_updates)

Update the Node’s editable attributes. The OpenStack API currently supports editing name and IPv4/IPv6 access addresses.

The driver currently only supports updating the node name.

Parameters
  • node (Node) – Node

  • name (str) – New name for the server

Return type

Node

ex_update_port(port, description=None, admin_state_up=None, name=None, port_security_enabled=None, qos_policy_id=None, security_groups=None, allowed_address_pairs=None)[source]

Update a OpenStack_2_PortInterface

Parameters
  • port (OpenStack_2_PortInterface) – port interface to update

  • description (str) – Description of the port

  • admin_state_up (bool) – The administrative state of the resource, which is up or down

  • name (str) – Human-readable name of the resource

  • port_security_enabled (bool) – The port security status

  • qos_policy_id (str) – QoS policy associated with the port

  • security_groups (list of str) – The IDs of security groups applied

  • allowed_address_pairs (list of dict containing ip_address and mac_address; mac_address is optional, taken from the port if not specified) – IP and MAC address that the port can use when sending packets if port_security_enabled is true

Return type

OpenStack_2_PortInterface

ex_update_subnet(subnet, name=None, description=None, dns_nameservers=None, host_routes=None)[source]

Update data of an existing SubNet

Parameters
  • subnet (OpenStack_2_SubNet) – Subnet which should be updated

  • name (str) – Name of subnet which should be used

  • description (str) – Description for the resource.

  • dns_nameservers (list of str) – List of dns name servers.

  • host_routes (list of str) – Additional routes for the subnet.

Return type

OpenStack_2_SubNet

get_image(image_id)[source]

Get a NodeImage using the V2 Glance API

@inherits: OpenStack_1_1_NodeDriver.get_image

Parameters

image_id (str) – ID of the image which should be used

Return type

NodeImage

get_key_pair(name)

Retrieve a single key pair.

Parameters

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

Return type

KeyPair

image_connectionCls

alias of libcloud.compute.drivers.openstack.OpenStack_2_ImageConnection

import_key_pair_from_file(name, key_file_path)

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)

Import a new public key from string.

Parameters
  • name (str) – Key pair name.

  • key_material (str) – Public key material.

Return type

KeyPair object

list_images(location=None, ex_only_active=True)[source]

Lists all active images using the V2 Glance API

@inherits: NodeDriver.list_images

Parameters
  • location (NodeLocation) – Which data center to list the images in. If empty, undefined behavior will be selected. (optional)

  • ex_only_active (bool) – True if list only active (optional)

list_key_pairs()

List all the available key pair objects.

Return type

list of KeyPair objects

list_locations()

List data centers for a provider

Returns

list of node location objects

Return type

list of NodeLocation

list_nodes(ex_all_tenants=False)[source]

List the nodes in a tenant

Parameters

ex_all_tenants (bool) – List nodes for all the tenants. Note: Your user must have admin privileges for this functionality to work.

list_sizes(location=None)

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)

List snapshots for a storage volume.

Return type

list of VolumeSnapshot

list_volumes()[source]

Get a list of Volumes that are available.

Return type

list of StorageVolume

network_connectionCls

alias of libcloud.compute.drivers.openstack.OpenStack_2_NetworkConnection

openstack_connection_kwargs()

Returns certain ex_* parameters for this connection.

Return type

dict

reboot_node(node)

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)

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)

Stop a node

Parameters

node (Node) – The node to be stopped.

Returns

True if the stop was successful, otherwise False

Return type

bool

volumev2_connectionCls

alias of libcloud.compute.drivers.openstack.OpenStack_2_VolumeV2Connection

volumev3_connectionCls

alias of libcloud.compute.drivers.openstack.OpenStack_2_VolumeV3Connection

wait_until_running(nodes, wait_period=5, timeout=600, ssh_interface='public_ips', force_ipv4=True, ex_list_nodes_kwargs=None)

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

Compute 1.1 API version (old installations)

class libcloud.compute.drivers.openstack.OpenStack_1_1_NodeDriver(key, secret=None, secure=True, host=None, port=None, api_version='1.1', **kwargs)[source]

OpenStack 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, volume, device='auto')

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 libcloud.compute.drivers.openstack.OpenStack_1_1_Connection

copy_image(source_region, node_image, name, description=None)

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, name, metadata=None)[source]

Creates a new image.

Parameters
  • node (Node) – Node

  • name (str) – The name for the new image.

  • metadata (dict) – Key and value pairs for metadata.

Return type

NodeImage

create_key_pair(name)[source]

Create a new key pair object.

Parameters

name (str) – Key pair name.

Return type

KeyPair object

create_node(name, size, image=None, ex_keyname=None, ex_userdata=None, ex_config_drive=None, ex_security_groups=None, ex_metadata=None, ex_files=None, networks=None, ex_disk_config=None, ex_admin_pass=None, ex_availability_zone=None, ex_blockdevicemappings=None, ex_os_scheduler_hints=None)[source]

Create a new node

@inherits: NodeDriver.create_node

Parameters
  • ex_keyname (str) – The name of the key pair

  • ex_userdata (str) – String containing user data see https://help.ubuntu.com/community/CloudInit

  • ex_config_drive (bool) – Enable config drive see http://docs.openstack.org/grizzly/openstack-compute/admin/content/config-drive.html

  • ex_security_groups (list of OpenStackSecurityGroup) – List of security groups to assign to the node

  • ex_metadata (dict) – Key/Value metadata to associate with a node

  • ex_files (dict) – File Path => File contents to create on the node

  • networks (list of OpenStackNetwork) – The server is launched into a set of Networks.

  • ex_disk_config (str) – Name of the disk configuration. Can be either AUTO or MANUAL.

  • ex_config_drive – If True enables metadata injection in a server through a configuration drive.

  • ex_admin_pass (str) – The root password for the node

  • ex_availability_zone (str) – Nova availability zone for the node

  • ex_blockdevicemappings (dict) – Enables fine grained control of the block device mapping for an instance.

  • ex_os_scheduler_hints (dict) – The dictionary of data to send to the scheduler.

create_volume(size, name, location=None, snapshot=None, ex_volume_type=None)

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)

  • ex_volume_type (str) – What kind of volume to create. (optional)

Returns

The newly created volume.

Return type

StorageVolume

create_volume_snapshot(volume, name=None, ex_description=None, ex_force=True)[source]

Create snapshot from volume

Parameters
  • volume (StorageVolume) – Instance of StorageVolume

  • name (str | NoneType) – Name of snapshot (optional)

  • ex_description (str | NoneType) – Description of the snapshot (optional)

  • ex_force (bool) – Specifies if we create a snapshot that is not in state available. For example in-use. Defaults to True. (optional)

Return type

VolumeSnapshot

delete_image(image)[source]

Delete a NodeImage

@inherits: NodeDriver.delete_image

Parameters

image (NodeImage) – image witch should be used

Return type

bool

delete_key_pair(key_pair)[source]

Delete a KeyPair.

Parameters

keypair (OpenStackKeyPair) – KeyPair to delete

Return type

bool

deploy_node(deploy, ssh_username='root', ssh_alternate_usernames=None, ssh_port=22, ssh_timeout=10, ssh_key=None, ssh_key_password=None, auth=None, timeout=300, max_tries=3, ssh_interface='public_ips', at_exit_func=None, wait_period=5, **create_node_kwargs)

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)

Destroy a node.

Depending upon the provider, this may destroy all data associated with the node, including backups.

Parameters

node (Node) – The node to be destroyed

Returns

True if the destroy was successful, False otherwise.

Return type

bool

destroy_volume(volume)

Destroys a storage volume.

Parameters

volume (StorageVolume) – Volume to be destroyed

Return type

bool

destroy_volume_snapshot(snapshot)[source]

Destroys a snapshot.

Parameters

snapshot (VolumeSnapshot) – The snapshot to delete

Return type

bool

detach_volume(volume, ex_node=None)

Detaches a volume from a node.

Parameters

volume (StorageVolume) – Volume to be detached

Return type

bool

ex_attach_floating_ip_to_node(node, ip)[source]

Attach the floating IP to the node

Parameters
Return type

bool

ex_confirm_resize(node)[source]

Confirms a pending resize action.

Parameters

node (Node) – Node to resize.

Return type

bool

ex_create_floating_ip(ip_pool=None)[source]

Create new floating IP. The ip_pool attribute is optional only if your infrastructure has only one IP pool available.

Parameters

ip_pool (str) – name of the floating IP pool

Return type

OpenStack_1_1_FloatingIpAddress

ex_create_keypair(name)[source]

Create a new KeyPair

Parameters

name (str) – Name of the new KeyPair

Return type

OpenStackKeyPair

ex_create_network(name, cidr)[source]

Create a new Network

Parameters
  • name (str) – Name of network which should be used

  • cidr (str) – cidr of network which should be used

Return type

OpenStackNetwork

ex_create_security_group(name, description)[source]

Create a new Security Group

Parameters
  • name (str) – Name of the new Security Group

  • description (str) – Description of the new Security Group

Return type

OpenStackSecurityGroup

ex_create_security_group_rule(security_group, ip_protocol, from_port, to_port, cidr=None, source_security_group=None)[source]

Create a new Rule in a Security Group

Parameters
  • security_group (OpenStackSecurityGroup) – Security Group in which to add the rule

  • ip_protocol (str) – Protocol to which this rule applies Examples: tcp, udp, …

  • from_port (int) – First port of the port range

  • to_port (int) – Last port of the port range

  • cidr (str) – CIDR notation of the source IP range for this rule

  • source_security_group (L{OpenStackSecurityGroup) – Existing Security Group to use as the source (instead of CIDR)

Return type

OpenStackSecurityGroupRule

ex_create_snapshot(volume, name, description=None, force=False)[source]

Create a snapshot based off of a volume.

Parameters
  • volume (StorageVolume) – volume

  • name (str) – New name for the volume snapshot

  • description (str) – Description of the snapshot (optional)

  • force (bool) – Whether to force creation (optional)

Return type

VolumeSnapshot

ex_delete_floating_ip(ip)[source]

Delete specified floating IP

Parameters

ip (OpenStack_1_1_FloatingIpAddress) – floating IP to remove

Return type

bool

ex_delete_keypair(keypair)[source]

Delete a KeyPair.

Parameters

keypair (OpenStackKeyPair) – KeyPair to delete

Return type

bool

ex_delete_network(network)[source]

Delete a Network

Parameters

network (OpenStackNetwork) – Network which should be used

Return type

bool

ex_delete_security_group(security_group)[source]

Delete a Security Group.

Parameters

security_group (OpenStackSecurityGroup) – Security Group should be deleted

Return type

bool

ex_delete_security_group_rule(rule)[source]

Delete a Rule from a Security Group.

Parameters

rule (OpenStackSecurityGroupRule) – Rule should be deleted

Return type

bool

ex_delete_snapshot(snapshot)[source]

Delete a VolumeSnapshot

Parameters

snapshot (VolumeSnapshot) – snapshot

Return type

bool

ex_detach_floating_ip_from_node(node, ip)[source]

Detach the floating IP from the node

Parameters
Return type

bool

ex_get_console_output(node, length=None)[source]

Get console output

Parameters
  • node (Node) – node

  • length (int) – Optional number of lines to fetch from the console log

Returns

Dictionary with the output

Return type

dict

ex_get_floating_ip(ip)[source]

Get specified floating IP

Parameters

ip (str) – floating IP to get

Return type

OpenStack_1_1_FloatingIpAddress

ex_get_metadata(node)[source]

Get a Node’s metadata.

Parameters

node (Node) – Node

Returns

Key/Value metadata associated with node.

Return type

dict

ex_get_metadata_for_node(node)[source]

Return the metadata associated with the node.

Parameters

node (Node) – Node instance

Returns

A dictionary or other mapping of strings to strings, associating tag names with tag values.

ex_get_network(network_id)[source]

Retrieve the Network with the given ID

Parameters

networkId (str) – ID of the network

:rtype OpenStackNetwork

ex_get_node_details(node_id)

Lists details of the specified server.

Parameters

node_id (str) – ID of the node which should be used

Return type

Node

ex_get_node_security_groups(node)[source]

Get Security Groups of the specified server.

Return type

list of OpenStackSecurityGroup

ex_get_size(size_id)[source]

Get a NodeSize

Parameters

size_id (str) – ID of the size which should be used

Return type

NodeSize

ex_get_size_extra_specs(size_id)[source]

Get the extra_specs field of a NodeSize

Parameters

size_id (str) – ID of the size which should be used

Return type

dict

ex_hard_reboot_node(node)

Hard reboots the specified server

Parameters

node (Node) – node

Return type

bool

ex_import_keypair(name, keyfile)[source]

Import a KeyPair from a file

Parameters
  • name (str) – Name of the new KeyPair

  • keyfile (str) – Path to the public key file (in OpenSSH format)

Return type

OpenStackKeyPair

ex_import_keypair_from_string(name, key_material)[source]

Import a KeyPair from a string

Parameters
  • name (str) – Name of the new KeyPair

  • key_material (str) – Public key (in OpenSSH format)

Return type

OpenStackKeyPair

ex_list_floating_ip_pools()[source]

List available floating IP pools

Return type

list of OpenStack_1_1_FloatingIpPool

ex_list_floating_ips()[source]

List floating IPs

Return type

list of OpenStack_1_1_FloatingIpAddress

ex_list_keypairs()[source]

Get a list of KeyPairs that are available.

Return type

list of OpenStackKeyPair

ex_list_networks()[source]

Get a list of Networks that are available.

Return type

list of OpenStackNetwork

ex_list_security_groups()[source]

Get a list of Security Groups that are available.

Return type

list of OpenStackSecurityGroup

ex_rebuild(node, image, **kwargs)[source]

Rebuild a Node.

Parameters
  • node (Node) – Node to rebuild.

  • image (NodeImage) – New image to use.

  • ex_metadata (dict) – Key/Value metadata to associate with a node

  • ex_files (dict) – File Path => File contents to create on the node

  • ex_keyname (str) – Name of existing public key to inject into instance

  • ex_userdata (str) – String containing user data see https://help.ubuntu.com/community/CloudInit

  • ex_security_groups (list of OpenStackSecurityGroup) – List of security groups to assign to the node

  • ex_disk_config (str) – Name of the disk configuration. Can be either AUTO or MANUAL.

  • ex_config_drive (bool) – If True enables metadata injection in a server through a configuration drive.

Return type

bool

ex_rescue(node, password=None)[source]

Rescue a node

Parameters
  • node (Node) – node

  • password (str) – password

Return type

Node

ex_resize(node, size)[source]

Change a node size.

Parameters
  • node (Node) – Node to resize.

  • size (NodeSize) – New size to use.

Return type

bool

ex_revert_resize(node)[source]

Cancels and reverts a pending resize action.

Parameters

node (Node) – Node to resize.

Return type

bool

ex_set_metadata(node, metadata)[source]

Sets the Node’s metadata.

Parameters
  • node (Node) – Node

  • metadata (dict) – Key/Value metadata to associate with a node

Return type

dict

ex_set_password(node, password)[source]

Changes the administrator password for a specified server.

Parameters
  • node (Node) – Node to rebuild.

  • password (str) – The administrator password.

Return type

bool

ex_set_server_name(node, name)[source]

Sets the Node’s name.

Parameters
  • node (Node) – Node

  • name (str) – The name of the server.

Return type

Node

ex_soft_reboot_node(node)

Soft reboots the specified server

Parameters

node (Node) – node

Return type

bool

ex_unrescue(node)[source]

Unrescue a node

Parameters

node (Node) – node

Return type

bool

ex_update_node(node, **node_updates)[source]

Update the Node’s editable attributes. The OpenStack API currently supports editing name and IPv4/IPv6 access addresses.

The driver currently only supports updating the node name.

Parameters
  • node (Node) – Node

  • name (str) – New name for the server

Return type

Node

get_image(image_id)[source]

Get a NodeImage

@inherits: NodeDriver.get_image

Parameters

image_id (str) – ID of the image which should be used

Return type

NodeImage

get_key_pair(name)[source]

Retrieve a single key pair.

Parameters

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

Return type

KeyPair

import_key_pair_from_file(name, key_file_path)

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.

  • key_material (str) – Public key material.

Return type

KeyPair object

list_images(location=None, ex_only_active=True)

Lists all active images

@inherits: NodeDriver.list_images

Parameters

ex_only_active (bool) – True if list only active (optional)

list_key_pairs()[source]

List all the available key pair objects.

Return type

list of KeyPair objects

list_locations()

List data centers for a provider

Returns

list of node location objects

Return type

list of NodeLocation

list_nodes(ex_all_tenants=False)

List the nodes in a tenant

Parameters

ex_all_tenants (bool) – List nodes for all the tenants. Note: Your user must have admin privileges for this functionality to work.

list_sizes(location=None)

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

List snapshots for a storage volume.

Return type

list of VolumeSnapshot

list_volumes()

List storage volumes.

Return type

list of StorageVolume

openstack_connection_kwargs()

Returns certain ex_* parameters for this connection.

Return type

dict

reboot_node(node)

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)

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)

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, wait_period=5, timeout=600, ssh_interface='public_ips', force_ipv4=True, ex_list_nodes_kwargs=None)

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

Compute 1.0 API version (older installations)

class libcloud.compute.drivers.openstack.OpenStack_1_0_NodeDriver(key, secret=None, secure=True, host=None, port=None, api_version='1.1', **kwargs)[source]

OpenStack node driver.

Extra node attributes:
  • password: root password, available after create.

  • hostId: represents the host your cloud server runs on

  • imageId: id of image

  • flavorId: id of flavor

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, volume, device='auto')

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 libcloud.compute.drivers.openstack.OpenStack_1_0_Connection

copy_image(source_region, node_image, name, description=None)

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, name, description=None, reboot=True)[source]

Create an image for node.

@inherits: NodeDriver.create_image

Parameters
  • node (Node) – node to use as a base for image

  • name (str) – name for new image

Return type

NodeImage

create_key_pair(name)

Create a new key pair object.

Parameters

name (str) – Key pair name.

Return type

KeyPair object

create_node(name, size, image, ex_metadata=None, ex_files=None, ex_shared_ip_group=None, ex_shared_ip_group_id=None)[source]

Create a new node

@inherits: NodeDriver.create_node

Parameters
  • ex_metadata (dict) – Key/Value metadata to associate with a node

  • ex_files (dict) – File Path => File contents to create on the node

  • ex_shared_ip_group_id (str) – The server is launched into that shared IP group

create_volume(size, name, location=None, snapshot=None, ex_volume_type=None)

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)

  • ex_volume_type (str) – What kind of volume to create. (optional)

Returns

The newly created volume.

Return type

StorageVolume

create_volume_snapshot(volume, name=None)

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

Delete an image for node.

@inherits: NodeDriver.delete_image

Parameters

image (NodeImage) – the image to be deleted

Return type

bool

delete_key_pair(key_pair)

Delete an existing key pair.

Parameters

key_pair (KeyPair) – Key pair object.

Return type

bool

deploy_node(deploy, ssh_username='root', ssh_alternate_usernames=None, ssh_port=22, ssh_timeout=10, ssh_key=None, ssh_key_password=None, auth=None, timeout=300, max_tries=3, ssh_interface='public_ips', at_exit_func=None, wait_period=5, **create_node_kwargs)

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)

Destroy a node.

Depending upon the provider, this may destroy all data associated with the node, including backups.

Parameters

node (Node) – The node to be destroyed

Returns

True if the destroy was successful, False otherwise.

Return type

bool

destroy_volume(volume)

Destroys a storage volume.

Parameters

volume (StorageVolume) – Volume to be destroyed

Return type

bool

destroy_volume_snapshot(snapshot)

Destroys a snapshot.

Parameters

snapshot (VolumeSnapshot) – The snapshot to delete

Return type

bool

detach_volume(volume, ex_node=None)

Detaches a volume from a node.

Parameters

volume (StorageVolume) – Volume to be detached

Return type

bool

ex_confirm_resize(node)[source]

Confirm a resize request which is currently in progress. If a resize request is not explicitly confirmed or reverted it’s automatically confirmed after 24 hours.

For more info refer to the API documentation: http://goo.gl/zjFI1

Parameters

node (Node) – node for which the resize request will be confirmed.

Return type

bool

ex_create_ip_group(group_name, node_id=None)[source]

Creates a shared IP group.

Parameters
  • group_name (str) – group name which should be used

  • node_id (str) – ID of the node which should be used

Return type

bool

ex_delete_ip_group(group_id)[source]

Deletes the specified shared IP group.

Parameters

group_id (str) – group id which should be used

Return type

bool

ex_get_node_details(node_id)

Lists details of the specified server.

Parameters

node_id (str) – ID of the node which should be used

Return type

Node

ex_hard_reboot_node(node)

Hard reboots the specified server

Parameters

node (Node) – node

Return type

bool

ex_limits()[source]

Extra call to get account’s limits, such as rates (for example amount of POST requests per day) and absolute limits like total amount of available RAM to be used by servers.

Returns

dict with keys ‘rate’ and ‘absolute’

Return type

dict

ex_list_ip_addresses(node_id)[source]

List all server addresses.

Parameters

node_id (str) – ID of the node which should be used

Return type

OpenStack_1_0_NodeIpAddresses

ex_list_ip_groups(details=False)[source]

Lists IDs and names for shared IP groups. If details lists all details for shared IP groups.

Parameters

details (bool) – True if details is required

Return type

list of OpenStack_1_0_SharedIpGroup

ex_rebuild(node_id, image_id)[source]

Rebuilds the specified server.

Parameters
  • node_id (str) – ID of the node which should be used

  • image_id (str) – ID of the image which should be used

Return type

bool

ex_resize(node, size)[source]

NOTE: This method is here for backward compatibility reasons.

You should use ex_resize_node instead.

ex_resize_node(node, size)[source]

Change an existing server flavor / scale the server up or down.

Parameters
  • node (Node) – node to resize.

  • size (NodeSize) – new size.

Return type

bool

ex_revert_resize(node)[source]

Revert a resize request which is currently in progress. All resizes are automatically confirmed after 24 hours if they have not already been confirmed explicitly or reverted.

For more info refer to the API documentation: http://goo.gl/AizBu

Parameters

node (Node) – node for which the resize request will be reverted.

Return type

bool

ex_set_password(node, password)[source]

Sets the Node’s root password.

This will reboot the instance to complete the operation.

Node.extra['password'] will be set to the new value if the operation was successful.

Parameters
  • node (Node) – node to set password

  • password (str) – new password.

Return type

bool

ex_set_server_name(node, name)[source]

Sets the Node’s name.

This will reboot the instance to complete the operation.

Parameters
  • node (Node) – node to set name

  • name (str) – new name

Return type

bool

ex_share_ip(group_id, node_id, ip, configure_node=True)[source]

Shares an IP address to the specified server.

Parameters
  • group_id (str) – group id which should be used

  • node_id (str) – ID of the node which should be used

  • ip (str) – ip which should be used

  • configure_node (bool) – configure node

Return type

bool

ex_soft_reboot_node(node)

Soft reboots the specified server

Parameters

node (Node) – node

Return type

bool

ex_unshare_ip(node_id, ip)[source]

Removes a shared IP address from the specified server.

Parameters
  • node_id (str) – ID of the node which should be used

  • ip (str) – ip which should be used

Return type

bool

get_image(image_id)

Get an image based on an image_id

@inherits: NodeDriver.get_image

Parameters

image_id (str) – Image identifier

Returns

A NodeImage object

Return type

NodeImage

get_key_pair(name)

Retrieve a single key pair.

Parameters

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

Return type

KeyPair

import_key_pair_from_file(name, key_file_path)

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)

Import a new public key from string.

Parameters
  • name (str) – Key pair name.

  • key_material (str) – Public key material.

Return type

KeyPair object

list_images(location=None, ex_only_active=True)

Lists all active images

@inherits: NodeDriver.list_images

Parameters

ex_only_active (bool) – True if list only active (optional)

list_key_pairs()

List all the available key pair objects.

Return type

list of KeyPair objects

list_locations()

List data centers for a provider

Returns

list of node location objects

Return type

list of NodeLocation

list_nodes(ex_all_tenants=False)

List the nodes in a tenant

Parameters

ex_all_tenants (bool) – List nodes for all the tenants. Note: Your user must have admin privileges for this functionality to work.

list_sizes(location=None)

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)

List snapshots for a storage volume.

Return type

list of VolumeSnapshot

list_volumes()

List storage volumes.

Return type

list of StorageVolume

openstack_connection_kwargs()

Returns certain ex_* parameters for this connection.

Return type

dict

reboot_node(node)

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)

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)

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, wait_period=5, timeout=600, ssh_interface='public_ips', force_ipv4=True, ex_list_nodes_kwargs=None)

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