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: ConnectionUserAndKey

Initialize user_id and key; set secure to an int based on passed value.

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: int | float | None = 60
class libcloud.container.drivers.docker.DockerContainerDriver(key='', secret='', secure=False, host='localhost', port=4243, key_file=None, cert_file=None)[source]

Bases: 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

Whether the driver supports containers being deployed into clusters

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: 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: KeyCertificateConnection

Initialize cert_file; set secure to an int based on passed value.

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 formatted datetime string.