1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

redfish: clean etag of quotes before patch (#3296)

* Some vendors surround header etag with quotes, which need to be cleaned before sending a patch

* Minor change fragment

* Add etag strip quote option

* Rebase

* Cleanup fragment

* Apply suggestions from code review

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/remote_management/redfish/redfish_command.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Description update

* Update plugins/modules/remote_management/redfish/redfish_config.py

Co-authored-by: Felix Fontein <felix@fontein.de>

Co-authored-by: Kyle Williams <kyle.williams@thetradedesk.com>
Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
Kyle Williams 2021-09-01 14:59:27 -06:00 committed by GitHub
parent 7c493eb4e5
commit 3502f3b486
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 5 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- "redfish_command and redfish_config and redfish_utils module utils - add parameter to strip etag of quotes before patch, since some vendors do not properly ``If-Match`` etag with quotes (https://github.com/ansible-collections/community.general/pull/3296)."

View file

@ -29,7 +29,7 @@ FAIL_MSG = 'Issuing a data modification command without specifying the '\
class RedfishUtils(object):
def __init__(self, creds, root_uri, timeout, module, resource_id=None,
data_modification=False):
data_modification=False, strip_etag_quotes=False):
self.root_uri = root_uri
self.creds = creds
self.timeout = timeout
@ -37,6 +37,7 @@ class RedfishUtils(object):
self.service_root = '/redfish/v1/'
self.resource_id = resource_id
self.data_modification = data_modification
self.strip_etag_quotes = strip_etag_quotes
self._init_session()
def _auth_params(self, headers):
@ -121,6 +122,8 @@ class RedfishUtils(object):
if not etag:
etag = r['data'].get('@odata.etag')
if etag:
if self.strip_etag_quotes:
etag = etag.strip('"')
req_headers['If-Match'] = etag
username, password, basic_auth = self._auth_params(req_headers)
try:

View file

@ -207,6 +207,15 @@ options:
description:
- The transfer method to use with the image
type: str
strip_etag_quotes:
description:
- Removes surrounding quotes of etag used in C(If-Match) header
of C(PATCH) requests.
- Only use this option to resolve bad vendor implementation where
C(If-Match) only matches the unquoted etag string.
type: bool
default: false
version_added: 3.7.0
author: "Jose Delarosa (@jose-delarosa)"
'''
@ -631,7 +640,8 @@ def main():
transfer_protocol_type=dict(),
transfer_method=dict(),
)
)
),
strip_etag_quotes=dict(type='bool', default=False),
),
required_together=[
('username', 'password'),
@ -686,10 +696,13 @@ def main():
# VirtualMedia options
virtual_media = module.params['virtual_media']
# Etag options
strip_etag_quotes = module.params['strip_etag_quotes']
# Build root URI
root_uri = "https://" + module.params['baseuri']
rf_utils = RedfishUtils(creds, root_uri, timeout, module,
resource_id=resource_id, data_modification=True)
resource_id=resource_id, data_modification=True, strip_etag_quotes=strip_etag_quotes)
# Check that Category is valid
if category not in CATEGORY_COMMANDS_ALL:

View file

@ -91,6 +91,15 @@ options:
- setting dict of EthernetInterface on OOB controller
type: dict
version_added: '0.2.0'
strip_etag_quotes:
description:
- Removes surrounding quotes of etag used in C(If-Match) header
of C(PATCH) requests.
- Only use this option to resolve bad vendor implementation where
C(If-Match) only matches the unquoted etag string.
type: bool
default: false
version_added: 3.7.0
author: "Jose Delarosa (@jose-delarosa)"
'''
@ -237,7 +246,8 @@ def main():
nic_config=dict(
type='dict',
default={}
)
),
strip_etag_quotes=dict(type='bool', default=False),
),
required_together=[
('username', 'password'),
@ -275,10 +285,13 @@ def main():
nic_addr = module.params['nic_addr']
nic_config = module.params['nic_config']
# Etag options
strip_etag_quotes = module.params['strip_etag_quotes']
# Build root URI
root_uri = "https://" + module.params['baseuri']
rf_utils = RedfishUtils(creds, root_uri, timeout, module,
resource_id=resource_id, data_modification=True)
resource_id=resource_id, data_modification=True, strip_etag_quotes=strip_etag_quotes)
# Check that Category is valid
if category not in CATEGORY_COMMANDS_ALL: