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

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

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

Whether the driver supports containers being deployed into clusters

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