Implement docker backend for magnum service

Change-Id: I6bde0149caaf93b6e446f5f01039895fb36751e6
Implements: blueprint magnum-backend-docker
This commit is contained in:
digambar 2014-12-19 23:07:24 +05:30 committed by Davanum Srinivas
parent 36244a0443
commit ea25d067a6
1 changed files with 80 additions and 23 deletions

View File

@ -12,52 +12,109 @@
"""Magnum Docker RPC handler."""
from docker import Client
from docker import tls
from oslo.config import cfg
from magnum.openstack.common import log as logging
LOG = logging.getLogger(__name__)
CONF = cfg.CONF
docker_opts = [
cfg.StrOpt('host_url',
help='tcp://host:port to bind/connect to or'
'unix://path/to/socker to use'),
cfg.BoolOpt('api_secure',
default=False,
help='If set, ignore any SSL validation issues'),
cfg.StrOpt('ca_file',
help='Location of CA certificate file for '
'securing docker api requests (tlscacert).'),
cfg.StrOpt('cert_file',
help='Location of TLS certificate file for '
'securing docker api requests (tlscert).'),
cfg.StrOpt('key_file',
help='Location of TLS private key file for '
'securing docker api requests (tlskey).'),
]
CONF.register_opts(docker_opts, 'docker')
# These are the backend operations. They are executed by the backend
# service. API calls via AMQP (within the ReST API) trigger the handlers to
# be called.
class Handler(object):
def __init__(self):
def __init__(self, url):
super(Handler, self).__init__()
if (CONF.docker.cert_file or
CONF.docker.key_file):
client_cert = (CONF.docker.cert_file, CONF.docker.key_file)
else:
client_cert = None
if (CONF.docker.ca_file or
CONF.docker.api_insecure or
client_cert):
tls_config = tls.TLSConfig(
client_cert=client_cert,
ca_Cert=CONF.docker.ca_file,
verify=CONF.docker.api_insecure)
else:
tls_config = None
self.client = Client(base_url=url, tls=tls_config)
def encode_utf8(self, value):
return unicode(value).encode('utf-8')
# Container operations
def container_create(uuid, contents):
LOG.debug("container_create %s contents=%s" % (uuid, contents))
def container_create(self, bay_uuid, image_name, command):
LOG.debug("container_create %s contents=%s" % (bay_uuid, image_name))
self.client.inspect_image(self._encode_utf8(image_name))
container_id = self.client.create_container(image_name, command)
self.container_start(container_id)
def container_list():
def container_list(self, bay_uuid):
LOG.debug("container_list")
container_list = self.client.containers()
return container_list
# return container list dict
def container_delete(uuid):
LOG.debug("cotainer_delete %s" % uuid)
def container_delete(self, bay_uuid, container_id):
LOG.debug("cotainer_delete %s" % bay_uuid)
return None
def container_show(uuid):
LOG.debug("container_show %s" % uuid)
# return container information dict
def container_show(self, bay_uuid, container_id):
LOG.debug("container_show %s" % bay_uuid)
return None
def container_reboot(uuid):
LOG.debug("container_reboot %s" % uuid)
def container_reboot(self, bay_uuid, container_id):
LOG.debug("container_reboot %s" % bay_uuid)
return None
def container_stop(uuid):
LOG.debug("container_stop %s" % uuid)
def container_stop(self, bay_uuid, container_id):
LOG.debug("container_stop %s" % bay_uuid)
self.client.start(container_id)
def container_start(uuid):
LOG.debug("container_start %s" % uuid)
def container_start(self, bay_uuid, container_id):
LOG.debug("container_start %s" % bay_uuid)
self.client.start(container_id)
def container_pause(uuid):
LOG.debug("container_pause %s" % uuid)
def container_pause(self, bay_uuid, container_id):
LOG.debug("container_pause %s" % bay_uuid)
return None
def container_unpause(uuid):
LOG.debug("container_unpause %s" % uuid)
def container_unpause(self, bay_uuid, container_id):
LOG.debug("container_unpause %s" % bay_uuid)
return None
def container_logs(uuid):
LOG.debug("container_logs %s" % uuid)
def container_logs(self, bay_uuid, container_id):
LOG.debug("container_logs %s" % bay_uuid)
return None
def container_execute(uuid):
LOG.debug("container_execute %s" % uuid)
def container_execute(self, bay_uuid, container_id):
LOG.debug("container_execute %s" % bay_uuid)
return None