intersight_rest_api module and integration tests. (#52430)

* intersight_rest_api module and integration tests.
Fix intersight module_utils issues when using POST/PATCH/DELETE.

* Update json returns based on code review
This commit is contained in:
David Soper 2019-02-19 09:40:40 -06:00 committed by Dag Wieers
commit 63ea76d174
4 changed files with 412 additions and 2 deletions

View file

@ -186,11 +186,13 @@ class IntersightModule():
try:
response, info = self.intersight_call(**options)
if not re.match(r'2..', str(info['status'])):
raise RuntimeError(info['status'], info['msg'])
raise RuntimeError(info['status'], info['msg'], info['body'])
except Exception as e:
self.module.fail_json(msg="API error: %s " % str(e))
return json.loads(response.read())
if response.length > 0:
return json.loads(response.read())
return {}
def intersight_call(self, http_method="", resource_path="", query_params=None, body=None, moid=None, name=None):
"""
@ -278,6 +280,7 @@ class IntersightModule():
# Generate the HTTP requests header
request_header = {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Host': '{0}'.format(target_host),
'Date': '{0}'.format(cdate),
'Digest': 'SHA-256={0}'.format(b64_body_digest.decode('ascii')),