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
This commit is contained in:
Shu Muto 2017-12-05 20:44:49 +09:00
parent 20c1196e2c
commit a4cb8d1f24
8 changed files with 79 additions and 12 deletions

View File

@ -15,6 +15,7 @@ from horizon import exceptions
from horizon.utils.memoized import memoized_with_request from horizon.utils.memoized import memoized_with_request
import logging import logging
from openstack_dashboard.api import base from openstack_dashboard.api import base
from zunclient import api_versions
from zunclient.common import utils from zunclient.common import utils
from zunclient.v1 import client as zun_client from zunclient.v1 import client as zun_client
@ -23,6 +24,7 @@ LOG = logging.getLogger(__name__)
CONTAINER_CREATE_ATTRS = zun_client.containers.CREATION_ATTRIBUTES CONTAINER_CREATE_ATTRS = zun_client.containers.CREATION_ATTRIBUTES
IMAGE_PULL_ATTRS = zun_client.images.PULL_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): def get_auth_params_from_request(request):
@ -58,7 +60,8 @@ def zunclient(request_auth_params):
c = zun_client.Client(username=username, c = zun_client.Client(username=username,
project_id=project_id, project_id=project_id,
auth_token=token_id, auth_token=token_id,
endpoint_override=endpoint_override) endpoint_override=endpoint_override,
api_version=API_VERSION)
return c return c
@ -74,7 +77,8 @@ def _cleanup_params(attrs, check, **params):
elif key == "memory": elif key == "memory":
args[key] = int(value) args[key] = int(value)
elif key == "interactive" or key == "nets" \ 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 args[key] = value
elif key == "restart_policy": elif key == "restart_policy":
args[key] = utils.check_restart_policy(value) args[key] = utils.check_restart_policy(value)

View File

@ -104,7 +104,7 @@
// Not only "null", blank too. // Not only "null", blank too.
for (var key in model) { for (var key in model) {
if (model.hasOwnProperty(key) && model[key] === null || model[key] === "" || if (model.hasOwnProperty(key) && model[key] === null || model[key] === "" ||
key === "tabs") { key === "tabs" || (key === "auto_remove" && model[key] === false)) {
delete model[key]; delete model[key];
} }
} }

View File

@ -79,6 +79,8 @@
? response.data.image_pull_policy : ""; ? response.data.image_pull_policy : "";
config.model.command = response.data.command config.model.command = response.data.command
? response.data.command : ""; ? response.data.command : "";
config.model.hostname = response.data.hostname
? response.data.hostname : "";
config.model.cpu = response.data.cpu config.model.cpu = response.data.cpu
? response.data.cpu : ""; ? response.data.cpu : "";
config.model.memory = response.data.memory config.model.memory = response.data.memory
@ -87,12 +89,16 @@
? response.data.restart_policy.Name : ""; ? response.data.restart_policy.Name : "";
config.model.restart_policy_max_retry = response.data.restart_policy.MaximumRetryCount config.model.restart_policy_max_retry = response.data.restart_policy.MaximumRetryCount
? parseInt(response.data.restart_policy.MaximumRetryCount, 10) : null; ? parseInt(response.data.restart_policy.MaximumRetryCount, 10) : null;
config.model.runtime = response.data.runtime
? response.data.runtime : "";
config.model.workdir = response.data.workdir config.model.workdir = response.data.workdir
? response.data.workdir : ""; ? response.data.workdir : "";
config.model.environment = response.data.environment config.model.environment = response.data.environment
? hashToString(response.data.environment) : ""; ? hashToString(response.data.environment) : "";
config.model.interactive = response.data.interactive config.model.interactive = response.data.interactive
? response.data.interactive : false; ? response.data.interactive : false;
config.model.auto_remove = response.data.auto_remove
? response.data.auto_remove : false;
config.model.labels = response.data.labels config.model.labels = response.data.labels
? hashToString(response.data.labels) : ""; ? hashToString(response.data.labels) : "";
} }

View File

