Container Controller gets container uuid not name

Change-Id: I97ce71eea4132c7e10306e167e303b3236ba0155
This commit is contained in:
Davanum Srinivas 2014-12-29 13:51:18 -05:00
parent 3e2a1e5f69
commit 882d1280b9
4 changed files with 99 additions and 87 deletions

View File

@ -171,52 +171,58 @@ backend_api = api.API(context=context.RequestContext())
class StartController(object):
@wsme_pecan.wsexpose(wtypes.text, wtypes.text)
def _default(self, name):
LOG.debug('Calling backend_api.container_start with %s' % name)
return backend_api.container_start(name)
def _default(self, container_uuid):
LOG.debug('Calling backend_api.container_start with %s' %
container_uuid)
return backend_api.container_start(container_uuid)
class StopController(object):
@wsme_pecan.wsexpose(wtypes.text, wtypes.text)
def _default(self, name, *remainder):
LOG.debug('Calling backend_api.container_stop with %s' % name)
return backend_api.container_stop(name)
def _default(self, container_uuid, *remainder):
LOG.debug('Calling backend_api.container_stop with %s' %
container_uuid)
return backend_api.container_stop(container_uuid)
class RebootController(object):
@wsme_pecan.wsexpose(wtypes.text, wtypes.text)
def _default(self, name, *remainder):
LOG.debug('Calling backend_api.container_reboot with %s' % name)
return backend_api.container_reboot(name)
def _default(self, container_uuid, *remainder):
LOG.debug('Calling backend_api.container_reboot with %s' %
container_uuid)
return backend_api.container_reboot(container_uuid)
class PauseController(object):
@wsme_pecan.wsexpose(wtypes.text, wtypes.text)
def _default(self, name, *remainder):
LOG.debug('Calling backend_api.container_pause with %s' % name)
return backend_api.container_pause(name)
def _default(self, container_uuid, *remainder):
LOG.debug('Calling backend_api.container_pause with %s' %
container_uuid)
return backend_api.container_pause(container_uuid)
class UnpauseController(object):
@wsme_pecan.wsexpose(wtypes.text, wtypes.text)
def _default(self, name, *remainder):
LOG.debug('Calling backend_api.container_unpause with %s' % name)
return backend_api.container_unpause(name)
def _default(self, container_uuid, *remainder):
LOG.debug('Calling backend_api.container_unpause with %s' %
container_uuid)
return backend_api.container_unpause(container_uuid)
class LogsController(object):
@wsme_pecan.wsexpose(wtypes.text, wtypes.text)
def _default(self, name, *remainder):
LOG.debug('Calling backend_api.container_logs with %s' % name)
return backend_api.container_logs(name)
def _default(self, container_uuid, *remainder):
LOG.debug('Calling backend_api.container_logs with %s' %
container_uuid)
return backend_api.container_logs(container_uuid)
class ExecuteController(object):
@wsme_pecan.wsexpose(wtypes.text, wtypes.text, wtypes.text)
def _default(self, name, command, *remainder):
def _default(self, container_uuid, command, *remainder):
LOG.debug('Calling backend_api.container_execute with %s command %s'
% (name, command))
backend_api.container_execute(name, command)
% (container_uuid, command))
backend_api.container_execute(container_uuid, command)
class ContainersController(rest.RestController):
@ -328,7 +334,9 @@ class ContainersController(rest.RestController):
**container.as_dict())
new_container.create()
res_container = backend_api.container_create(new_container.name,
new_container.uuid,
new_container)
# Set the HTTP Location Header
pecan.response.location = link.build_url('containers',
res_container.uuid)

View File

@ -89,36 +89,39 @@ class API(rpc_service.API):
# Container operations
def container_create(self, name, container):
return self._call('container_create', name=name, container=container)
def container_create(self, name, container_uuid, container):
return self._call('container_create', name=name,
container_uuid=container_uuid,
container=container)
def container_list(self, context, limit, marker, sort_key, sort_dir):
return objects.Container.list(context, limit, marker, sort_key,
sort_dir)
def container_delete(self, name):
return self._call('container_delete', name=name)
def container_delete(self, container_uuid):
return self._call('container_delete', container_uuid=container_uuid)
def container_show(self, name):
return self._call('container_show', name)
def container_show(self, container_uuid):
return self._call('container_show', container_uuid)
def container_reboot(self, name):
return self._call('container_reboot', name=name)
def container_reboot(self, container_uuid):
return self._call('container_reboot', container_uuid=container_uuid)
def container_stop(self, name):
return self._call('container_stop', name=name)
def container_stop(self, container_uuid):
return self._call('container_stop', container_uuid=container_uuid)
def container_start(self, name):
return self._call('container_start', name=name)
def container_start(self, container_uuid):
return self._call('container_start', container_uuid=container_uuid)
def container_pause(self, name):
return self._call('container_pause', name=name)
def container_pause(self, container_uuid):
return self._call('container_pause', container_uuid=container_uuid)
def container_unpause(self, name):
return self._call('container_unpause', name=name)
def container_unpause(self, container_uuid):
return self._call('container_unpause', container_uuid=container_uuid)
def container_logs(self, name):
return self._call('container_logs', name=name)
def container_logs(self, container_uuid):
return self._call('container_logs', container_uuid=container_uuid)
def container_execute(self, name, command):
return self._call('container_execute', name=name, command=command)
def container_execute(self, container_uuid, command):
return self._call('container_execute', container_uuid=container_uuid,
command=command)

