From a4cb8d1f24ea7ff29c384f2af88c3fbfcfb0464d Mon Sep 17 00:00:00 2001 From: Shu Muto Date: Tue, 5 Dec 2017 20:44:49 +0900 Subject: [PATCH] Add parameters for container creation This patch adds 'auto_remove', 'hostname' and 'runtime' parameters for container creation. Also, adds these parameters into details view. These parameters are not for update, so these are readonly in update dialog. Change-Id: I011008023158dabf6f69b3b1695d6ed3eaed849d Implements: blueprint add-create-options-for-queens --- zun_ui/api/client.py | 8 ++- .../containers/actions/create.service.js | 2 +- .../containers/actions/update.service.js | 6 ++ .../actions/workflow/misc.help.html | 4 +- .../actions/workflow/spec.help.html | 2 + .../actions/workflow/workflow.service.js | 59 +++++++++++++++++-- .../container/containers/containers.module.js | 6 +- .../containers/details/overview.html | 4 +- 8 files changed, 79 insertions(+), 12 deletions(-) diff --git a/zun_ui/api/client.py b/zun_ui/api/client.py index afb42aa..6a8bb40 100644 --- a/zun_ui/api/client.py +++ b/zun_ui/api/client.py @@ -15,6 +15,7 @@ from horizon import exceptions from horizon.utils.memoized import memoized_with_request import logging from openstack_dashboard.api import base +from zunclient import api_versions from zunclient.common import utils from zunclient.v1 import client as zun_client @@ -23,6 +24,7 @@ LOG = logging.getLogger(__name__) CONTAINER_CREATE_ATTRS = zun_client.containers.CREATION_ATTRIBUTES IMAGE_PULL_ATTRS = zun_client.images.PULL_ATTRIBUTES +API_VERSION = api_versions.APIVersion(api_versions.DEFAULT_API_VERSION) def get_auth_params_from_request(request): @@ -58,7 +60,8 @@ def zunclient(request_auth_params): c = zun_client.Client(username=username, project_id=project_id, auth_token=token_id, - endpoint_override=endpoint_override) + endpoint_override=endpoint_override, + api_version=API_VERSION) return c @@ -74,7 +77,8 @@ def _cleanup_params(attrs, check, **params): elif key == "memory": args[key] = int(value) elif key == "interactive" or key == "nets" \ - or key == "security_groups" or key == "hints": + or key == "security_groups" or key == "hints"\ + or key == "auto_remove": args[key] = value elif key == "restart_policy": args[key] = utils.check_restart_policy(value) diff --git a/zun_ui/static/dashboard/container/containers/actions/create.service.js b/zun_ui/static/dashboard/container/containers/actions/create.service.js index ea69aec..8df2c52 100644 --- a/zun_ui/static/dashboard/container/containers/actions/create.service.js +++ b/zun_ui/static/dashboard/container/containers/actions/create.service.js @@ -104,7 +104,7 @@ // Not only "null", blank too. for (var key in model) { if (model.hasOwnProperty(key) && model[key] === null || model[key] === "" || - key === "tabs") { + key === "tabs" || (key === "auto_remove" && model[key] === false)) { delete model[key]; } } diff --git a/zun_ui/static/dashboard/container/containers/actions/update.service.js b/zun_ui/static/dashboard/container/containers/actions/update.service.js index fac9ef7..30a11b1 100644 --- a/zun_ui/static/dashboard/container/containers/actions/update.service.js +++ b/zun_ui/static/dashboard/container/containers/actions/update.service.js @@ -79,6 +79,8 @@ ? response.data.image_pull_policy : ""; config.model.command = response.data.command ? response.data.command : ""; + config.model.hostname = response.data.hostname + ? response.data.hostname : ""; config.model.cpu = response.data.cpu ? response.data.cpu : ""; config.model.memory = response.data.memory @@ -87,12 +89,16 @@ ? response.data.restart_policy.Name : ""; config.model.restart_policy_max_retry = response.data.restart_policy.MaximumRetryCount ? parseInt(response.data.restart_policy.MaximumRetryCount, 10) : null; + config.model.runtime = response.data.runtime + ? response.data.runtime : ""; config.model.workdir = response.data.workdir ? response.data.workdir : ""; config.model.environment = response.data.environment ? hashToString(response.data.environment) : ""; config.model.interactive = response.data.interactive ? response.data.interactive : false; + config.model.auto_remove = response.data.auto_remove + ? response.data.auto_remove : false; config.model.labels = response.data.labels ? hashToString(response.data.labels) : ""; } diff --git a/zun_ui/static/dashboard/container/containers/actions/workflow/misc.help.html b/zun_ui/static/dashboard/container/containers/actions/workflow/misc.help.html index 7545b87..0a92239 100644 --- a/zun_ui/static/dashboard/container/containers/actions/workflow/misc.help.html +++ b/zun_ui/static/dashboard/container/containers/actions/workflow/misc.help.html @@ -4,5 +4,7 @@
Environment Variables
The environment variables in comma separated KEY=VALUE pairs
Enable Interactive Mode
-
Allocate pseudo-TTY and keep STDIN open even if not attatched. This also enables Web console in console tab on details view.
+
Allocate pseudo-TTY and keep STDIN open even if not attached. This also enables Web console in console tab on details view.
+
Auto remove
+
Automatically remove the container when it exits
diff --git a/zun_ui/static/dashboard/container/containers/actions/workflow/spec.help.html b/zun_ui/static/dashboard/container/containers/actions/workflow/spec.help.html index 95e13fc..fdfca13 100644 --- a/zun_ui/static/dashboard/container/containers/actions/workflow/spec.help.html +++ b/zun_ui/static/dashboard/container/containers/actions/workflow/spec.help.html @@ -5,4 +5,6 @@
The container memory size in MiB.
Restart Policy
Restart policy to apply when a container exits.
+
Restart Policy
+
The runtime to use for this container. Default: "runc"
diff --git a/zun_ui/static/dashboard/container/containers/actions/workflow/workflow.service.js b/zun_ui/static/dashboard/container/containers/actions/workflow/workflow.service.js index 19a8e71..1739a03 100644 --- a/zun_ui/static/dashboard/container/containers/actions/workflow/workflow.service.js +++ b/zun_ui/static/dashboard/container/containers/actions/workflow/workflow.service.js @@ -51,6 +51,10 @@ {value: "always", name: gettext("Always")}, {value: "unless-stopped", name: gettext("Unless Stopped")} ]; + var runtimes = [ + {value: "", name: gettext("Select runtime.")}, + {value: "runc", name: gettext("runc")} + ]; // schema schema = { @@ -92,6 +96,10 @@ type: "number", minimum: 4 }, + hostname: { + title: gettext("Hostname"), + type: "string" + }, restart_policy: { title: gettext("Restart Policy"), type: "string" @@ -101,6 +109,10 @@ type: "number", minimum: 0 }, + runtime: { + title: gettext("Runtime"), + type: "string" + }, // misc workdir: { title: gettext("Working Directory"), @@ -114,6 +126,10 @@ title: gettext("Enable interactive mode"), type: "boolean" }, + auto_remove: { + title: gettext("Auto remove"), + type: "boolean" + }, // labels labels: { title: gettext("Labels"), @@ -183,8 +199,7 @@ }, { key: "run", - readonly: action === "update", - condition: action === "update" + readonly: action === "update" } ] } @@ -199,12 +214,29 @@ { type: "section", htmlClass: "col-xs-12", + items: [ + { + key: "hostname", + placeholder: gettext("The host name of this container."), + readonly: action === "update" + } + ] + }, + { + type: "section", + htmlClass: "col-xs-6", items: [ { key: "cpu", step: 0.1, placeholder: gettext("The number of virtual cpu for this container.") - }, + } + ] + }, + { + type: "section", + htmlClass: "col-xs-6", + items: [ { key: "memory", placeholder: gettext("The container memory size in MiB.") @@ -225,7 +257,7 @@ if (readonly) { model.restart_policy_max_retry = ""; } - form[0].tabs[1].items[2].items[0].readonly = readonly; + form[0].tabs[1].items[4].items[0].readonly = readonly; } } ] @@ -240,6 +272,18 @@ readonly: true } ] + }, + { + type: "section", + htmlClass: "col-xs-6", + items: [ + { + key: "runtime", + type: "select", + readonly: action === "update", + titleMap: runtimes + } + ] } ] }, @@ -327,6 +371,10 @@ { key: "interactive", readonly: action === "update" + }, + { + key: "auto_remove", + readonly: action === "update" } ] } @@ -387,10 +435,12 @@ command: "", run: true, // spec + hostname: "", cpu: "", memory: "", restart_policy: "", restart_policy_max_retry: "", + runtime: "", // networks networks: [], // ports @@ -401,6 +451,7 @@ workdir: "", environment: "", interactive: true, + auto_remove: false, // labels labels: "", // hints diff --git a/zun_ui/static/dashboard/container/containers/containers.module.js b/zun_ui/static/dashboard/container/containers/containers.module.js index 83feab6..cb251a5 100644 --- a/zun_ui/static/dashboard/container/containers/containers.module.js +++ b/zun_ui/static/dashboard/container/containers/containers.module.js @@ -143,6 +143,7 @@ function containerProperties() { return { 'addresses': { label: gettext('Addresses'), filters: ['noValue', 'json'] }, + 'auto_remove': { label: gettext('Auto Remove'), filters: ['yesno'] }, 'command': { label: gettext('Command'), filters: ['noValue'] }, 'cpu': { label: gettext('CPU'), filters: ['noValue'] }, 'environment': { label: gettext('Environment'), filters: ['noValue', 'json'] }, @@ -152,17 +153,18 @@ 'image': {label: gettext('Image'), filters: ['noValue'] }, 'image_driver': {label: gettext('Image Driver'), filters: ['noValue'] }, 'image_pull_policy': {label: gettext('Image Pull Policy'), filters: ['noValue'] }, + 'interactive': {label: gettext('Interactive'), filters: ['yesno'] }, 'labels': {label: gettext('Labels'), filters: ['noValue', 'json'] }, 'links': {label: gettext('Links'), filters: ['noValue', 'json'] }, 'memory': {label: gettext('Memory'), filters: ['noValue'] }, 'name': {label: gettext('Name'), filters: ['noName'] }, 'ports': {label: gettext('Ports'), filters: ['noValue', 'json'] }, - 'security_groups': {label: gettext('Security Groups'), filters: ['noValue', 'json'] }, 'restart_policy': {label: gettext('Restart Policy'), filters: ['noValue', 'json'] }, + 'runtime': {label: gettext('Runtime'), filters: ['noName'] }, + 'security_groups': {label: gettext('Security Groups'), filters: ['noValue', 'json'] }, 'status': {label: gettext('Status'), filters: ['noValue'] }, 'status_detail': {label: gettext('Status Detail'), filters: ['noValue'] }, 'status_reason': {label: gettext('Status Reason'), filters: ['noValue'] }, - 'interactive': {label: gettext('Interactive'), filters: ['yesno'] }, 'task_state': {label: gettext('Task State'), filters: ['noValue'] }, 'workdir': {label: gettext('Workdir'), filters: ['noValue'] } }; diff --git a/zun_ui/static/dashboard/container/containers/details/overview.html b/zun_ui/static/dashboard/container/containers/details/overview.html index f904c14..39ccc70 100644 --- a/zun_ui/static/dashboard/container/containers/details/overview.html +++ b/zun_ui/static/dashboard/container/containers/details/overview.html @@ -19,7 +19,7 @@ cls="dl-horizontal" item="ctrl.container" property-groups="[['image', 'image_driver', 'image_pull_policy', - 'cpu', 'memory', 'restart_policy', + 'cpu', 'memory', 'restart_policy', 'runtime', 'hostname', 'addresses', 'ports', 'security_groups']]"> @@ -33,7 +33,7 @@ cls="dl-horizontal" item="ctrl.container" property-groups="[['host', 'workdir', 'environment', 'interactive', - 'labels','links']]"> + 'auto_remove', 'labels','links']]">