Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Rancher Container Driver #876

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added docs/_static/images/provider_logos/rancher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
79 changes: 79 additions & 0 deletions docs/container/drivers/rancher.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
Rancher Container Service Documentation
=======================================

Rancher is a container orchestration platform.

.. figure:: /_static/images/provider_logos/rancher.png
:align: center
:width: 300
:target: http://rancher.com/

This driver supports the main top-level interactions for handling containers,
services, and stacks in a Rancher Environment.

Here are some notes around this driver:

- Does not support user based API credentials, only Environment API
credentials (one env, no cluster support)
- Does not support images other than docker formatted images. ``docker:``
prefix is forced!
- Images follow a standardized format. See deploy_container docstring!
- ``launchConfig`` options for ``ex_deploy_service`` can all be defined at the
top level then get slipstreamed appropriately.
- Passing your own cert/key of any sort for SSL/TLS is not presently supported.
- For SSL/TLS (https) support with newer versions of OpenSSL, the following
is necessary (in your own code):

.. code::
import ssl
import libcloud.security
libcloud.security.SSL_VERSION = ssl.PROTOCOL_TLSv1_2

To enable API access, obtain an Environment API Key from your Rancher Server
for the specific environment you want to control.

Instantiating the driver
------------------------

.. literalinclude:: /examples/container/rancher/instantiate_driver.py
:language: python

Deploying a container
---------------------

.. literalinclude:: /examples/container/rancher/deploy_container.py
:language: python

Deploying a service
-------------------

.. literalinclude:: /examples/container/rancher/deploy_service.py
:language: python

Deploying a stack
-----------------

.. literalinclude:: /examples/container/rancher/deploy_stack.py
:language: python

Searching for a container
-------------------------

.. literalinclude:: /examples/container/rancher/search_containers.py
:language: python

API Docs
--------

.. autoclass:: libcloud.container.drivers.rancher.RancherContainerDriver
:members:
:inherited-members:

Contributors
------------

For the first version of this driver, Mario Loria of Arroyo Networks wrote most
of the code. He received help from Anthony Shaw, a core libcloud contributor
and Vincent Fiduccia, software architect at Rancher Labs.

.. _`Rancher`: https://rancher.com/
13 changes: 13 additions & 0 deletions docs/examples/container/rancher/deploy_container.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from libcloud.container.types import Provider
from libcloud.container.providers import get_driver

driver = get_driver(Provider.RANCHER)

connection = driver("MYRANCHERACCESSKEY", "MYRANCHERSECRETKEY",
host="172.30.0.100", port=8080, secure=False)

image = ContainerImage("hastebin", "hastebin", "rlister/hastebin", "latest",
driver=None)

new_container = connection.deploy_container(name="awesomecontainer",
image=image, networkMode="managed")
17 changes: 17 additions & 0 deletions docs/examples/container/rancher/deploy_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from libcloud.container.types import Provider
from libcloud.container.providers import get_driver

driver = get_driver(Provider.RANCHER)

connection = driver("MYRANCHERACCESSKEY", "MYRANCHERSECRETKEY",
host="17.23.66.4", port=443)

image = ContainerImage("hastebin", "hastebin", "rlister/hastebin", "latest",
driver=None)

new_service = connection.ex_deploy_service(name="excitingservice", image=image,
environmentid="1e2",
environment={
"STORAGE_TYPE": "file"
})

13 changes: 13 additions & 0 deletions docs/examples/container/rancher/deploy_stack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from libcloud.container.types import Provider
from libcloud.container.providers import get_driver

driver = get_driver(Provider.RANCHER)

connection = driver("MYRANCHERACCESSKEY", "MYRANCHERSECRETKEY",
host="172.30.0.100", port=8080, secure=False)

new_stack = connection.ex_deploy_stack(name="GhostBlog",
description="Contains services for the"
"ghost blog.")

id_of_new_stack = new_stack['id']
9 changes: 9 additions & 0 deletions docs/examples/container/rancher/instantiate_driver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from libcloud.container.types import Provider
from libcloud.container.providers import get_driver

driver = get_driver(Provider.RANCHER)

connection = driver("MYRANCHERACCESSKEY", "MYRANCHERSECRETKEY",
host="172.30.0.100", port=8080, secure=False)

connection.list_containers()
12 changes: 12 additions & 0 deletions docs/examples/container/rancher/search_containers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from libcloud.container.types import Provider
from libcloud.container.providers import get_driver

driver = get_driver(Provider.RANCHER)

connection = driver("MYRANCHERACCESSKEY", "MYRANCHERSECRETKEY",
host="172.30.22.1", port=8080, secure=False)

search_results = connection.ex_search_containers(
search_params={ "imageUuid": "docker:mysql", "state": "running" })

id_of_first_result = search_results[0]['id']
Loading