Implement docker container related operations

Change-Id: I817b49a2e5d5f5f37433d102b431330ef9b89362
This commit is contained in:
Jay Lau 2014-12-22 21:30:33 -05:00
parent 51d3cb88a6
commit 3c794bd972
2 changed files with 65 additions and 48 deletions

View File

@ -89,36 +89,46 @@ class API(rpc_service.API):
# Container operations
def container_create(self, uuid, container):
return self._call('container_create', container=container)
def container_create(self, image_name, command):
return self._call('container_create', image_name=image_name,
command=command)
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, uuid):
return self._call('container_delete', uuid=uuid)
def container_delete(self, container_id):
return self._call('container_delete',
container_id=container_id)
def container_show(self, uuid):
return self._call('container_show', uuid=uuid)
def container_show(self, container_id):
return self._call('container_show',
container_id=container_id)
def container_reboot(self, uuid):
return self._call('container_reboot', uuid=uuid)
def container_reboot(self, container_id):
return self._call('container_reboot',
container_id=container_id)
def container_stop(self, uuid):
return self._call('container_stop', uuid=uuid)
def container_stop(self, container_id):
return self._call('container_stop',
container_id=container_id)
def container_start(self, uuid):
return self._call('container_start', uuid=uuid)
def container_start(self, container_id):
return self._call('container_start',
container_id=container_id)
def container_pause(self, uuid):
return self._call('container_pause', uuid=uuid)
def container_pause(self, container_id):
return self._call('container_pause',
container_id=container_id)
def container_unpause(self, uuid):
return self._call('container_unpause', uuid=uuid)
def container_unpause(self, container_id):
return self._call('container_unpause',
container_id=container_id)
def container_logs(self, uuid):
return self._call('container_logs', uuid=uuid)
def container_logs(self, container_id):
return self._call('container_logs',
container_id=container_id)
def container_execute(self, uuid):
return self._call('container_execute', uuid=uuid)
def container_execute(self, container_id, cmd):
return self._call('container_execute',
container_id=container_id, cmd=cmd)

View File

@ -71,50 +71,57 @@ class Handler(object):
# Container operations
def container_create(self, bay_uuid, image_name, command):
LOG.debug("container_create %s contents=%s" % (bay_uuid, image_name))
def container_create(self, image_name, command):
LOG.debug("container_create image=%s command=%s"
% (image_name, command))
self.client.inspect_image(self._encode_utf8(image_name))
container_id = self.client.create_container(image_name, command)
self.container_start(container_id)
return container_id
def container_list(self, bay_uuid):
def container_list(self):
LOG.debug("container_list")
container_list = self.client.containers()
return container_list
# return container list dict
def container_delete(self, bay_uuid, container_id):
LOG.debug("cotainer_delete %s" % bay_uuid)
def container_delete(self, container_id):
LOG.debug("cotainer_delete %s" % container_id)
self.client.remove_container(container_id, force=True)
return None
def container_show(self, bay_uuid, container_id):
LOG.debug("container_show %s" % bay_uuid)
return None
def container_show(self, container_id):
LOG.debug("container_show %s" % container_id)
container_info = self.client.inspect_container(container_id)
return container_info
def container_reboot(self, bay_uuid, container_id):
LOG.debug("container_reboot %s" % bay_uuid)
return None
def container_stop(self, bay_uuid, container_id):
LOG.debug("container_stop %s" % bay_uuid)
def container_reboot(self, container_id):
LOG.debug("container_reboot %s" % container_id)
self.client.stop(container_id)
self.client.start(container_id)
def container_start(self, bay_uuid, container_id):
LOG.debug("container_start %s" % bay_uuid)
def container_stop(self, container_id):
LOG.debug("container_stop %s" % container_id)
self.cleint.stop(container_id)
def container_start(self, container_id):
LOG.debug("container_start %s" % container_id)
self.client.start(container_id)
def container_pause(self, bay_uuid, container_id):
LOG.debug("container_pause %s" % bay_uuid)
return None
def container_pause(self, container_id):
LOG.debug("container_pause %s" % container_id)
self.client.pause(container_id)
def container_unpause(self, bay_uuid, container_id):
LOG.debug("container_unpause %s" % bay_uuid)
return None
def container_unpause(self, container_id):
LOG.debug("container_unpause %s" % container_id)
self.client.unpause(container_id)
def container_logs(self, bay_uuid, container_id):
LOG.debug("container_logs %s" % bay_uuid)
return None
def container_logs(self, container_id):
LOG.debug("container_logs %s" % container_id)
container_logs = self.client.logs(container_id)
return container_logs
def container_execute(self, bay_uuid, container_id):
LOG.debug("container_execute %s" % bay_uuid)
return None
def container_execute(self, container_id, cmd):
LOG.debug("container_execute %s cmd=%s" % (container_id, cmd))
self.client.execute(container_id, cmd, detach=False, stdout=True,
stderr=True, stream=False, tty=False)