mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Redfish: implementing ResetToDefaults (#8164)
Fixing #8163 Signed-off-by: Boris Glimcher <Boris.Glimcher@emc.com>
This commit is contained in:
parent
48b5a7a80a
commit
e4e091acca
3 changed files with 67 additions and 0 deletions
|
@ -0,0 +1,2 @@
|
|||
minor_changes:
|
||||
- redfish_command - add command ``ResetToDefaults`` to reset manager to default state (https://github.com/ansible-collections/community.general/issues/8163).
|
|
@ -1149,6 +1149,54 @@ class RedfishUtils(object):
|
|||
return response
|
||||
return {'ret': True, 'changed': True}
|
||||
|
||||
def manager_reset_to_defaults(self, command):
|
||||
return self.reset_to_defaults(command, self.manager_uri,
|
||||
'#Manager.ResetToDefaults')
|
||||
|
||||
def reset_to_defaults(self, command, resource_uri, action_name):
|
||||
key = "Actions"
|
||||
reset_type_values = ['ResetAll',
|
||||
'PreserveNetworkAndUsers',
|
||||
'PreserveNetwork']
|
||||
|
||||
if command not in reset_type_values:
|
||||
return {'ret': False, 'msg': 'Invalid Command (%s)' % command}
|
||||
|
||||
# read the resource and get the current power state
|
||||
response = self.get_request(self.root_uri + resource_uri)
|
||||
if response['ret'] is False:
|
||||
return response
|
||||
data = response['data']
|
||||
|
||||
# get the reset Action and target URI
|
||||
if key not in data or action_name not in data[key]:
|
||||
return {'ret': False, 'msg': 'Action %s not found' % action_name}
|
||||
reset_action = data[key][action_name]
|
||||
if 'target' not in reset_action:
|
||||
return {'ret': False,
|
||||
'msg': 'target URI missing from Action %s' % action_name}
|
||||
action_uri = reset_action['target']
|
||||
|
||||
# get AllowableValues
|
||||
ai = self._get_all_action_info_values(reset_action)
|
||||
allowable_values = ai.get('ResetType', {}).get('AllowableValues', [])
|
||||
|
||||
# map ResetType to an allowable value if needed
|
||||
if allowable_values and command not in allowable_values:
|
||||
return {'ret': False,
|
||||
'msg': 'Specified reset type (%s) not supported '
|
||||
'by service. Supported types: %s' %
|
||||
(command, allowable_values)}
|
||||
|
||||
# define payload
|
||||
payload = {'ResetType': command}
|
||||
|
||||
# POST to Action URI
|
||||
response = self.post_request(self.root_uri + action_uri, payload)
|
||||
if response['ret'] is False:
|
||||
return response
|
||||
return {'ret': True, 'changed': True}
|
||||
|
||||
def _find_account_uri(self, username=None, acct_id=None):
|
||||
if not any((username, acct_id)):
|
||||
return {'ret': False, 'msg':
|
||||
|
|
|
@ -281,6 +281,12 @@ options:
|
|||
- BIOS attributes that needs to be verified in the given server.
|
||||
type: dict
|
||||
version_added: 6.4.0
|
||||
reset_to_defaults_mode:
|
||||
description:
|
||||
- Mode to apply when reseting to default.
|
||||
type: str
|
||||
choices: [ ResetAll, PreserveNetworkAndUsers, PreserveNetwork ]
|
||||
version_added: 8.6.0
|
||||
|
||||
author:
|
||||
- "Jose Delarosa (@jose-delarosa)"
|
||||
|
@ -714,6 +720,13 @@ EXAMPLES = '''
|
|||
command: PowerReboot
|
||||
resource_id: BMC
|
||||
|
||||
- name: Factory reset manager to defaults
|
||||
community.general.redfish_command:
|
||||
category: Manager
|
||||
command: ResetToDefaults
|
||||
resource_id: BMC
|
||||
reset_to_defaults_mode: ResetAll
|
||||
|
||||
- name: Verify BIOS attributes
|
||||
community.general.redfish_command:
|
||||
category: Systems
|
||||
|
@ -764,6 +777,7 @@ CATEGORY_COMMANDS_ALL = {
|
|||
"UpdateAccountServiceProperties"],
|
||||
"Sessions": ["ClearSessions", "CreateSession", "DeleteSession"],
|
||||
"Manager": ["GracefulRestart", "ClearLogs", "VirtualMediaInsert",
|
||||
"ResetToDefaults",
|
||||
"VirtualMediaEject", "PowerOn", "PowerForceOff", "PowerForceRestart",
|
||||
"PowerGracefulRestart", "PowerGracefulShutdown", "PowerReboot"],
|
||||
"Update": ["SimpleUpdate", "MultipartHTTPPushUpdate", "PerformRequestedOperations"],
|
||||
|
@ -825,6 +839,7 @@ def main():
|
|||
)
|
||||
),
|
||||
strip_etag_quotes=dict(type='bool', default=False),
|
||||
reset_to_defaults_mode=dict(choices=['ResetAll', 'PreserveNetworkAndUsers', 'PreserveNetwork']),
|
||||
bios_attributes=dict(type="dict")
|
||||
),
|
||||
required_together=[
|
||||
|
@ -1017,6 +1032,8 @@ def main():
|
|||
result = rf_utils.virtual_media_insert(virtual_media, category)
|
||||
elif command == 'VirtualMediaEject':
|
||||
result = rf_utils.virtual_media_eject(virtual_media, category)
|
||||
elif command == 'ResetToDefaults':
|
||||
result = rf_utils.manager_reset_to_defaults(module.params['reset_to_defaults_mode'])
|
||||
|
||||
elif category == "Update":
|
||||
# execute only if we find UpdateService resources
|
||||
|
|
Loading…
Reference in a new issue