@ -4,5 +4,7 @@
<dt translate>Environment Variables</dt> <dt translate>Environment Variables</dt>
<dd translate>The environment variables in comma separated KEY=VALUE pairs</dd> <dd translate>The environment variables in comma separated KEY=VALUE pairs</dd>
<dt translate>Enable Interactive Mode</dt> <dt translate>Enable Interactive Mode</dt>
<dd translate>Allocate pseudo-TTY and keep STDIN open even if not attatched. This also enables Web console in console tab on details view.</dd> <dd translate>Allocate pseudo-TTY and keep STDIN open even if not attached. This also enables Web console in console tab on details view.</dd>
<dt translate>Auto remove</dt>
<dd translate>Automatically remove the container when it exits</dd>
</dl> </dl>

View File

@ -5,4 +5,6 @@
<dd translate>The container memory size in MiB.</dd> <dd translate>The container memory size in MiB.</dd>
<dt translate>Restart Policy</dt> <dt translate>Restart Policy</dt>
<dd translate>Restart policy to apply when a container exits.</dd> <dd translate>Restart policy to apply when a container exits.</dd>
<dt translate>Restart Policy</dt>
<dd translate>The runtime to use for this container. Default: "runc"</dd>
</dl> </dl>

View File

@ -51,6 +51,10 @@
{value: "always", name: gettext("Always")}, {value: "always", name: gettext("Always")},
{value: "unless-stopped", name: gettext("Unless Stopped")} {value: "unless-stopped", name: gettext("Unless Stopped")}
]; ];
var runtimes = [
{value: "", name: gettext("Select runtime.")},
{value: "runc", name: gettext("runc")}
];
// schema // schema
schema = { schema = {
@ -92,6 +96,10 @@
type: "number", type: "number",
minimum: 4 minimum: 4
}, },
hostname: {
title: gettext("Hostname"),
type: "string"
},
restart_policy: { restart_policy: {
title: gettext("Restart Policy"), title: gettext("Restart Policy"),
type: "string" type: "string"
@ -101,6 +109,10 @@
type: "number", type: "number",
minimum: 0 minimum: 0
}, },
runtime: {
title: gettext("Runtime"),
type: "string"
},
// misc // misc
workdir: { workdir: {
title: gettext("Working Directory"), title: gettext("Working Directory"),
@ -114,6 +126,10 @@
title: gettext("Enable interactive mode"), title: gettext("Enable interactive mode"),
type: "boolean" type: "boolean"
}, },
auto_remove: {
title: gettext("Auto remove"),
type: "boolean"
},
// labels // labels
labels: { labels: {
title: gettext("Labels"), title: gettext("Labels"),
@ -183,8 +199,7 @@
}, },
{ {
key: "run", key: "run",
readonly: action === "update", readonly: action === "update"
condition: action === "update"
} }
] ]
} }
@ -199,12 +214,29 @@
{ {
type: "section", type: "section",
htmlClass: "col-xs-12", 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: [ items: [
{ {
key: "cpu", key: "cpu",
step: 0.1, step: 0.1,
placeholder: gettext("The number of virtual cpu for this container.") placeholder: gettext("The number of virtual cpu for this container.")
}
]
}, },
{
type: "section",
htmlClass: "col-xs-6",
items: [
{ {
key: "memory", key: "memory",
placeholder: gettext("The container memory size in MiB.") placeholder: gettext("The container memory size in MiB.")
@ -225,7 +257,7 @@
if (readonly) { if (readonly) {
model.restart_policy_max_retry = ""; 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 readonly: true
} }
] ]
},
{
type: "section",
htmlClass: "col-xs-6",
items: [
{
key: "runtime",
type: "select",
readonly: action === "update",
titleMap: runtimes
}
]
} }
] ]
}, },
@ -327,6 +371,10 @@
{ {
key: "interactive", key: "interactive",
readonly: action === "update" readonly: action === "update"
},
{
key: "auto_remove",
readonly: action === "update"
} }
] ]
} }
@ -387,10 +435,12 @@
command: "", command: "",
run: true, run: true,
// spec // spec
hostname: "",
cpu: "", cpu: "",
memory: "", memory: "",
restart_policy: "", restart_policy: "",
restart_policy_max_retry: "", restart_policy_max_retry: "",
runtime: "",
// networks // networks
networks: [], networks: [],
// ports // ports
@ -401,6 +451,7 @@
workdir: "", workdir: "",
environment: "", environment: "",
interactive: true, interactive: true,
auto_remove: false,
// labels // labels
labels: "", labels: "",
// hints // hints

