diff --git a/requirements.txt b/requirements.txt index 1a0af2c..6412a80 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,8 +8,8 @@ # # PBR should always appear first pbr>=1.6 # Apache-2.0 -# If python-higginsclient will be created, we will use it. -#python-higginsclient>=0.1.0 # Apache-2.0 +# If python-zunclient will be released, we will use it. +#python-zunclient>=0.0.1 # Apache-2.0 Babel>=2.3.4 # BSD Django<1.9,>=1.8 # BSD django-babel>=0.5.1 # BSD diff --git a/tox.ini b/tox.ini index 7e8c056..d565db9 100644 --- a/tox.ini +++ b/tox.ini @@ -16,6 +16,13 @@ deps = -r{toxinidir}/requirements.txt -r{toxinidir}/test-requirements.txt commands = python manage.py test {posargs} --settings=zun_ui.test.settings +# Until python-zunclient released, install from github temporary. +[testenv:py27] +basepython = python2.7 +commands = + pip install git+https://github.com/openstack/python-zunclient.git + python manage.py test {posargs} --settings=zun_ui.test.settings + [testenv:pep8] commands = flake8 {posargs} diff --git a/zun_ui/api/client.py b/zun_ui/api/client.py index 8651b8e..7e17848 100644 --- a/zun_ui/api/client.py +++ b/zun_ui/api/client.py @@ -11,45 +11,20 @@ # under the License. -from __future__ import absolute_import -import logging -# from zunclient.v1 import client as zun_client - from horizon import exceptions from horizon.utils.memoized import memoized -# from openstack_dashboard.api import base - -# for stab, should remove when use CLI API -import copy -import uuid +import logging +from openstack_dashboard.api import base +from zunclient.v1 import client as zun_client LOG = logging.getLogger(__name__) -CONTAINER_CREATE_ATTRS = ['name'] - -STUB_DATA = {} - - -# for stab, should be removed when use CLI API -class StubResponse(object): - - def __init__(self, info): - self._info = info - - def __repr__(self): - reprkeys = sorted(k for k in self.__dict__.keys() if k[0] != '_') - info = ", ".join("%s=%s" % (k, getattr(self, k)) for k in reprkeys) - return "<%s %s>" % (self.__class__.__name__, info) - - def to_dict(self): - return copy.deepcopy(self._info) +CONTAINER_CREATE_ATTRS = ['name', 'image', 'command', 'memory', 'environment'] @memoized def zunclient(request): - pass - """" zun_url = "" try: zun_url = base.url_for(request, 'container') @@ -60,11 +35,10 @@ def zunclient(request): LOG.debug('zunclient connection created using the token "%s" and url' '"%s"' % (request.user.token.id, zun_url)) c = zun_client.Client(username=request.user.username, - project_id=request.user.tenant_id, - input_auth_token=request.user.token.id, - zun_url=zun_url) + project_id=request.user.tenant_id, + input_auth_token=request.user.token.id, + zun_url=zun_url) return c - """ def container_create(request, **kwargs): @@ -75,41 +49,28 @@ def container_create(request, **kwargs): else: raise exceptions.BadRequest( "Key must be in %s" % ",".join(CONTAINER_CREATE_ATTRS)) - if key == "labels": - labels = {} + if key == "environment": + envs = {} vals = value.split(",") for v in vals: kv = v.split("=", 1) - labels[kv[0]] = kv[1] - args["labels"] = labels - # created = zunclient(request).containers.create(**args) - - # create dummy response - args["uuid"] = uuid.uuid1().hex - created = StubResponse(args) - for k in args: - setattr(created, k, args[k]) - STUB_DATA[created.uuid] = created - - return created + envs[kv[0]] = kv[1] + args["environment"] = envs + return zunclient(request).containers.create(**args) -def container_delete(request, id): - # deleted = zunclient(request).containers.delete(id) - deleted = STUB_DATA.pop(id) - - return deleted +def container_delete(request, id, force=False): + # TODO(shu-mutou): force option should be provided by user. + return zunclient(request).containers.delete(id, force) def container_list(request, limit=None, marker=None, sort_key=None, sort_dir=None, detail=True): - # list = zunclient(request).containers.list(limit, marker, sort_key, - # sort_dir, detail) - list = [STUB_DATA[data] for data in STUB_DATA] - return list + # TODO(shu-mutou): detail option should be added, if it is + # implemented in Zun API + return zunclient(request).containers.list(limit, marker, sort_key, + sort_dir) def container_show(request, id): - # show = zunclient(request).containers.get(id) - show = STUB_DATA.get(id) - return show + return zunclient(request).containers.get(id) diff --git a/zun_ui/static/dashboard/container/containers/containers.module.js b/zun_ui/static/dashboard/container/containers/containers.module.js index 7b112fb..dd61676 100644 --- a/zun_ui/static/dashboard/container/containers/containers.module.js +++ b/zun_ui/static/dashboard/container/containers/containers.module.js @@ -65,6 +65,12 @@ .setProperty('id', { label: gettext('ID') }) + .setProperty('image', { + label: gettext('Image') + }) + .setProperty('status', { + label: gettext('Status') + }) .setListFunction(listFunction) .tableColumns .append({ @@ -77,6 +83,14 @@ .append({ id: 'id', priority: 2 + }) + .append({ + id: 'image', + priority: 2 + }) + .append({ + id: 'status', + priority: 2 }); // for magic-search registry.getResourceType(resourceType).filterFacets @@ -89,6 +103,16 @@ 'label': gettext('ID'), 'name': 'id', 'singleton': true + }) + .append({ + 'label': gettext('Image'), + 'name': 'image', + 'singleton': true + }) + .append({ + 'label': gettext('Status'), + 'name': 'status', + 'singleton': true }); function listFunction(params) { diff --git a/zun_ui/static/dashboard/container/containers/create/container-model.js b/zun_ui/static/dashboard/container/containers/create/container-model.js index 8f58908..e1f7154 100644 --- a/zun_ui/static/dashboard/container/containers/create/container-model.js +++ b/zun_ui/static/dashboard/container/containers/create/container-model.js @@ -34,7 +34,14 @@ function initNewContainerSpec() { model.newContainerSpec = { + uuid: null, name: null, + image: null, + command: null, + memory: null, + memory_size: null, + memory_unit: "m", + environment: null }; } @@ -56,7 +63,8 @@ // Not only "null", blank too. for (var key in finalSpec) { if (finalSpec.hasOwnProperty(key) && finalSpec[key] === null - || finalSpec[key] === "") { + || finalSpec[key] === "" + || key === "memory_size" || key === "memory_unit") { delete finalSpec[key]; } } diff --git a/zun_ui/static/dashboard/container/containers/create/info/container.info.controller.js b/zun_ui/static/dashboard/container/containers/create/info/container.info.controller.js index 3a35265..4e0438b 100644 --- a/zun_ui/static/dashboard/container/containers/create/info/container.info.controller.js +++ b/zun_ui/static/dashboard/container/containers/create/info/container.info.controller.js @@ -36,5 +36,23 @@ function createContainerInfoController($q, $scope, basePath, zun, gettext) { var ctrl = this; + ctrl.memory_units = [{unit: "b", label: gettext("bytes")}, + {unit: "k", label: gettext("KB")}, + {unit: "m", label: gettext("MB")}, + {unit: "g", label: gettext("GB")}]; + + $scope.changeMemory = function(){ + if($scope.model.newContainerSpec.memory_size > 0){ + $scope.model.newContainerSpec.memory = $scope.model.newContainerSpec.memory_size + $scope.model.newContainerSpec.memory_unit; + }else{ + $scope.model.newContainerSpec.memory = null; + } + }; + $scope.changeMemoryUnit = function(){ + $scope.changeMemory(); + }; + $scope.changeMemorySize = function(){ + $scope.changeMemory(); + }; } })(); diff --git a/zun_ui/static/dashboard/container/containers/create/info/info.help.html b/zun_ui/static/dashboard/container/containers/create/info/info.help.html index f0eac99..a875d89 100644 --- a/zun_ui/static/dashboard/container/containers/create/info/info.help.html +++ b/zun_ui/static/dashboard/container/containers/create/info/info.help.html @@ -1,4 +1,13 @@
+
Container Name
An arbitrary human-readable name
+
Image
+
Name or ID of container image
+
Command
+
Command sent to the container
+
Memory
+
The container memory size
+
Environment Variables
+
The environment variables in comma separated KEY=VALUE pairs
diff --git a/zun_ui/static/dashboard/container/containers/create/info/info.html b/zun_ui/static/dashboard/container/containers/create/info/info.html index b4ac03d..2b84f61 100644 --- a/zun_ui/static/dashboard/container/containers/create/info/info.html +++ b/zun_ui/static/dashboard/container/containers/create/info/info.html @@ -1,6 +1,6 @@
-
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
diff --git a/zun_ui/static/dashboard/container/containers/details/drawer.controller.js b/zun_ui/static/dashboard/container/containers/details/drawer.controller.js index 578f609..eb2ad98 100644 --- a/zun_ui/static/dashboard/container/containers/details/drawer.controller.js +++ b/zun_ui/static/dashboard/container/containers/details/drawer.controller.js @@ -28,12 +28,9 @@ .controller('horizon.dashboard.container.containers.DrawerController', controller); controller.$inject = [ - 'horizon.app.core.openstack-service-api.zun', - 'horizon.dashboard.container.containers.resourceType' ]; - function controller(zun, resourceType) { - var ctrl = this; + function controller() { } })(); diff --git a/zun_ui/static/dashboard/container/containers/details/drawer.html b/zun_ui/static/dashboard/container/containers/details/drawer.html index e5bb69a..6ebfeb8 100644 --- a/zun_ui/static/dashboard/container/containers/details/drawer.html +++ b/zun_ui/static/dashboard/container/containers/details/drawer.html @@ -5,12 +5,24 @@
ID
{$ item.id $}
+
+
Image
+
{$ item.image $}
+
+
+
Status
+
{$ item.status $}
+
-
-
Name
-
{$ item.name $}
+
+
Command
+
{$ item.command $}
+
+
+
Memory
+
{$ item.memory $}
diff --git a/zun_ui/static/dashboard/container/containers/details/overview.html b/zun_ui/static/dashboard/container/containers/details/overview.html index 8307482..7151f4e 100644 --- a/zun_ui/static/dashboard/container/containers/details/overview.html +++ b/zun_ui/static/dashboard/container/containers/details/overview.html @@ -6,6 +6,24 @@
Name
{$ ctrl.container.name|noName $}
+
Status
+
{$ ctrl.container.status $}
+
Image
+
{$ ctrl.container.image $}
+
Command
+
{$ ctrl.container.command $}
+
Memory
+
{$ ctrl.container.memory $}
+
+ +
+

Environment

+
+
+
+
{$ key $}
+
{$ value $}
+