mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
redfish: Add If-Match ETag header to PATCH requests (#56150)
* add If-Match ETag header to PATCH requests * add changelog fragment * ensure header keys are lowercase * fix dict comprehension for python 2.6 and earlier
This commit is contained in:
parent
099917ddc8
commit
1a6b95a8f1
2 changed files with 17 additions and 2 deletions
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
bugfixes:
|
||||
- redfish_command - add If-Match etag header to Redfish PATCH requests (https://github.com/ansible/ansible/issues/56050)
|
|
@ -37,6 +37,7 @@ class RedfishUtils(object):
|
|||
follow_redirects='all',
|
||||
use_proxy=False, timeout=self.timeout)
|
||||
data = json.loads(resp.read())
|
||||
headers = dict((k.lower(), v) for (k, v) in resp.info().items())
|
||||
except HTTPError as e:
|
||||
msg = self._get_extended_message(e)
|
||||
return {'ret': False,
|
||||
|
@ -49,7 +50,7 @@ class RedfishUtils(object):
|
|||
except Exception as e:
|
||||
return {'ret': False,
|
||||
'msg': "Failed GET request to '%s': '%s'" % (uri, to_text(e))}
|
||||
return {'ret': True, 'data': data}
|
||||
return {'ret': True, 'data': data, 'headers': headers}
|
||||
|
||||
def post_request(self, uri, pyld):
|
||||
try:
|
||||
|
@ -75,9 +76,20 @@ class RedfishUtils(object):
|
|||
return {'ret': True, 'resp': resp}
|
||||
|
||||
def patch_request(self, uri, pyld):
|
||||
headers = PATCH_HEADERS
|
||||
r = self.get_request(uri)
|
||||
if r['ret']:
|
||||
# Get etag from etag header or @odata.etag property
|
||||
etag = r['headers'].get('etag')
|
||||
if not etag:
|
||||
etag = r['data'].get('@odata.etag')
|
||||
if etag:
|
||||
# Make copy of headers and add If-Match header
|
||||
headers = dict(headers)
|
||||
headers['If-Match'] = etag
|
||||
try:
|
||||
resp = open_url(uri, data=json.dumps(pyld),
|
||||
headers=PATCH_HEADERS, method="PATCH",
|
||||
headers=headers, method="PATCH",
|
||||
url_username=self.creds['user'],
|
||||
url_password=self.creds['pswd'],
|
||||
force_basic_auth=True, validate_certs=False,
|
||||
|
|
Loading…
Reference in a new issue