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
This commit is contained in:
parent
667beecf9a
commit
55f5303572
@ -123,9 +123,10 @@ class RESTClient(object):
|
|||||||
raise error(manager='', operation=operation, details=result_msg,
|
raise error(manager='', operation=operation, details=result_msg,
|
||||||
error_code=error_code)
|
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:
|
if result.status_code not in expected:
|
||||||
result_msg = result.json() if result.content else ''
|
result_msg = result.json() if result.content else ''
|
||||||
|
if not silent:
|
||||||
LOG.warning("The HTTP request returned error code "
|
LOG.warning("The HTTP request returned error code "
|
||||||
"%(result)s, whereas %(expected)s response "
|
"%(result)s, whereas %(expected)s response "
|
||||||
"codes were expected. Response body %(body)s",
|
"codes were expected. Response body %(body)s",
|
||||||
@ -199,7 +200,8 @@ class RESTClient(object):
|
|||||||
|
|
||||||
self._validate_result(
|
self._validate_result(
|
||||||
result, RESTClient._VERB_RESP_CODES[method.lower()],
|
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
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
@ -153,8 +153,8 @@ class NsxLibApiBase(object):
|
|||||||
def list(self):
|
def list(self):
|
||||||
return self.client.list(self.uri_segment)
|
return self.client.list(self.uri_segment)
|
||||||
|
|
||||||
def get(self, uuid):
|
def get(self, uuid, silent=False):
|
||||||
return self.client.get(self.get_path(uuid))
|
return self.client.get(self.get_path(uuid), silent=silent)
|
||||||
|
|
||||||
def delete(self, uuid):
|
def delete(self, uuid):
|
||||||
return self.client.delete(self.get_path(uuid))
|
return self.client.delete(self.get_path(uuid))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user