From 3152321c7ab8be1828432a0c39083db05dd6a355 Mon Sep 17 00:00:00 2001 From: "Ryan S. Brown" Date: Thu, 3 Mar 2016 12:57:16 -0500 Subject: [PATCH] Support PATCH of queue metadata This patch adds support to the v1.1 and v2 API for PATCH to update queue metadata. Depends on server support for PATCH waiting to be merged here https://review.openstack.org/#/c/280941/ Change-Id: I9dec8ab8b3f99d48b4a42fde6244d38038e4662f Depends-On: Iba6d7a0ca5cf7a755c20d9af69d5c52687142dff --- zaqarclient/queues/v1/api.py | 9 +++++++++ zaqarclient/queues/v1/core.py | 25 +++++++++++++++++++++++++ zaqarclient/queues/v1/queues.py | 5 ++++- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/zaqarclient/queues/v1/api.py b/zaqarclient/queues/v1/api.py index d111ea30..3e560982 100644 --- a/zaqarclient/queues/v1/api.py +++ b/zaqarclient/queues/v1/api.py @@ -294,6 +294,15 @@ V1_1.schema.update({ } }, + 'queue_update': { + 'ref': 'queues/{queue_name}', + 'method': 'PATCH', + 'required': ['queue_name'], + 'properties': { + 'queue_name': {'type': 'string'} + } + }, + 'message_pop': { 'ref': 'queues/{queue_name}/messages', 'method': 'DELETE', diff --git a/zaqarclient/queues/v1/core.py b/zaqarclient/queues/v1/core.py index 22026aa0..cefb80b2 100644 --- a/zaqarclient/queues/v1/core.py +++ b/zaqarclient/queues/v1/core.py @@ -80,6 +80,31 @@ def queue_create(transport, request, name, return resp.deserialized_content +def queue_update(transport, request, name, metadata, callback=None): + """Updates a queue's metadata using PATCH. API v1.1+ only + + :param transport: Transport instance to use + :type transport: `transport.base.Transport` + :param request: Request instance ready to be sent. + :type request: `transport.request.Request` + :param name: Queue reference name. + :type name: `six.text_type` + :param metadata: Queue's metadata object. (>=v1.1) + :type metadata: `dict` + :param callback: Optional callable to use as callback. + If specified, this request will be sent asynchronously. + (IGNORED UNTIL ASYNC SUPPORT IS COMPLETE) + :type callback: Callable object. + """ + + request.operation = 'queue_update' + request.params['queue_name'] = name + request.content = json.dumps(metadata) + + resp = transport.send(request) + return resp.deserialized_content + + def queue_exists(transport, request, name, callback=None): """Checks if the queue exists.""" try: diff --git a/zaqarclient/queues/v1/queues.py b/zaqarclient/queues/v1/queues.py index a45a1fe2..e9e72461 100644 --- a/zaqarclient/queues/v1/queues.py +++ b/zaqarclient/queues/v1/queues.py @@ -97,8 +97,11 @@ class Queue(object): if new_meta is not None: if self.client.api_version < 1.1: core.queue_set_metadata(trans, req, self._name, new_meta) - else: + elif not len(new_meta): + # if metadata is empty dict, clear existing metadata core.queue_create(trans, req, self._name, metadata=new_meta) + else: + core.queue_update(trans, req, self._name, metadata=new_meta) self._metadata = new_meta # TODO(flaper87): Cache with timeout