View File

@ -82,13 +82,13 @@ class DockerHTTPClient(client.Client):
res.append(info['Config'].get('Hostname'))
return res
def pause(self, container_id):
url = self._url("/containers/{0}/pause".format(container_id))
def pause(self, docker_id):
url = self._url("/containers/{0}/pause".format(docker_id))
res = self._post(url)
return res.status_code == 204
def unpause(self, container_id):
url = self._url("/containers/{0}/unpause".format(container_id))
def unpause(self, docker_id):
url = self._url("/containers/{0}/unpause".format(docker_id))
res = self._post(url)
return res.status_code == 204
@ -96,8 +96,8 @@ class DockerHTTPClient(client.Client):
with open(path) as fh:
self.load_image(fh)
def get_container_logs(self, container_id):
return self.attach(container_id, 1, 1, 0, 1)
def get_container_logs(self, docker_id):
return self.attach(docker_id, 1, 1, 0, 1)
# These are the backend operations. They are executed by the backend
@ -132,12 +132,12 @@ class Handler(object):
# Container operations
def container_create(self, ctxt, name, container):
def container_create(self, ctxt, name, container_uuid, container):
LOG.debug('Creating container with image %s name %s'
% (container.image_id, name))
self.docker.inspect_image(self._encode_utf8(container.image_id))
self.docker.create_container(container.image_id, name=name,
hostname=name)
hostname=container_uuid)
return container
def container_list(self, ctxt):
@ -145,48 +145,49 @@ class Handler(object):
container_list = self.docker.containers()
return container_list
def container_delete(self, ctxt, name):
LOG.debug("container_delete %s" % name)
container_id = self._find_container_by_name(name)
return self.docker.stop(container_id)
def container_delete(self, ctxt, container_uuid):
LOG.debug("container_delete %s" % container_uuid)
docker_id = self._find_container_by_name(container_uuid)
return self.docker.stop(docker_id)
def container_show(self, ctxt, name):
LOG.debug("container_show %s" % name)
container_id = self._find_container_by_name(name)
return self.docker.inspect_container(container_id)
def container_show(self, ctxt, container_uuid):
LOG.debug("container_show %s" % container_uuid)
docker_id = self._find_container_by_name(container_uuid)
return self.docker.inspect_container(docker_id)
def container_reboot(self, ctxt, name):
LOG.debug("container_reboot %s" % name)
container_id = self._find_container_by_name(name)
return self.docker.restart(container_id)
def container_reboot(self, ctxt, container_uuid):
LOG.debug("container_reboot %s" % container_uuid)
docker_id = self._find_container_by_name(container_uuid)
return self.docker.restart(docker_id)
def container_stop(self, ctxt, name):
LOG.debug("container_stop %s" % name)
container_id = self._find_container_by_name(name)
return self.docker.stop(container_id)
def container_stop(self, ctxt, container_uuid):
LOG.debug("container_stop %s" % container_uuid)
docker_id = self._find_container_by_name(container_uuid)
return self.docker.stop(docker_id)
def container_start(self, ctxt, name):
LOG.debug("Starting container %s" % name)
container_id = self._find_container_by_name(name)
LOG.debug("Found Docker container %s" % container_id)
return self.docker.start(container_id)
def container_start(self, ctxt, container_uuid):
LOG.debug("Starting container %s" % container_uuid)
docker_id = self._find_container_by_name(container_uuid)
LOG.debug("Found Docker container %s" % docker_id)
return self.docker.start(docker_id)
def container_pause(self, ctxt, name):
LOG.debug("container_pause %s" % name)
container_id = self._find_container_by_name(name)
return self.docker.pause(container_id)
def container_pause(self, ctxt, container_uuid):
LOG.debug("container_pause %s" % container_uuid)
docker_id = self._find_container_by_name(container_uuid)
return self.docker.pause(docker_id)
def container_unpause(self, ctxt, name):
LOG.debug("container_unpause %s" % name)
container_id = self._find_container_by_name(name)
return self.docker.unpause(container_id)
def container_unpause(self, ctxt, container_uuid):
LOG.debug("container_unpause %s" % container_uuid)
docker_id = self._find_container_by_name(container_uuid)
return self.docker.unpause(docker_id)
def container_logs(self, ctxt, name):
LOG.debug("container_logs %s" % name)
container_id = self._find_container_by_name(name)
return self.docker.get_container_logs(container_id)
def container_logs(self, ctxt, container_uuid):
LOG.debug("container_logs %s" % container_uuid)
docker_id = self._find_container_by_name(container_uuid)
return self.docker.get_container_logs(docker_id)
def container_execute(self, ctxt, name, command):
LOG.debug("container_execute %s command %s" % (name, command))
container_id = self._find_container_by_name(name)
return self.docker.execute(container_id, command)
def container_execute(self, ctxt, container_uuid, command):
LOG.debug("container_execute %s command %s" %
(container_uuid, command))
docker_id = self._find_container_by_name(container_uuid)
return self.docker.execute(docker_id, command)

View File

@ -32,7 +32,7 @@ class TestContainerController(db_base.DbTestCase):
mock_container_stop,
mock_container_start,
mock_container_create):
mock_container_create.side_effect = lambda x, y: y
mock_container_create.side_effect = lambda x, y, z: z
mock_container_start.return_value = None
mock_container_stop.return_value = None
mock_container_pause.return_value = None