diff options
| author | Steve Lewis <stevelle@gmail.com> | 2015-03-10 13:10:37 -0700 |
|---|---|---|
| committer | Steve Lewis <stevelle@gmail.com> | 2015-03-12 15:18:20 -0700 |
| commit | f6f573316cfc2dd87ff7224590087e7f3be01b2e (patch) | |
| tree | a530629a80888352ec85b36ede9a02a7f2bd73a9 /glanceclient | |
| parent | 2858645cefe94e3ab33d95bb255a4e04113c83bc (diff) | |
| download | python-glanceclient-f6f573316cfc2dd87ff7224590087e7f3be01b2e.tar.gz | |
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
Diffstat (limited to 'glanceclient')
| -rw-r--r-- | glanceclient/v2/schemas.py | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/glanceclient/v2/schemas.py b/glanceclient/v2/schemas.py index 0dd2869..5c31741 100644 --- a/glanceclient/v2/schemas.py +++ b/glanceclient/v2/schemas.py @@ -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): |
