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=None, secret=None, 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:
exceptions.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.
-
valid_response_codes
= [200, 202, 201, 204]¶
- response (
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.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
DockerConnection
-
name
= 'Joyent Triton'¶
-
supports_clusters
= False¶
-
type
= 'joyent'¶
-
website
= 'http://joyent.com'¶
-
libcloud.container.drivers.kubernetes module¶
-
class
libcloud.container.drivers.kubernetes.
KubernetesConnection
(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
KubernetesResponse
-
timeout
= 60¶
-
-
class
libcloud.container.drivers.kubernetes.
KubernetesContainerDriver
(key=None, secret=None, secure=False, host='localhost', port=4243)[source]¶ Bases:
libcloud.container.base.ContainerDriver
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.
Returns: None
-
connectionCls
¶ alias of
KubernetesConnection
-
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: - name (
-
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: - name (
-
destroy_cluster
(cluster)[source]¶ Delete a cluster (namespace)
Returns: True
if the destroy was successful, otherwiseFalse
.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 destroyReturn type: bool
-
ex_list_pods
()[source]¶ List available Pods
Return type: list
ofKubernetesPod
-
get_cluster
(id)[source]¶ Get a cluster by ID
Parameters: id ( str
) – The ID of the cluster to getReturn type: libcloud.container.base.ContainerCluster
-
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 namespaces that pods can be deployed into
Parameters: location ( libcloud.container.base.ClusterLocation
) – The location to search inReturn type: list
oflibcloud.container.base.ContainerCluster
-
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 (
-
name
= 'Kubernetes'¶
-
supports_clusters
= True¶
-
type
= 'kubernetes'¶
-
website
= 'http://kubernetes.io'¶
- key (
-
exception
libcloud.container.drivers.kubernetes.
KubernetesException
(code, message)[source]¶ Bases:
exceptions.Exception
-
class
libcloud.container.drivers.kubernetes.
KubernetesPod
(name, containers, namespace)[source]¶ Bases:
object
A Kubernetes pod
-
class
libcloud.container.drivers.kubernetes.
KubernetesResponse
(response, connection)[source]¶ Bases:
libcloud.common.base.JsonResponse
Parameters: - response (
httplib.HTTPResponse
) – HTTP response object. (optional) - connection (
Connection
) – Parent connection object.
-
valid_response_codes
= [200, 202, 201, 204]¶
- response (