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
- name (
-
destroy_container
(container)[source]¶ Remove a container
Parameters: container ( libcloud.container.base.Container
) – The container to be destroyedReturns: 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 removeReturn 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: - container (
libcloud.container.base.Container
) – The container to list logs for - stream (
bool
) – Stream the output
Return type: bool
- container (
-
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: - container (
libcloud.container.base.Container
) – The container to be renamed - name (
str
) – The new name
Return type: - 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
oflibcloud.container.base.ContainerImage
-
get_container
(id)[source]¶ Get a container by ID
Parameters: id ( str
) – The ID of the container to getReturn type: libcloud.container.base.Container
-
install_image
(path)[source]¶ Install a container image from a remote path.
Parameters: path ( str
) – Path to the container imageReturn type: libcloud.container.base.ContainerImage
-
list_containers
(image=None, all=True)[source]¶ List the deployed container images
Parameters: - image (
libcloud.container.base.ContainerImage
) – Filter to containers with a certain image - all (
bool
) – Show all container (including stopped ones)
Return type: - image (
-
list_images
()[source]¶ List the installed container images
Return type: list
oflibcloud.container.base.ContainerImage
-
name
= 'Docker'¶
-
restart_container
(container)[source]¶ Restart a container
Parameters: container ( libcloud.container.base.Container
) – The container to be stoppedReturns: 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 startedReturns: 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 stoppedReturns: The container refreshed with current data Return type: libcloud.container.base.Container
-
supports_clusters
= False¶
-
type
= 'docker'¶
-
version
= '1.24'¶
-
website
= 'http://docker.io'¶
- key (
-
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
orFalse
-
valid_response_codes
= [<HTTPStatus.OK: 200>, <HTTPStatus.ACCEPTED: 202>, <HTTPStatus.CREATED: 201>, <HTTPStatus.NO_CONTENT: 204>]¶
- response (
-
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.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'¶
- api_key (
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: - name (
str
) – The name of the cluster - location (
libcloud.container.base.ClusterLocation
) – The location to create the cluster in
Return type: - name (
-
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: - name (
str
) – The name of the new container - image (
libcloud.container.base.ContainerImage
) – The container image to deploy - cluster (
libcloud.container.base.ContainerCluster
) – The cluster to deploy to, None is default - parameters (
str
) – Container Image parameters - start (
bool
) – Start the container on deployment
Return type: - name (
-
destroy_cluster
(cluster)[source]¶ Delete a cluster
Returns: True
if the destroy was successful, otherwiseFalse
.Return type: bool
-
destroy_container
(container)[source]¶ Destroy a deployed container
Parameters: container ( libcloud.container.base.Container
) – The container to destroyReturn 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- name (
-
ex_describe_service
(service_arn)[source]¶ Get the details of a service
Parameters: - cluster (
libcloud.container.base.ContainerCluster
) – The hosting cluster - service_arn (
str
) – The service ARN to describe
Returns: The service object
Return type: object
- cluster (
-
ex_destroy_service
(service_arn)[source]¶ Deletes a service
Parameters: - cluster (
libcloud.container.base.ContainerCluster
) – The target cluster - service_arn (
str
) – The service ARN to destroy
- cluster (
-
ex_get_registry_client
(repository_name)[source]¶ Get a client for an ECR repository
Parameters: repository_name ( str
) – The unique name of the repositoryReturns: 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 repositoryReturns: 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 repositoryReturns: 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
ofstr
) – The list of ARNsReturn type: list
oflibcloud.container.base.Container
-
ex_list_service_arns
(cluster=None)[source]¶ List the services
Parameters: cluster ( libcloud.container.base.ContainerCluster
) – The cluster hosting the servicesReturn type: list
ofstr
-
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: - task_arn (
-
get_container
(id)[source]¶ Get a container by ID
Parameters: id ( str
) – The ID of the container to getReturn 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 inReturn type: list
oflibcloud.container.base.ContainerCluster
-
list_containers
(image=None, cluster=None)[source]¶ List the deployed container images
Parameters: - image (
libcloud.container.base.ContainerImage
) – Filter to containers with a certain image - cluster (
libcloud.container.base.ContainerCluster
) – Filter to containers in a cluster
Return type: - image (
-
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
oflibcloud.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 restartReturn type: libcloud.container.base.Container
-
start_container
(container, count=1)[source]¶ Start a deployed task
Parameters: - container (
libcloud.container.base.Container
) – The container to start - count (
int
) – Number of containers to start
Return type: - container (
-
status_map
= {'RUNNING': 'running'}¶
-
stop_container
(container)[source]¶ Stop a deployed container
Parameters: container ( libcloud.container.base.Container
) – The container to stopReturn 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: - modify request_path for GKE URI.
- Implement gce_params functionality described below.
- 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
- GKEConnection extends
-
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
orGCEZone
orNodeLocation
orNone
) – 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
orGCEZone
orNodeLocation
orNone
) – Optional zone name or None
-
name
= 'Google Container Engine'¶
-
supports_clusters
= True¶
-
type
= 'GKE'¶
-
website
= 'https://container.googleapis.com'¶
- user_id (
-
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.
- response (
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_namespace
(name: str) → libcloud.container.drivers.kubernetes.KubernetesNamespace[source]¶ Create a namespace
Parameters: name ( str
) – The name of the namespaceReturn type: KubernetesNamespace
-
delete_namespace
(namespace: libcloud.container.drivers.kubernetes.KubernetesNamespace) → bool[source]¶ Delete a namespace
Returns: True
if the destroy was successful, otherwiseFalse
.Return type: bool
-
deploy_container
(name: str, image: libcloud.container.base.ContainerImage, namespace: libcloud.container.drivers.kubernetes.KubernetesNamespace = None, parameters: Optional[str] = None, start: Optional[bool] = 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 - namespace (
KubernetesNamespace
) – The namespace to deploy to, None is default - parameters (
str
) – Container Image parameters(unused) - start (
bool
) – Start the container on deployment(unused)
Return type: - name (
-
destroy_container
(container: libcloud.container.base.Container) → bool[source]¶ Destroy a deployed container. Because the containers are single container pods, this will delete the pod.
Parameters: container ( Container
) – The container to destroyReturn type: bool
-
ex_destroy_node
(node_name: str) → bool[source]¶ Destroy a node.
Parameters: node_name ( str
) – Name of the node to destroyReturn type: bool
-
ex_destroy_pod
(namespace: str, pod_name: str) → bool[source]¶ Delete a pod and the containers within it.
Parameters: - namespace (
str
) – The pod’s namespace - pod_name (
str
) – Name of the pod to destroy
Return type: bool
- namespace (
-
ex_list_deployments
() → List[libcloud.container.drivers.kubernetes.KubernetesDeployment][source]¶ Get cluster deployments
Return type: list
ofKubernetesDeployment
-
ex_list_nodes
() → List[libcloud.compute.base.Node][source]¶ List available Nodes
Return type: list
ofNode
-
ex_list_nodes_metrics
() → List[Dict[str, Any]][source]¶ Get nodes metrics from Kubernetes Metrics Server
Return type: list
ofdict
-
ex_list_pods
(fetch_metrics: bool = False) → List[libcloud.container.drivers.kubernetes.KubernetesPod][source]¶ List available Pods
Parameters: fetch_metrics ( bool
) – Fetch metrics for podsReturn type: list
ofKubernetesPod
-
ex_list_pods_metrics
() → List[Dict[str, Any]][source]¶ Get pods metrics from Kubernetes Metrics Server
Return type: list
ofdict
-
get_container
(id: str) → libcloud.container.base.Container[source]¶ Get a container by ID
Parameters: id ( str
) – The ID of the container to getReturn type: libcloud.container.base.Container
-
get_namespace
(id: str) → libcloud.container.drivers.kubernetes.KubernetesNamespace[source]¶ Get a namespace by ID
Parameters: id ( str
) – The ID of the namespace to getReturn type: KubernetesNamespace
-
list_containers
(image=None, all=True) → List[libcloud.container.base.Container][source]¶ List the deployed container images
Parameters: - image (
libcloud.container.base.ContainerImage
) – Filter to containers with a certain image(unused) - all (
bool
) – Show all container (unused)
Return type: - image (
-
list_namespaces
() → List[libcloud.container.drivers.kubernetes.KubernetesNamespace][source]¶ Get a list of namespaces that pods can be deployed into
Return type: list
ofKubernetesNamespace
-
name
= 'Kubernetes'¶
-
supports_clusters
= True¶
-
type
= 'kubernetes'¶
-
website
= 'http://kubernetes.io'¶
- key (
-
libcloud.container.drivers.kubernetes.
to_n_bytes
(memory_str: str) → int[source]¶ Convert memory string to number of bytes (e.g. ‘1234Mi’-> 1293942784)
-
libcloud.container.drivers.kubernetes.
to_memory_str
(n_bytes: int, unit: Optional[str] = None) → str[source]¶ Convert number of bytes to k8s memory string (e.g. 1293942784 -> ‘1234Mi’)
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
-
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
dictionary 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
) – TimeoutReturn type: libcloud.container.base.Container
- image (
-
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 - 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=Noneif 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=Noneif 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=resultif 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=resultin 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
- 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 fingerprintReturn 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: 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 aliasReturn 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
- 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
- id (
-
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: - path (
-
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- image (
-
list_images
()[source]¶ List of URLs for images the server is publishing
Return type: list
ofContainerImage
-
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
- 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: - 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
- 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
-
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
orFalse
-
valid_response_codes
= [<HTTPStatus.OK: 200>, <HTTPStatus.ACCEPTED: 202>, <HTTPStatus.CREATED: 201>, <HTTPStatus.NO_CONTENT: 204>]¶
- response (
-
class
libcloud.container.drivers.lxd.
LXDServerInfo
[source]¶ Bases:
object
Wraps the response form /1.0
-
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.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 destroyedReturns: 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
- name (
-
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
- name (
-
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
ofdict
-
ex_list_stacks
()[source]¶ List all Rancher Stacks
http://docs.rancher.com/rancher/v1.2/en/api/api-resources/environment/
Return type: list
ofdict
-
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 getReturn 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
oflibcloud.container.base.Container
-
name
= 'Rancher'¶
-
start_container
(container)[source]¶ Start a container
Parameters: container ( libcloud.container.base.Container
) – The container to be startedReturns: 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 stoppedReturns: The container refreshed with current data Return type: libcloud.container.base.Container
-
supports_clusters
= False¶
-
type
= 'rancher'¶
-
version
= '1'¶
-
website
= 'http://rancher.com'¶
- key (
-
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.
- response (