Enable to rename container in update action
This patch enables to rename container in update action. Change-Id: I2c58d65355965f512ff89ba0b689d735b7f36522
This commit is contained in:
parent
6ab8f75e59
commit
f42c24e1e8
@ -50,6 +50,10 @@ def _cleanup_params(attrs, check, **params):
|
|||||||
for (key, value) in params.items():
|
for (key, value) in params.items():
|
||||||
if key == "run":
|
if key == "run":
|
||||||
run = value
|
run = value
|
||||||
|
elif key == "cpu":
|
||||||
|
args["cpu"] = float(value)
|
||||||
|
elif key == "memory":
|
||||||
|
args["memory"] = int(value)
|
||||||
elif key == "interactive":
|
elif key == "interactive":
|
||||||
args["interactive"] = value
|
args["interactive"] = value
|
||||||
elif key == "restart_policy":
|
elif key == "restart_policy":
|
||||||
@ -72,6 +76,19 @@ def _cleanup_params(attrs, check, **params):
|
|||||||
return args, run
|
return args, run
|
||||||
|
|
||||||
|
|
||||||
|
def _delete_attributes_with_same_value(old, new):
|
||||||
|
'''Delete attributes with same value from new dict
|
||||||
|
|
||||||
|
If new dict has same value in old dict, remove the attributes
|
||||||
|
from new dict.
|
||||||
|
'''
|
||||||
|
for k in old.keys():
|
||||||
|
if k in new:
|
||||||
|
if old[k] == new[k]:
|
||||||
|
del new[k]
|
||||||
|
return new
|
||||||
|
|
||||||
|
|
||||||
def container_create(request, **kwargs):
|
def container_create(request, **kwargs):
|
||||||
args, run = _cleanup_params(CONTAINER_CREATE_ATTRS, True, **kwargs)
|
args, run = _cleanup_params(CONTAINER_CREATE_ATTRS, True, **kwargs)
|
||||||
response = None
|
response = None
|
||||||
@ -83,8 +100,32 @@ def container_create(request, **kwargs):
|
|||||||
|
|
||||||
|
|
||||||
def container_update(request, id, **kwargs):
|
def container_update(request, id, **kwargs):
|
||||||
|
'''Update Container
|
||||||
|
|
||||||
|
Get current Container attributes and check updates.
|
||||||
|
And update with "rename" for "name", then use "update" for
|
||||||
|
"cpu" and "memory".
|
||||||
|
'''
|
||||||
|
|
||||||
|
# get current data
|
||||||
|
container = zunclient(request).containers.get(id).to_dict()
|
||||||
|
if container["memory"] is not None:
|
||||||
|
container["memory"] = int(container["memory"].replace("M", ""))
|
||||||
args, run = _cleanup_params(CONTAINER_CREATE_ATTRS, True, **kwargs)
|
args, run = _cleanup_params(CONTAINER_CREATE_ATTRS, True, **kwargs)
|
||||||
return zunclient(request).containers.update(id, **args)
|
|
||||||
|
# remove same values from new params
|
||||||
|
_delete_attributes_with_same_value(container, args)
|
||||||
|
|
||||||
|
# do rename
|
||||||
|
name = args.pop("name", None)
|
||||||
|
if len(args):
|
||||||
|
zunclient(request).containers.update(id, **args)
|
||||||
|
|
||||||
|
# do update
|
||||||
|
if name:
|
||||||
|
zunclient(request).containers.rename(id, name)
|
||||||
|
args["name"] = name
|
||||||
|
return args
|
||||||
|
|
||||||
|
|
||||||
def container_delete(request, id, force=False):
|
def container_delete(request, id, force=False):
|
||||||
|
@ -52,10 +52,8 @@ class Container(generic.View):
|
|||||||
|
|
||||||
Returns the Container object on success.
|
Returns the Container object on success.
|
||||||
"""
|
"""
|
||||||
container = client.container_update(request, id, **request.DATA)
|
args = client.container_update(request, id, **request.DATA)
|
||||||
return rest_utils.CreatedResponse(
|
return args
|
||||||
'/api/zun/containers/%s' % id,
|
|
||||||
container.to_dict())
|
|
||||||
|
|
||||||
|
|
||||||
@urls.register
|
@urls.register
|
||||||
|
@ -121,7 +121,7 @@
|
|||||||
// only "cpu" and "memory" fields are editable.
|
// only "cpu" and "memory" fields are editable.
|
||||||
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 !== "cpu" && key !== "memory")) {
|
(key !== "name" && key !== "cpu" && key !== "memory")) {
|
||||||
delete model[key];
|
delete model[key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -135,8 +135,7 @@
|
|||||||
items: [
|
items: [
|
||||||
{
|
{
|
||||||
key: "name",
|
key: "name",
|
||||||
placeholder: gettext("Name of the container to create."),
|
placeholder: gettext("Name of the container to create.")
|
||||||
readonly: action === "update"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: "image",
|
key: "image",
|
||||||
|
Loading…
Reference in New Issue
Block a user