summaryrefslogtreecommitdiff
path: root/ironic/api/controllers/v1/node.py
diff options
context:
space:
mode:
authorLucas Alvares Gomes <lucasagomes@gmail.com>2013-09-12 16:04:57 +0100
committerLucas Alvares Gomes <lucasagomes@gmail.com>2013-09-16 19:21:26 +0100
commit0104db9bdd6240f72b8a1cf5d2f040a1f6d8b5b2 (patch)
tree989d8463ea23ce904677573c63941e61db6c2b5c /ironic/api/controllers/v1/node.py
parent33399cca3142b4474d87a7038698edd74e1b61d9 (diff)
downloadironic-0104db9bdd6240f72b8a1cf5d2f040a1f6d8b5b2.tar.gz
Update only the changed fields
When updating a resource do not update fields that haven't changed, it's causing obj_what_changed() method from objects to return untouched fields. Change-Id: I1ecebbddb0fe73b54f7044ebcc2f0f1d9fc66c87
Diffstat (limited to 'ironic/api/controllers/v1/node.py')
-rw-r--r--ironic/api/controllers/v1/node.py23
1 files changed, 14 insertions, 9 deletions
diff --git a/ironic/api/controllers/v1/node.py b/ironic/api/controllers/v1/node.py
index 5b00ff49e..1c0a7bd75 100644
--- a/ironic/api/controllers/v1/node.py
+++ b/ironic/api/controllers/v1/node.py
@@ -310,10 +310,6 @@ class NodesController(rest.RestController):
node = objects.Node.get_by_uuid(pecan.request.context, uuid)
node_dict = node.as_dict()
- # These are internal values that shouldn't be part of the patch
- internal_attrs = ['id', 'updated_at', 'created_at']
- [node_dict.pop(attr, None) for attr in internal_attrs]
-
utils.validate_patch(patch)
patch_obj = jsonpatch.JsonPatch(patch)
@@ -326,19 +322,28 @@ class NodesController(rest.RestController):
"nodes/%s/state interface.")
% uuid)
try:
- final_patch = jsonpatch.apply_patch(node_dict, patch_obj)
+ patched_node = jsonpatch.apply_patch(node_dict, patch_obj)
except jsonpatch.JsonPatchException as e:
LOG.exception(e)
raise wsme.exc.ClientSideError(_("Patching Error: %s") % e)
response = wsme.api.Response(Node(), status_code=200)
try:
- # In case of a remove operation, add the missing fields back to
- # the document with their default value
defaults = objects.Node.get_defaults()
- defaults.update(final_patch)
+ for key in defaults:
+ # Internal values that shouldn't be part of the patch
+ if key in ['id', 'updated_at', 'created_at']:
+ continue
+
+ # In case of a remove operation, add the missing fields back
+ # to the document with their default value
+ if key in node_dict and key not in patched_node:
+ patched_node[key] = defaults[key]
+
+ # Update only the fields that have changed
+ if node[key] != patched_node[key]:
+ node[key] = patched_node[key]
- node.update(defaults)
node = pecan.request.rpcapi.update_node(pecan.request.context,
node)
response.obj = node