View File

@ -143,6 +143,7 @@
function containerProperties() { function containerProperties() {
return { return {
'addresses': { label: gettext('Addresses'), filters: ['noValue', 'json'] }, 'addresses': { label: gettext('Addresses'), filters: ['noValue', 'json'] },
'auto_remove': { label: gettext('Auto Remove'), filters: ['yesno'] },
'command': { label: gettext('Command'), filters: ['noValue'] }, 'command': { label: gettext('Command'), filters: ['noValue'] },
'cpu': { label: gettext('CPU'), filters: ['noValue'] }, 'cpu': { label: gettext('CPU'), filters: ['noValue'] },
'environment': { label: gettext('Environment'), filters: ['noValue', 'json'] }, 'environment': { label: gettext('Environment'), filters: ['noValue', 'json'] },
@ -152,17 +153,18 @@
'image': {label: gettext('Image'), filters: ['noValue'] }, 'image': {label: gettext('Image'), filters: ['noValue'] },
'image_driver': {label: gettext('Image Driver'), filters: ['noValue'] }, 'image_driver': {label: gettext('Image Driver'), filters: ['noValue'] },
'image_pull_policy': {label: gettext('Image Pull Policy'), 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'] }, 'labels': {label: gettext('Labels'), filters: ['noValue', 'json'] },
'links': {label: gettext('Links'), filters: ['noValue', 'json'] }, 'links': {label: gettext('Links'), filters: ['noValue', 'json'] },
'memory': {label: gettext('Memory'), filters: ['noValue'] }, 'memory': {label: gettext('Memory'), filters: ['noValue'] },
'name': {label: gettext('Name'), filters: ['noName'] }, 'name': {label: gettext('Name'), filters: ['noName'] },
'ports': {label: gettext('Ports'), filters: ['noValue', 'json'] }, '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'] }, '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': {label: gettext('Status'), filters: ['noValue'] },
'status_detail': {label: gettext('Status Detail'), filters: ['noValue'] }, 'status_detail': {label: gettext('Status Detail'), filters: ['noValue'] },
'status_reason': {label: gettext('Status Reason'), filters: ['noValue'] }, 'status_reason': {label: gettext('Status Reason'), filters: ['noValue'] },
'interactive': {label: gettext('Interactive'), filters: ['yesno'] },
'task_state': {label: gettext('Task State'), filters: ['noValue'] }, 'task_state': {label: gettext('Task State'), filters: ['noValue'] },
'workdir': {label: gettext('Workdir'), filters: ['noValue'] } 'workdir': {label: gettext('Workdir'), filters: ['noValue'] }
}; };

View File

@ -19,7 +19,7 @@
cls="dl-horizontal" cls="dl-horizontal"
item="ctrl.container" item="ctrl.container"
property-groups="[['image', 'image_driver', 'image_pull_policy', property-groups="[['image', 'image_driver', 'image_pull_policy',
'cpu', 'memory', 'restart_policy', 'cpu', 'memory', 'restart_policy', 'runtime',
'hostname', 'addresses', 'ports', 'security_groups']]"> 'hostname', 'addresses', 'ports', 'security_groups']]">
</hz-resource-property-list> </hz-resource-property-list>
</div> </div>
@ -33,7 +33,7 @@
cls="dl-horizontal" cls="dl-horizontal"
item="ctrl.container" item="ctrl.container"
property-groups="[['host', 'workdir', 'environment', 'interactive', property-groups="[['host', 'workdir', 'environment', 'interactive',
'labels','links']]"> 'auto_remove', 'labels','links']]">
</hz-resource-property-list> </hz-resource-property-list>
</div> </div>
</div> </div>