From 55f5303572ebbe2ea1a91aae69e5a5ec8a4123d0 Mon Sep 17 00:00:00 2001 From: Adit Sarfaty Date: Thu, 8 Jun 2017 10:38:30 +0300 Subject: [PATCH] Extend client silent mode Allow resources get operations to be silent, and also not log the validate result warning if silent. The reason is that get actions are sometimes used in order to verify that the object does not exist, and so we do not want to log it. Change-Id: Ib32637da86e72ff22a7c5684a3f179b91f09406f --- vmware_nsxlib/v3/client.py | 20 +++++++++++--------- vmware_nsxlib/v3/utils.py | 4 ++-- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/vmware_nsxlib/v3/client.py b/vmware_nsxlib/v3/client.py index ee6843bb..45e51cb7 100644 --- a/vmware_nsxlib/v3/client.py +++ b/vmware_nsxlib/v3/client.py @@ -123,16 +123,17 @@ class RESTClient(object): raise error(manager='', operation=operation, details=result_msg, error_code=error_code) - def _validate_result(self, result, expected, operation): + def _validate_result(self, result, expected, operation, silent=False): if result.status_code not in expected: result_msg = result.json() if result.content else '' - LOG.warning("The HTTP request returned error code " - "%(result)s, whereas %(expected)s response " - "codes were expected. Response body %(body)s", - {'result': result.status_code, - 'expected': '/'.join([str(code) - for code in expected]), - 'body': result_msg}) + if not silent: + LOG.warning("The HTTP request returned error code " + "%(result)s, whereas %(expected)s response " + "codes were expected. Response body %(body)s", + {'result': result.status_code, + 'expected': '/'.join([str(code) + for code in expected]), + 'body': result_msg}) error_code = None if isinstance(result_msg, dict) and 'error_message' in result_msg: @@ -199,7 +200,8 @@ class RESTClient(object): self._validate_result( result, RESTClient._VERB_RESP_CODES[method.lower()], - _("%(verb)s %(url)s") % {'verb': method, 'url': request_url}) + _("%(verb)s %(url)s") % {'verb': method, 'url': request_url}, + silent=silent) return result diff --git a/vmware_nsxlib/v3/utils.py b/vmware_nsxlib/v3/utils.py index 1331bdb5..02bf5dc4 100644 --- a/vmware_nsxlib/v3/utils.py +++ b/vmware_nsxlib/v3/utils.py @@ -153,8 +153,8 @@ class NsxLibApiBase(object): def list(self): return self.client.list(self.uri_segment) - def get(self, uuid): - return self.client.get(self.get_path(uuid)) + def get(self, uuid, silent=False): + return self.client.get(self.get_path(uuid), silent=silent) def delete(self, uuid): return self.client.delete(self.get_path(uuid))