mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
modified redfish_config and idrac_redfish_config to skip incorrect attributes (#2334)
* modified redfish_config and idrac_redfish_config to skip incorrect attributes Signed-off-by: Trevor Squillario Trevor_Squillario@Dell.com * modified redfish_utils.py and idrac_redfish_config.py to return empty warning message * modified redfish_config.py and idrac_redfish_config.py to use module.warn() * updated changelog fragment for pr 2334
This commit is contained in:
parent
eea4f45965
commit
9d46ccf1b2
4 changed files with 47 additions and 12 deletions
|
@ -179,6 +179,7 @@ class IdracRedfishUtils(RedfishUtils):
|
|||
|
||||
attrs_to_patch = {}
|
||||
attrs_skipped = {}
|
||||
attrs_bad = {} # Store attrs which were not found in the system
|
||||
|
||||
# Search for key entry and extract URI from it
|
||||
response = self.get_request(self.root_uri + manager_uri + "/" + key)
|
||||
|
@ -189,13 +190,15 @@ class IdracRedfishUtils(RedfishUtils):
|
|||
|
||||
if key not in data:
|
||||
return {'ret': False,
|
||||
'msg': "%s: Key %s not found" % (command, key)}
|
||||
'msg': "%s: Key %s not found" % (command, key),
|
||||
'warning': ""}
|
||||
|
||||
for attr_name, attr_value in attributes.items():
|
||||
# Check if attribute exists
|
||||
if attr_name not in data[u'Attributes']:
|
||||
return {'ret': False,
|
||||
'msg': "%s: Manager attribute %s not found" % (command, attr_name)}
|
||||
# Skip and proceed to next attribute if this isn't valid
|
||||
attrs_bad.update({attr_name: attr_value})
|
||||
continue
|
||||
|
||||
# Find out if value is already set to what we want. If yes, exclude
|
||||
# those attributes
|
||||
|
@ -204,16 +207,23 @@ class IdracRedfishUtils(RedfishUtils):
|
|||
else:
|
||||
attrs_to_patch.update({attr_name: attr_value})
|
||||
|
||||
warning = ""
|
||||
if attrs_bad:
|
||||
warning = "Incorrect attributes %s" % (attrs_bad)
|
||||
|
||||
if not attrs_to_patch:
|
||||
return {'ret': True, 'changed': False,
|
||||
'msg': "Manager attributes already set"}
|
||||
'msg': "No changes made. Manager attributes already set.",
|
||||
'warning': warning}
|
||||
|
||||
payload = {"Attributes": attrs_to_patch}
|
||||
response = self.patch_request(self.root_uri + manager_uri + "/" + key, payload)
|
||||
if response['ret'] is False:
|
||||
return response
|
||||
|
||||
return {'ret': True, 'changed': True,
|
||||
'msg': "%s: Modified Manager attributes %s" % (command, attrs_to_patch)}
|
||||
'msg': "%s: Modified Manager attributes %s" % (command, attrs_to_patch),
|
||||
'warning': warning}
|
||||
|
||||
|
||||
CATEGORY_COMMANDS_ALL = {
|
||||
|
@ -221,6 +231,7 @@ CATEGORY_COMMANDS_ALL = {
|
|||
"SetSystemAttributes"]
|
||||
}
|
||||
|
||||
|
||||
# list of mutually exclusive commands for a category
|
||||
CATEGORY_COMMANDS_MUTUALLY_EXCLUSIVE = {
|
||||
"Manager": [["SetManagerAttributes", "SetLifecycleControllerAttributes",
|
||||
|
@ -308,6 +319,9 @@ def main():
|
|||
|
||||
# Return data back or fail with proper message
|
||||
if result['ret'] is True:
|
||||
if result.get('warning'):
|
||||
module.warn(to_native(result['warning']))
|
||||
|
||||
module.exit_json(changed=result['changed'], msg=to_native(result['msg']))
|
||||
else:
|
||||
module.fail_json(msg=to_native(result['msg']))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue