libcloud.container.drivers package

Submodules

libcloud.container.drivers.docker module

class libcloud.container.drivers.docker.DockerConnection(user_id, key, secure=True, host=None, port=None, url=None, timeout=None, proxy_url=None, backoff=None, retry_delay=None)[source]

Bases: libcloud.common.base.ConnectionUserAndKey

add_default_headers(headers)[source]

Add parameters that are necessary for every request If user and password are specified, include a base http auth header

responseCls

alias of DockerResponse

timeout = 60
class libcloud.container.drivers.docker.DockerContainerDriver(key='', secret='', secure=False, host='localhost', port=4243, key_file=None, cert_file=None)[source]

Bases: libcloud.container.base.ContainerDriver

Docker container driver class.

>>> from libcloud.container.providers import get_driver
>>> driver = get_driver('docker')
>>> conn = driver(host='198.61.239.128', port=4243)
>>> conn.list_containers()
or connecting to http basic auth protected https host:
>>> conn = driver('user', 'pass', host='https://198.61.239.128', port=443)

connect with tls authentication, by providing a hostname, port, a private key file (.pem) and certificate (.pem) file >>> conn = driver(host=’https://198.61.239.128’, >>> port=4243, key_file=’key.pem’, cert_file=’cert.pem’)

Parameters:
  • key (str) – API key or username to 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.
  • key_file (str) – Path to private key for TLS connection (optional)
  • cert_file (str) – Path to public key for TLS connection (optional)
Returns:

None

connectionCls

alias of DockerConnection

deploy_container(name, image, parameters=None, start=True, command=None, hostname=None, user='', stdin_open=True, tty=True, mem_limit=0, ports=None, environment=None, dns=None, volumes=None, volumes_from=None, network_disabled=False, entrypoint=None, cpu_shares=None, working_dir='', domainname=None, memswap_limit=0, port_bindings=None, network_mode='bridge', labels=None)[source]

Deploy an installed container image

For details on the additional parameters see : http://bit.ly/1PjMVKV

Parameters:
  • name (str) – The name of the new container
  • image (libcloud.container.base.ContainerImage) – The container image to deploy
  • parameters (str) – Container Image parameters
  • start (bool) – Start the container on deployment
Return type:

Container

destroy_container(container)[source]

Remove a container

Parameters:container (libcloud.container.base.Container) – The container to be destroyed
Returns:True if the destroy was successful, False otherwise.
Return type:bool
ex_delete_image(image)[source]

Remove image from the filesystem

Parameters:image (libcloud.container.base.ContainerImage) – The image to remove
Return type:bool
ex_get_logs(container, stream=False)[source]

Get container logs

If stream == True, logs will be yielded as a stream From Api Version 1.11 and above we need a GET request to get the logs Logs are in different format of those of Version 1.10 and below

Parameters:
Return type:

bool

ex_list_processes(container)[source]

List processes running inside a container

Parameters:container (libcloud.container.base.Container) – The container to list processes for.
Return type:str
ex_rename_container(container, name)[source]

Rename a container

Parameters:
Return type:

libcloud.container.base.Container

ex_search_images(term)[source]

Search for an image on Docker.io. Returns a list of ContainerImage objects

>>> images = conn.ex_search_images(term='mistio')
>>> images
[<ContainerImage: id=rolikeusch/docker-mistio...>,
 <ContainerImage: id=mist/mistio, name=mist/mistio,
     driver=Docker  ...>]
param term:The search term
type term:str
rtype:list of libcloud.container.base.ContainerImage
get_container(id)[source]

Get a container by ID

Parameters:id (str) – The ID of the container to get
Return type:libcloud.container.base.Container
install_image(path)[source]

Install a container image from a remote path.

Parameters:path (str) – Path to the container image
Return type:libcloud.container.base.ContainerImage
list_containers(image=None, all=True)[source]

List the deployed container images

Parameters:
Return type:

list of libcloud.container.base.Container

list_images()[source]

List the installed container images

Return type:list of libcloud.container.base.ContainerImage
name = 'Docker'
restart_container(container)[source]

Restart a container

Parameters:container (libcloud.container.base.Container) – The container to be stopped
Returns:The container refreshed with current data
Return type:libcloud.container.base.Container
start_container(container)[source]

Start a container

Parameters:container (libcloud.container.base.Container) – The container to be started
Returns:The container refreshed with current data
Return type:libcloud.container.base.Container
stop_container(container)[source]

Stop a container

Parameters:container (libcloud.container.base.Container) – The container to be stopped
Returns:The container refreshed with current data
Return type:libcloud.container.base.Container
supports_clusters = False
type = 'docker'
version = '1.24'
website = 'http://docker.io'
exception libcloud.container.drivers.docker.DockerException(code, message)[source]

Bases: Exception

class libcloud.container.drivers.docker.DockerResponse(response, connection)[source]

Bases: libcloud.common.base.JsonResponse

Parameters:
  • response (httplib.HTTPResponse) – HTTP response object. (optional)
  • connection (Connection) – Parent connection object.
parse_body()[source]

Parse response body.

Override in a provider’s subclass.

Returns:Parsed body.
Return type:str
parse_error()[source]

Parse the error messages.

Override in a provider’s subclass.

Returns:Parsed error.
Return type:str
success()[source]

Determine if our request was successful.

The meaning of this can be arbitrary; did we receive OK status? Did the node get created? Were we authenticated?

Return type:bool
Returns:True or False
valid_response_codes = [<HTTPStatus.OK: 200>, <HTTPStatus.ACCEPTED: 202>, <HTTPStatus.CREATED: 201>, <HTTPStatus.NO_CONTENT: 204>]
class libcloud.container.drivers.docker.DockertlsConnection(key, secret, secure=True, host='localhost', port=4243, key_file='', cert_file='', **kwargs)[source]

Bases: libcloud.common.base.KeyCertificateConnection

add_default_headers(headers)[source]

Adds default headers (such as Authorization, X-Foo-Bar) to the passed headers

Should return a dictionary.

responseCls

alias of DockerResponse

libcloud.container.drivers.docker.ts_to_str(timestamp)[source]

Return a timestamp as a nicely formated datetime string.

libcloud.container.drivers.dummy module

class libcloud.container.drivers.dummy.DummyContainerDriver(api_key, api_secret)[source]

Bases: libcloud.container.base.ContainerDriver

Dummy Container driver.

>>> from libcloud.container.drivers.dummy import DummyContainerDriver
>>> driver = DummyContainerDriver('key', 'secret')
>>> driver.name
'Dummy Container Provider'
Parameters:
  • api_key (str) – API key or username to used (required)
  • api_secret (str) – Secret password to be used (required)
Return type:

None

name = 'Dummy Container Provider'
supports_clusters = False
website = 'http://example.com'

libcloud.container.drivers.ecs module

class libcloud.container.drivers.ecs.ElasticContainerDriver(access_id, secret, region)[source]

Bases: libcloud.container.base.ContainerDriver

connectionCls

alias of ECSJsonConnection

create_cluster(name, location=None)[source]

Create a container cluster

Parameters:
Return type:

libcloud.container.base.ContainerCluster

deploy_container(name, image, cluster=None, parameters=None, start=True, ex_cpu=10, ex_memory=500, ex_container_port=None, ex_host_port=None)[source]

Creates a task definition from a container image that can be run in a cluster.

Parameters:
Return type:

libcloud.container.base.Container

destroy_cluster(cluster)[source]

Delete a cluster

Returns:True if the destroy was successful, otherwise False.
Return type:bool
destroy_container(container)[source]

Destroy a deployed container

Parameters:container (libcloud.container.base.Container) – The container to destroy
Return type:libcloud.container.base.Container
ecrConnectionClass

alias of ECRJsonConnection

ecr_repository_host = '%s.dkr.ecr.%s.amazonaws.com'
ex_create_service(name, cluster, task_definition, desired_count=1)[source]

Runs and maintains a desired number of tasks from a specified task definition. If the number of tasks running in a service drops below desired_count, Amazon ECS spawns another instantiation of the task in the specified cluster.

Parameters:
  • name (str) – the name of the service
  • cluster (libcloud.container.base.ContainerCluster) – The cluster to run the service on
  • task_definition (str) – The task definition name or ARN for the service
  • desired_count (int) – The desired number of tasks to be running at any one time
Return type:

object The service object

ex_describe_service(service_arn)[source]

Get the details of a service

Parameters:
Returns:

The service object

Return type:

object

ex_destroy_service(service_arn)[source]

Deletes a service

Parameters:
ex_get_registry_client(repository_name)[source]

Get a client for an ECR repository

Parameters:repository_name (str) – The unique name of the repository
Returns:a docker registry API client
Return type:libcloud.container.utils.docker.RegistryClient
ex_get_repository_id(repository_name)[source]

Get the ID of a repository

Parameters:repository_name (str) – The unique name of the repository
Returns:The repository ID
Return type:str
ex_get_repository_token(repository_id)[source]

Get the authorization token (12 hour expiry) for a repository

Parameters:repository_id (str) – The ID of the repository
Returns:A token for login
Return type:str
ex_list_containers_for_task(task_arns)[source]

Get a list of containers by ID collection (ARN)

Parameters:task_arns (list of str) – The list of ARNs
Return type:list of libcloud.container.base.Container
ex_list_service_arns(cluster=None)[source]

List the services

Parameters:cluster (libcloud.container.base.ContainerCluster) – The cluster hosting the services
Return type:list of str
ex_start_task(task_arn, count=1)[source]

Run a task definition and get the containers

Parameters:
  • task_arn (str) – The task ARN to Run
  • count (int) – The number of containers to start
Return type:

list of libcloud.container.base.Container

get_container(id)[source]

Get a container by ID

Parameters:id (str) – The ID of the container to get
Return type:libcloud.container.base.Container
list_clusters()[source]

Get a list of potential locations to deploy clusters into

Parameters:location (libcloud.container.base.ClusterLocation) – The location to search in
Return type:list of libcloud.container.base.ContainerCluster
list_containers(image=None, cluster=None)[source]

List the deployed container images

Parameters:
Return type:

list of libcloud.container.base.Container

list_images(ex_repository_name)[source]

List the images in an ECR repository

Parameters:ex_repository_name (str) – The name of the repository to check defaults to the default repository.
Returns:a list of images
Return type:list of libcloud.container.base.ContainerImage
name = 'Amazon Elastic Container Service'
restart_container(container)[source]

Restart a deployed container

Parameters:container (libcloud.container.base.Container) – The container to restart
Return type:libcloud.container.base.Container
start_container(container, count=1)[source]

Start a deployed task

Parameters:
Return type:

libcloud.container.base.Container

status_map = {'RUNNING': 'running'}
stop_container(container)[source]

Stop a deployed container

Parameters:container (libcloud.container.base.Container) – The container to stop
Return type:libcloud.container.base.Container
supports_clusters = False
website = 'https://aws.amazon.com/ecs/details/'

libcloud.container.drivers.gke module

class libcloud.container.drivers.gke.GKEConnection(user_id, key, secure, auth_type=None, credential_file=None, project=None, **kwargs)[source]

Bases: libcloud.common.google.GoogleBaseConnection

Connection class for the GKE driver.

GKEConnection extends google.GoogleBaseConnection for 3 reasons:
  1. modify request_path for GKE URI.
  2. Implement gce_params functionality described below.
  3. Add request_aggregated_items method for making aggregated API calls.
host = 'container.googleapis.com'
pre_connect_hook(params, headers)[source]

Update URL parameters with values from self.gke_params.

@inherits: GoogleBaseConnection.pre_connect_hook

request(*args, **kwargs)[source]

Perform request then do GKE-specific processing of URL params.

@inherits: GoogleBaseConnection.request

responseCls

alias of GKEResponse

class libcloud.container.drivers.gke.GKEContainerDriver(user_id, key=None, datacenter=None, project=None, auth_type=None, scopes=None, credential_file=None, host=None, port=443, **kwargs)[source]

Bases: libcloud.container.drivers.kubernetes.KubernetesContainerDriver

GKE Container Driver class.

This is the primary driver for interacting with Google Container Engine. It contains all of the standard libcloud methods, plus additional ex_* methods for more features.

Note that many methods allow either objects or strings (or lists of objects/strings). In most cases, passing strings instead of objects will result in additional GKE API calls.

Parameters:
  • user_id (str) – The email address (for service accounts) or Client ID (for installed apps) to be used for authentication.
  • key (str) – The RSA Key (for service accounts) or file path containing key or Client Secret (for installed apps) to be used for authentication.
  • datacenter (str) – The name of the datacenter (zone) used for operations.
  • project (str) – Your GKE project name. (required)
  • auth_type (str) – Accepted values are “SA” or “IA” or “GKE” (“Service Account” or “Installed Application” or “GKE” if libcloud is being used on a GKE instance with service account enabled). If not supplied, auth_type will be guessed based on value of user_id or if the code is being executed in a GKE instance.
  • scopes (list) – List of authorization URLs. Default is empty and grants read/write to Compute, Storage, DNS.
  • credential_file (str) – Path to file for caching authentication information used by GKEConnection.
AUTH_URL = 'https://container.googleapis.com/auth/'
api_name = 'google'
connectionCls

alias of GKEConnection

get_server_config(ex_zone=None)[source]

Return configuration info about the Container Engine service.

Parameters:ex_zone (str or GCEZone or NodeLocation or None) – Optional zone name or None
list_clusters(ex_zone=None)[source]

Return a list of cluster information in the current zone or all zones.

Parameters:ex_zone (str or GCEZone or NodeLocation or None) – Optional zone name or None
name = 'Google Container Engine'
supports_clusters = True
type = 'GKE'
website = 'https://container.googleapis.com'
class libcloud.container.drivers.gke.GKEResponse(response, connection)[source]

Bases: libcloud.common.google.GoogleResponse

Parameters:
  • response (httplib.HTTPResponse) – HTTP response object. (optional)
  • connection (Connection) – Parent connection object.

libcloud.container.drivers.joyent module

class libcloud.container.drivers.joyent.JoyentContainerDriver(key=None, secret=None, secure=False, host='localhost', port=2376, key_file=None, cert_file=None)[source]

Bases: libcloud.container.drivers.docker.DockerContainerDriver

Joyent Triton container driver class.

>>> from libcloud.container.providers import get_driver
>>> driver = get_driver('joyent')
>>> conn = driver(host='https://us-east-1.docker.joyent.com',
    port=2376, key_file='key.pem', cert_file='cert.pem')
connectionCls

alias of libcloud.container.drivers.docker.DockerConnection

name = 'Joyent Triton'
supports_clusters = False
type = 'joyent'
website = 'http://joyent.com'

libcloud.container.drivers.kubernetes module

class libcloud.container.drivers.kubernetes.KubernetesContainerDriver(key=None, secret=None, secure=False, host='localhost', port=4243, key_file=None, cert_file=None, ca_cert=None, ex_token_bearer_auth=False)[source]

Bases: libcloud.common.kubernetes.KubernetesDriverMixin, libcloud.container.base.ContainerDriver

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.
  • key_file (str) – Path to the key file used to authenticate (when using key file auth).
  • cert_file (str) – Path to the cert file used to authenticate (when using key file auth).
  • ex_token_bearer_auth (bool) – True to use token bearer auth.
Returns:

None

connectionCls

alias of libcloud.common.kubernetes.KubernetesBasicAuthConnection

create_cluster(name, location=None)[source]

Create a container cluster (a namespace)

Parameters:
  • name (str) – The name of the cluster
  • location (ClusterLocation) – The location to create the cluster in
Return type:

ContainerCluster

deploy_container(name, image, cluster=None, parameters=None, start=True)[source]

Deploy an installed container image. In kubernetes this deploys a single container Pod. https://cloud.google.com/container-engine/docs/pods/single-container

Parameters:
  • name (str) – The name of the new container
  • image (ContainerImage) – The container image to deploy
  • cluster (ContainerCluster) – The cluster to deploy to, None is default
  • parameters (str) – Container Image parameters
  • start (bool) – Start the container on deployment
Return type:

Container

destroy_cluster(cluster)[source]

Delete a cluster (namespace)

Returns:True if the destroy was successful, otherwise False.
Return type:bool
destroy_container(container)[source]

Destroy a deployed container. Because the containers are single container pods, this will delete the pod.

Parameters:container (Container) – The container to destroy
Return type:bool
ex_destroy_pod(namespace, pod_name)[source]

Delete a pod and the containers within it.

ex_list_pods()[source]

List available Pods

Return type:list of KubernetesPod
get_cluster(id)[source]

Get a cluster by ID

Parameters:id (str) – The ID of the cluster to get
Return type:libcloud.container.base.ContainerCluster
get_container(id)[source]

Get a container by ID

Parameters:id (str) – The ID of the container to get
Return type:libcloud.container.base.Container
list_clusters()[source]

Get a list of namespaces that pods can be deployed into

Parameters:location (libcloud.container.base.ClusterLocation) – The location to search in
Return type:list of libcloud.container.base.ContainerCluster
list_containers(image=None, all=True)[source]

List the deployed container images

Parameters:
Return type:

list of libcloud.container.base.Container

name = 'Kubernetes'
supports_clusters = True
type = 'kubernetes'
website = 'http://kubernetes.io'

libcloud.container.drivers.lxd module

exception libcloud.container.drivers.lxd.LXDAPIException(message='Unknown Error Occurred', response_dict=None, error_type='')[source]

Bases: Exception

Basic exception to be thrown when LXD API returns with some kind of error

class libcloud.container.drivers.lxd.LXDConnection(user_id, key, secure=True, host=None, port=None, url=None, timeout=None, proxy_url=None, backoff=None, retry_delay=None)[source]

Bases: libcloud.common.base.ConnectionUserAndKey

add_default_headers(headers)[source]

Add parameters that are necessary for every request If user and password are specified, include a base http auth header

responseCls

alias of LXDResponse

timeout = 60
class libcloud.container.drivers.lxd.LXDContainerDriver(key='', secret='', secure=False, host='localhost', port=8443, key_file=None, cert_file=None, ca_cert=None, certificate_validator=<function check_certificates>)[source]

Bases: libcloud.container.base.ContainerDriver

Driver for LXD REST API of LXC containers https://lxd.readthedocs.io/en/stable-2.0/rest-api/ https://github.com/lxc/lxd/blob/master/doc/rest-api.md

attach_volume(container_id, volume_id, pool_id, name, path, ex_timeout=30)[source]

Attach the volume with id volume_id to the container with id container_id

build_operation_websocket_url(uuid, w_secret)[source]
connectionCls

alias of LXDConnection

create_volume(pool_id, definition, **kwargs)[source]

Create a new storage volume on a given storage pool Operation: sync or async (when copying an existing volume) :return: A StorageVolume representing a storage volume

default_architecture = ''
default_ephemeral = False
default_profiles = 'default'
default_time_out = 30
deploy_container(name, image, cluster=None, parameters=None, start=True, ex_architecture='', ex_profiles=None, ex_ephemeral=False, ex_config=None, ex_devices=None, ex_instance_type=None, ex_timeout=30)[source]

Create a new container Authentication: trusted Operation: async

Parameters:name – The name of the new container.

64 chars max, ASCII, no slash, no colon and no comma :type name: str

Parameters:
  • image (ContainerImage) – The container image to deploy. Currently not used
  • cluster (ContainerCluster) – The cluster to deploy to, None is default
  • parameters – Container Image parameters.

This parameter should represent the the source dictioanry expected by the LXD API call. For more information how this parameter should be structured see https://github.com/lxc/lxd/blob/master/doc/rest-api.md :type parameters: str

Parameters:
  • start (bool) – Start the container on deployment. True is the default
  • ex_architecture (str) – string e.g. x86_64
  • ex_profiles (list) – List of profiles
  • ex_ephemeral (bool) – Whether to destroy the container on shutdown
  • ex_config (dict) – Config override e.g. {“limits.cpu”: “2”}
  • ex_devices (dict) – optional list of devices the container should have
  • ex_instance_type – An optional instance type

to use as basis for limits e.g. “c2.micro” :type ex_instance_type: str

Parameters:ex_timeout (int) – Timeout
Return type:libcloud.container.base.Container
destroy_container(container, ex_timeout=30)[source]

Destroy a deployed container. Raises and exception

if the container is running

Parameters:
  • container (Container) – The container to destroy
  • ex_timeout – Time to wait for the operation to complete

:type ex_timeout int

Return type::class:`libcloud.container.base.Container
ex_create_network(name, **kwargs)[source]

Create a new network with the given name and and the specified configuration

Authentication: trusted Operation: sync

Parameters:name (str) – The name of the new network
ex_create_storage_pool(definition)[source]

Create a storage_pool from definition.

Implements POST /1.0/storage-pools

The definition parameter defines what the storage pool will be. An example config for the zfs driver is:

{
“config”: {
“size”: “10GB”

}, “driver”: “zfs”, “name”: “pool1”

}

Note that all fields in the definition parameter are strings. Note that size has to be at least 64MB in order to create the pool

For further details on the storage pool types see: https://lxd.readthedocs.io/en/latest/storage/

The function returns the a StoragePool instance, if it is successfully created, otherwise an LXDAPIException is raised.

Parameters:definition (dict) – the fields to pass to the LXD API endpoint
Returns:a storage pool if successful,

raises NotFound if not found :rtype: StoragePool

Raises:LXDAPIExtensionNotAvailable

if the ‘storage’ api extension is missing. :raises: LXDAPIException if the storage pool couldn’t be created.

ex_delete_network(name)[source]

Delete the network with the given name Authentication: trusted Operation: sync

Parameters:name (str) – The network name to delete
Returns:True is successfully deleted the network
ex_delete_storage_pool(id)[source]

Delete the storage pool.

Implements DELETE /1.0/storage-pools/<self.name>

Deleting a storage pool may fail if it is being used. See the LXD documentation for further details.

Raises:LXDAPIException if the storage pool can’t be deleted.
ex_delete_storage_pool_volume(pool_id, type, name)[source]

Delete a storage volume of a given type on a given storage pool

Parameters:pool_id

:type str

Parameters:type

:type str

Parameters:name

:type str

Returns:
ex_execute_cmd_on_container(cont_id, command, **config)[source]

Description: run a remote command Operation: async

Return: Depends on the the configuration

if wait-for-websocket=true and interactive=false returns a LXDContainerExecuteResult with:

uuid=uuid, secret_0=fds[“0”], secret_1=fds[“1”], secret_2=fds[“2”], control=fds[“control”], output={}, result=None

if wait-for-websocket=true and interactive=true returns a LXDContainerExecuteResult with:

uuid=uuid, secret_0=fds[“0”], secret_1=None, secret_2=None, control=fds[“control”], output={}, result=None

if interactive=false and record-output=true returns a LXDContainerExecuteResult with:

uuid=uuid, secret_0=None, secret_1=None, secret_2=None, control=None, output=output, result=result

if none of the above it assumes that the command has been executed and returns LXDContainerExecuteResult with:

uuid=uuid, secret_0=None, secret_1=None, secret_2=None, control=None, output=None, result=result

in all the above uuid is the operation id

Parameters:cont_id – The container name to run the commands

“:type cont_id: str

Parameters:command – a list of strings indicating the commands

and their arguments e.g: [“/bin/bash ls -l”] :type command list

Parameters:config

Dict with extra arguments.

For example:

width: Initial width of the terminal default 80 height: Initial height of the terminal default 25 user: User to run the command as default 1000 group: Group to run the command as default 1000 cwd: Current working directory default /tmp

wait-for-websocket: Whether to wait for a connection before starting the process. Default False

record-output: Whether to store stdout and stderr (only valid with wait-for-websocket=false) (requires API extension container_exec_recording). Default False

interactive: Whether to allocate a pts device instead of PIPEs. Default true

:type config dict

:rtype LXDContainerExecuteResult

ex_freeze_container(container, ex_timeout=30)[source]

Set the given container into a freeze state

Parameters:
  • container (Container) – The container to restart
  • ex_timeout (int) – Time to wait for the operation to complete
Rtype :class:

`libcloud.container.base.Container

ex_get_api_endpoints()[source]

Description: List of supported APIs Authentication: guest Operation: sync Return: list of supported API endpoint URLs

ex_get_image(fingerprint)[source]

Returns a container image from the given image fingerprint

Parameters:fingerprint (str) – image fingerprint
Return type:ContainerImage
ex_get_network(name)[source]

Returns the LXD network with the given name. Implements GET /1.0/networks/<name>

Authentication: trusted Operation: sync

Parameters:name (str) – The name of the network to return
Return type:LXDNetwork
ex_get_server_configuration()[source]

Description: Server configuration and environment information Authentication: guest, untrusted or trusted Operation: sync Return: Dict representing server state

The returned configuration depends on whether the connection is trusted or not :rtype: :class: .LXDServerInfo

ex_get_storage_pool(id)[source]

Returns information about a storage pool :param id: the name of the storage pool :rtype: :class: StoragePool

ex_get_storage_pool_volume(pool_id, type, name)[source]

Description: information about a storage volume of a given type on a storage pool Introduced: with API extension storage Authentication: trusted Operation: sync Return: A StorageVolume representing a storage volume

ex_get_volume_by_name(name, vol_type='custom')[source]

Returns a storage volume that has the given name. The function will loop over all storage-polls available and will pick the first volume from the first storage poll that matches the given name. Thus this function can be quite expensive

Parameters:
  • name (str) – The name of the volume to look for
  • vol_type (str) – The type of the volume default is custom
Returns:

A StorageVolume representing a storage volume

ex_has_image(alias)[source]

Helper function. Returns true and the image fingerprint if the image with the given alias exists on the host.

Parameters:alias (str) – the image alias
Return type:tupple :: (boolean, str)
ex_list_networks()[source]

Returns a list of networks. Implements GET /1.0/networks Authentication: trusted Operation: sync

Return type:list of LXDNetwork objects
ex_list_storage_pool_volumes(pool_id, detailed=True)[source]

Description: list of storage volumes associated with the given storage pool

Parameters:
  • pool_id – the id of the storage pool to query
  • detailed – boolean flag.
If True extra API calls are made to fill in the missing details
of the storage volumes

Authentication: trusted Operation: sync Return: list of storage volumes that currently exist on a given storage pool

Return type:A list of :class: StorageVolume
ex_list_storage_pools(detailed=True)[source]

Returns a list of storage pools defined currently defined on the host

Description: list of storage pools Authentication: trusted Operation: sync

“:rtype: list of StoragePool items

ex_replace_storage_volume_config(pool_id, type, name, definition)[source]

Replace the storage volume information :param pool_id: :param type: :param name: :param definition

ex_unfreeze_container(container, ex_timeout=30)[source]

Set the given container into unfreeze state

Parameters:
  • container (Container) – The container to restart
  • ex_timeout (int) – Time to wait for the operation to complete
Rtype :class:

`libcloud.container.base.Container

get_container(id, ex_get_ip_addr=True)[source]

Get a container by ID

Parameters:
  • id (str) – The ID of the container to get
  • ex_get_ip_addr – Indicates whether ip addresses

should also be included. This requires an extra GET request :type ex_get_ip_addr: boolean`

Return type:libcloud.container.base.Container
install_image(path, ex_timeout=30, **ex_img_data)[source]

Install a container image from a remote path. Not that the path currently is not used. Image data should be provided under the key ‘ex_img_data’. Creating an image in LXD is an asynchronous operation

Parameters:
  • path (str) – Path to the container image
  • ex_timeout (int) – Time to wait before signaling timeout
  • ex_img_data (dict) – Dictionary describing the image data
Return type:

ContainerImage

list_containers(image=None, cluster=None, ex_detailed=True)[source]

List the deployed container images

Parameters:
  • image (ContainerImage) – Filter to containers with a certain image
  • cluster (ContainerCluster) – Filter to containers in a cluster
  • ex_detailed – Flag indicating whether detail info

of the containers is required. This will cause a GET request for every container present in the host. Default is True :type ex_detailed: bool

Return type:list of :class:`libcloud.container.base.Container
list_images()[source]

List of URLs for images the server is publishing

Return type:list of ContainerImage
name = 'LXD'
restart_container(container, ex_timeout=30, ex_force=True, ex_stateful=True)[source]

Restart a deployed container

Parameters:
  • container (Container) – The container to restart
  • ex_timeout (int) – Time to wait for the operation to complete
  • ex_force (boolean) –
  • ex_stateful (boolean) –
Return type:

:class:`libcloud.container.base.Container

start_container(container, ex_timeout=30, ex_force=True, ex_stateful=True)[source]

Start a container

Parameters:
  • container (libcloud.container.base.Container) – The container to start
  • ex_timeout (int) – Time to wait for the operation to complete
  • ex_force (boolean) –
  • ex_stateful (boolean) –
Return type:

libcloud.container.base.Container

stop_container(container, ex_timeout=30, ex_force=True, ex_stateful=True)[source]

Stop the given container

Parameters:
  • container (libcloud.container.base.Container) – The container to be stopped
  • ex_timeout (int) – Time to wait for the operation to complete
  • ex_force (boolean) –
  • ex_stateful (boolean) –
Return type:

:class:`libcloud.container.base.Container

supports_clusters = False
type = 'lxd'
version = '1.0'
website = 'https://linuxcontainers.org/'
class libcloud.container.drivers.lxd.LXDContainerExecuteResult(uuid, secret_0, secret_1, secret_2, control, output, result)

Bases: tuple

Create new instance of LXDContainerExecuteResult(uuid, secret_0, secret_1, secret_2, control, output, result)

control

Alias for field number 4

output

Alias for field number 5

result

Alias for field number 6

secret_0

Alias for field number 1

secret_1

Alias for field number 2

secret_2

Alias for field number 3

uuid

Alias for field number 0

class libcloud.container.drivers.lxd.LXDNetwork[source]

Bases: object

Utility class representing an LXD network

classmethod build_from_response(metadata)[source]
class libcloud.container.drivers.lxd.LXDResponse(response, connection)[source]

Bases: libcloud.common.base.JsonResponse

Parameters:
  • response (httplib.HTTPResponse) – HTTP response object. (optional)
  • connection (Connection) – Parent connection object.
parse_body()[source]

Parse response body.

Override in a provider’s subclass.

Returns:Parsed body.
Return type:str
parse_error()[source]

Parse the error messages.

Override in a provider’s subclass.

Returns:Parsed error.
Return type:str
success()[source]

Determine if our request was successful.

The meaning of this can be arbitrary; did we receive OK status? Did the node get created? Were we authenticated?

Return type:bool
Returns:True or False
valid_response_codes = [<HTTPStatus.OK: 200>, <HTTPStatus.ACCEPTED: 202>, <HTTPStatus.CREATED: 201>, <HTTPStatus.NO_CONTENT: 204>]
class libcloud.container.drivers.lxd.LXDServerInfo[source]

Bases: object

Wraps the response form /1.0

classmethod build_from_response(metadata)[source]
class libcloud.container.drivers.lxd.LXDStoragePool(name, driver, used_by, config, managed)[source]

Bases: object

Utility class representing an LXD storage pool https://lxd.readthedocs.io/en/latest/storage/

class libcloud.container.drivers.lxd.LXDtlsConnection(key, secret, secure=True, host='localhost', port=8443, ca_cert='', key_file=None, cert_file=None, certificate_validator=None, **kwargs)[source]

Bases: libcloud.common.base.KeyCertificateConnection

add_default_headers(headers)[source]

Adds default headers (such as Authorization, X-Foo-Bar) to the passed headers

Should return a dictionary.

responseCls

alias of LXDResponse

libcloud.container.drivers.lxd.assert_response(response_dict, status_code)[source]

Basic checks that the response is of the type the client is expecting

libcloud.container.drivers.lxd.check_certificates(key_file, cert_file, **kwargs)[source]

Basic checks for the provided certificates in LXDtlsConnection

libcloud.container.drivers.lxd.strip_http_prefix(host)[source]

libcloud.container.drivers.rancher module

class libcloud.container.drivers.rancher.RancherConnection(user_id, key, secure=True, host=None, port=None, url=None, timeout=None, proxy_url=None, backoff=None, retry_delay=None)[source]

Bases: libcloud.common.base.ConnectionUserAndKey

add_default_headers(headers)[source]

Add parameters that are necessary for every request If user and password are specified, include a base http auth header

responseCls

alias of RancherResponse

timeout = 30
class libcloud.container.drivers.rancher.RancherContainerDriver(key, secret, secure=True, host='localhost', port=443)[source]

Bases: libcloud.container.base.ContainerDriver

Driver for Rancher by Rancher Labs.

This driver is capable of interacting with the Version 1 API of Rancher. It currently does NOT support the Version 2 API.

Example:

>>> from libcloud.container.providers import get_driver
>>> from libcloud.container.types import Provider
>>> driver = get_driver(Provider.RANCHER)
>>> connection = driver(key="ACCESS_KEY_HERE",
secret="SECRET_KEY_HERE", host="172.30.0.100", port=8080)
>>> image = ContainerImage("hastebin", "hastebin", "rlister/hastebin",
"latest", driver=None)
>>> newcontainer = connection.deploy_container("myawesomepastebin",
image, environment={"STORAGE_TYPE": "file"})
Variables:baseuri – The URL base path to the API.

Creates a new Rancher Container driver.

Parameters:
  • key (str) – API key or username to used (required)
  • secret (str) – Secret password to be used (required)
  • secure (bool) – Whether to use HTTPS or HTTP.
  • host (str) – Override hostname used for connections. This can also be a full URL string, including scheme, port, and base path.
  • port (int) – Override port used for connections.
Returns:

A newly initialized driver instance.

connectionCls

alias of RancherConnection

deploy_container(name, image, parameters=None, start=True, **config)[source]

Deploy a new container.

http://docs.rancher.com/rancher/v1.2/en/api/api-resources/container/#create

The following is the Image format used for ``ContainerImage``

For a ``imageuuid``:

  • docker:<hostname>:<port>/<namespace>/<imagename>:<version>

The following applies:

  • id = <imagename>
  • name = <imagename>
  • path = <hostname>:<port>/<namespace>/<imagename>
  • version = <version>

Any extra configuration can also be passed i.e. “environment”

Parameters:
  • name (str) – The desired name of the container. (required)
  • image (libcloud.container.base.ContainerImage) – The Image object to deploy. (required)
  • parameters (str) – Container Image parameters (unused)
  • start (bool) – Whether to start the container on creation(startOnCreate)
Return type:

Container

destroy_container(container)[source]

Remove a container

Parameters:container (libcloud.container.base.Container) – The container to be destroyed
Returns:True if the destroy was successful, False otherwise.
Return type:bool
ex_activate_service(service_id)[source]

Activate a service.

http://docs.rancher.com/rancher/v1.2/en/api/api-resources/service/#activate

Parameters:service_id (str) – The service to activate services for.
Returns:True if activate was successful, False otherwise.
Return type:bool
ex_activate_stack(env_id)[source]

Activate Services for a stack.

http://docs.rancher.com/rancher/v1.2/en/api/api-resources/environment/#activateservices

Parameters:env_id (str) – The stack to activate services for.
Returns:True if activate was successful, False otherwise.
Return type:bool
ex_deactivate_service(service_id)[source]

Deactivate a service.

http://docs.rancher.com/rancher/v1.2/en/api/api-resources/service/#deactivate

Parameters:service_id (str) – The service to deactivate services for.
Returns:True if deactivate was successful, False otherwise.
Return type:bool
ex_deactivate_stack(env_id)[source]

Deactivate Services for a stack.

http://docs.rancher.com/rancher/v1.2/en/api/api-resources/environment/#deactivateservices

Parameters:env_id (str) – The stack to deactivate services for.
Returns:True if deactivate was successful, False otherwise.
Return type:bool
ex_deploy_service(name, image, environment_id, start=True, assign_service_ip_address=None, service_description=None, external_id=None, metadata=None, retain_ip=None, scale=None, scale_policy=None, secondary_launch_configs=None, selector_container=None, selector_link=None, vip=None, **launch_conf)[source]

Deploy a Rancher Service under a stack.

http://docs.rancher.com/rancher/v1.2/en/api/api-resources/service/#create

Any further configuration passed applies to the ``launchConfig``

Parameters:
  • name (str) – The desired name of the service. (required)
  • image (libcloud.container.base.ContainerImage) – The Image object to deploy. (required)
  • environment_id (str) – The stack ID this service is tied to. (required)
  • start (bool) – Whether to start the service on creation.
  • assign_service_ip_address (bool) – The IP address to assign the service.
  • service_description (str) – The service description.
  • external_id (str) – The externalId for this service.
  • metadata (dict) – K/V Metadata for this service.
  • retain_ip (bool) – Whether this service should retain its IP.
  • scale (int) – The scale of containers in this service.
  • scale_policy (dict) – The scaling policy for this service.
  • secondary_launch_configs (list) – Secondary container launch configs.
  • selector_container (str) – The selectorContainer for this service.
  • selector_link (type) – The selectorLink for this service.
  • vip (str) – The VIP to assign to this service.
Returns:

The newly created service.

Return type:

dict

ex_deploy_stack(name, description=None, docker_compose=None, environment=None, external_id=None, rancher_compose=None, start=True)[source]

Deploy a new stack.

http://docs.rancher.com/rancher/v1.2/en/api/api-resources/environment/#create

Parameters:
  • name (str) – The desired name of the stack. (required)
  • description (str) – A desired description for the stack.
  • docker_compose (str) – The Docker Compose configuration to use.
  • environment (dict) – Environment K/V specific to this stack.
  • external_id (str) – The externalId of the stack.
  • rancher_compose (str) – The Rancher Compose configuration for this env.
  • start (bool) – Whether to start this stack on creation.
Returns:

The newly created stack.

Return type:

dict

ex_destroy_service(service_id)[source]

Destroy a service by ID

http://docs.rancher.com/rancher/v1.2/en/api/api-resources/service/#delete

Parameters:service_id (str) – The service to be destroyed.
Returns:True if destroy was successful, False otherwise.
Return type:bool
ex_destroy_stack(env_id)[source]

Destroy a stack by ID

http://docs.rancher.com/rancher/v1.2/en/api/api-resources/environment/#delete

Parameters:env_id (str) – The stack to be destroyed.
Returns:True if destroy was successful, False otherwise.
Return type:bool
ex_get_service(service_id)[source]

Get a service by ID

Parameters:service_id (str) – The service_id to be obtained.
Return type:dict
ex_get_stack(env_id)[source]

Get a stack by ID

Parameters:env_id (str) – The stack to be obtained.
Return type:dict
ex_list_services()[source]

List all Rancher Services

http://docs.rancher.com/rancher/v1.2/en/api/api-resources/service/

Return type:list of dict
ex_list_stacks()[source]

List all Rancher Stacks

http://docs.rancher.com/rancher/v1.2/en/api/api-resources/environment/

Return type:list of dict
ex_search_containers(search_params)[source]

Search for containers matching certain filters

i.e. { "imageUuid": "docker:mysql", "state": "running"}

Parameters:search_params (dict) – A collection of search parameters to use.
Return type:list
ex_search_services(search_params)[source]

Search for services matching certain filters

i.e. { "name": "awesomesause", "environmentId": "1e2"}

Parameters:search_params (dict) – A collection of search parameters to use.
Return type:list
ex_search_stacks(search_params)[source]

Search for stacks matching certain filters

i.e. { "name": "awesomestack"}

Parameters:search_params (dict) – A collection of search parameters to use.
Return type:list
get_container(con_id)[source]

Get a container by ID

Parameters:con_id (str) – The ID of the container to get
Return type:libcloud.container.base.Container
list_containers()[source]

List the deployed containers.

http://docs.rancher.com/rancher/v1.2/en/api/api-resources/container/

Return type:list of libcloud.container.base.Container
name = 'Rancher'
start_container(container)[source]

Start a container

Parameters:container (libcloud.container.base.Container) – The container to be started
Returns:The container refreshed with current data
Return type:libcloud.container.base.Container
stop_container(container)[source]

Stop a container

Parameters:container (libcloud.container.base.Container) – The container to be stopped
Returns:The container refreshed with current data
Return type:libcloud.container.base.Container
supports_clusters = False
type = 'rancher'
version = '1'
website = 'http://rancher.com'
exception libcloud.container.drivers.rancher.RancherException(code, message)[source]

Bases: Exception

class libcloud.container.drivers.rancher.RancherResponse(response, connection)[source]

Bases: libcloud.common.base.JsonResponse

Parameters:
  • response (httplib.HTTPResponse) – HTTP response object. (optional)
  • connection (Connection) – Parent connection object.
parse_error()[source]

Parse the error messages.

Override in a provider’s subclass.

Returns:Parsed error.
Return type:str
success()[source]

Determine if our request was successful.

The meaning of this can be arbitrary; did we receive OK status? Did the node get created? Were we authenticated?

Return type:bool
Returns:True or False

Module contents