Apply expected patch format when updating tags in v2.images

Currently, glanceclient.v2.update builds a patch request that does not
match glance API.

This patch overrides the default behaviour to customize the patch
request with the right format for the API.

Co-Authored-By: Steve Lewis <steve.lewis@rackspace.com>
Fixes bug 1306774
Change-Id: If0739ac285da1e741bfa40b6c719331a5ce49319
This commit is contained in:
Steve Lewis
2015-03-10 13:10:37 -07:00
parent 2858645cef
commit f6f573316c
3 changed files with 57 additions and 6 deletions
+20 -2
View File
@@ -14,6 +14,7 @@
# under the License.
import copy
import json
import jsonpatch
import six
import warlock.model as warlock
@@ -29,18 +30,35 @@ class SchemaBasedModel(warlock.Model):
expects.
"""
def _make_custom_patch(self, new, original):
if not self.get('tags'):
tags_patch = []
else:
tags_patch = [{"path": "/tags",
"value": self.get('tags'),
"op": "replace"}]
patch_string = jsonpatch.make_patch(original, new).to_string()
patch = json.loads(patch_string)
if not patch:
return json.dumps(tags_patch)
else:
return json.dumps(patch + tags_patch)
@warlock.Model.patch.getter
def patch(self):
"""Return a jsonpatch object representing the delta."""
original = copy.deepcopy(self.__dict__['__original__'])
new = dict(self)
if self.__dict__['schema']:
if self.schema:
for (name, prop) in six.iteritems(self.schema['properties']):
if (name not in original and name in new and
prop.get('is_base', True)):
original[name] = None
return jsonpatch.make_patch(original, dict(self)).to_string()
original['tags'] = None
new['tags'] = None
return self._make_custom_patch(new, original)
class SchemaProperty(object):