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

Support same reset actions on Managers as on Systems (#903)

* bring Manager power cmds to parity with System power commands

* add changelog fragment

* Update changelogs/fragments/903-enhance-redfish-manager-reset-actions.yml

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

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
Bill Dodd 2020-09-23 01:42:56 -05:00 committed by GitHub
parent 5e8b27a224
commit e382044e42
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 101 additions and 28 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- redfish_command - support same reset actions on Managers as on Systems (https://github.com/ansible-collections/community.general/issues/901).

View file

@ -710,24 +710,6 @@ class RedfishUtils(object):
def get_multi_volume_inventory(self): def get_multi_volume_inventory(self):
return self.aggregate_systems(self.get_volume_inventory) return self.aggregate_systems(self.get_volume_inventory)
def restart_manager_gracefully(self):
result = {}
key = "Actions"
# Search for 'key' entry and extract URI from it
response = self.get_request(self.root_uri + self.manager_uri)
if response['ret'] is False:
return response
result['ret'] = True
data = response['data']
action_uri = data[key]["#Manager.Reset"]["target"]
payload = {'ResetType': 'GracefulRestart'}
response = self.post_request(self.root_uri + action_uri, payload)
if response['ret'] is False:
return response
return {'ret': True}
def manage_indicator_led(self, command): def manage_indicator_led(self, command):
result = {} result = {}
key = 'IndicatorLED' key = 'IndicatorLED'
@ -773,6 +755,14 @@ class RedfishUtils(object):
return reset_type return reset_type
def manage_system_power(self, command): def manage_system_power(self, command):
return self.manage_power(command, self.systems_uri,
'#ComputerSystem.Reset')
def manage_manager_power(self, command):
return self.manage_power(command, self.manager_uri,
'#Manager.Reset')
def manage_power(self, command, resource_uri, action_name):
key = "Actions" key = "Actions"
reset_type_values = ['On', 'ForceOff', 'GracefulShutdown', reset_type_values = ['On', 'ForceOff', 'GracefulShutdown',
'GracefulRestart', 'ForceRestart', 'Nmi', 'GracefulRestart', 'ForceRestart', 'Nmi',
@ -790,8 +780,8 @@ class RedfishUtils(object):
if reset_type not in reset_type_values: if reset_type not in reset_type_values:
return {'ret': False, 'msg': 'Invalid Command (%s)' % command} return {'ret': False, 'msg': 'Invalid Command (%s)' % command}
# read the system resource and get the current power state # read the resource and get the current power state
response = self.get_request(self.root_uri + self.systems_uri) response = self.get_request(self.root_uri + resource_uri)
if response['ret'] is False: if response['ret'] is False:
return response return response
data = response['data'] data = response['data']
@ -803,13 +793,13 @@ class RedfishUtils(object):
if power_state == "Off" and reset_type in ['GracefulShutdown', 'ForceOff']: if power_state == "Off" and reset_type in ['GracefulShutdown', 'ForceOff']:
return {'ret': True, 'changed': False} return {'ret': True, 'changed': False}
# get the #ComputerSystem.Reset Action and target URI # get the reset Action and target URI
if key not in data or '#ComputerSystem.Reset' not in data[key]: if key not in data or action_name not in data[key]:
return {'ret': False, 'msg': 'Action #ComputerSystem.Reset not found'} return {'ret': False, 'msg': 'Action %s not found' % action_name}
reset_action = data[key]['#ComputerSystem.Reset'] reset_action = data[key][action_name]
if 'target' not in reset_action: if 'target' not in reset_action:
return {'ret': False, return {'ret': False,
'msg': 'target URI missing from Action #ComputerSystem.Reset'} 'msg': 'target URI missing from Action %s' % action_name}
action_uri = reset_action['target'] action_uri = reset_action['target']
# get AllowableValues # get AllowableValues

View file

@ -206,6 +206,36 @@ EXAMPLES = '''
username: "{{ username }}" username: "{{ username }}"
password: "{{ password }}" password: "{{ password }}"
- name: Turn system power off
community.general.redfish_command:
category: Systems
command: PowerForceOff
resource_id: 437XR1138R2
- name: Restart system power forcefully
community.general.redfish_command:
category: Systems
command: PowerForceRestart
resource_id: 437XR1138R2
- name: Shutdown system power gracefully
community.general.redfish_command:
category: Systems
command: PowerGracefulShutdown
resource_id: 437XR1138R2
- name: Turn system power on
community.general.redfish_command:
category: Systems
command: PowerOn
resource_id: 437XR1138R2
- name: Reboot system power
community.general.redfish_command:
category: Systems
command: PowerReboot
resource_id: 437XR1138R2
- name: Set one-time boot device to {{ bootdevice }} - name: Set one-time boot device to {{ bootdevice }}
community.general.redfish_command: community.general.redfish_command:
category: Systems category: Systems
@ -439,6 +469,51 @@ EXAMPLES = '''
virtual_media: virtual_media:
image_url: 'http://example.com/images/SomeLinux-current.iso' image_url: 'http://example.com/images/SomeLinux-current.iso'
resource_id: BMC resource_id: BMC
- name: Restart manager power gracefully
community.general.redfish_command:
category: Manager
command: GracefulRestart
resource_id: BMC
baseuri: "{{ baseuri }}"
username: "{{ username }}"
password: "{{ password }}"
- name: Restart manager power gracefully
community.general.redfish_command:
category: Manager
command: PowerGracefulRestart
resource_id: BMC
- name: Turn manager power off
community.general.redfish_command:
category: Manager
command: PowerForceOff
resource_id: BMC
- name: Restart manager power forcefully
community.general.redfish_command:
category: Manager
command: PowerForceRestart
resource_id: BMC
- name: Shutdown manager power gracefully
community.general.redfish_command:
category: Manager
command: PowerGracefulShutdown
resource_id: BMC
- name: Turn manager power on
community.general.redfish_command:
category: Manager
command: PowerOn
resource_id: BMC
- name: Reboot manager power
community.general.redfish_command:
category: Manager
command: PowerReboot
resource_id: BMC
''' '''
RETURN = ''' RETURN = '''
@ -464,7 +539,8 @@ CATEGORY_COMMANDS_ALL = {
"UpdateAccountServiceProperties"], "UpdateAccountServiceProperties"],
"Sessions": ["ClearSessions"], "Sessions": ["ClearSessions"],
"Manager": ["GracefulRestart", "ClearLogs", "VirtualMediaInsert", "Manager": ["GracefulRestart", "ClearLogs", "VirtualMediaInsert",
"VirtualMediaEject"], "VirtualMediaEject", "PowerOn", "PowerForceOff", "PowerForceRestart",
"PowerGracefulRestart", "PowerGracefulShutdown", "PowerReboot"],
"Update": ["SimpleUpdate"] "Update": ["SimpleUpdate"]
} }
@ -598,7 +674,7 @@ def main():
module.fail_json(msg=to_native(result['msg'])) module.fail_json(msg=to_native(result['msg']))
for command in command_list: for command in command_list:
if "Power" in command: if command.startswith('Power'):
result = rf_utils.manage_system_power(command) result = rf_utils.manage_system_power(command)
elif command == "SetOneTimeBoot": elif command == "SetOneTimeBoot":
boot_opts['override_enabled'] = 'Once' boot_opts['override_enabled'] = 'Once'
@ -643,8 +719,13 @@ def main():
module.fail_json(msg=to_native(result['msg'])) module.fail_json(msg=to_native(result['msg']))
for command in command_list: for command in command_list:
# standardize on the Power* commands, but allow the the legacy
# GracefulRestart command
if command == 'GracefulRestart': if command == 'GracefulRestart':
result = rf_utils.restart_manager_gracefully() command = 'PowerGracefulRestart'
if command.startswith('Power'):
result = rf_utils.manage_manager_power(command)
elif command == 'ClearLogs': elif command == 'ClearLogs':
result = rf_utils.clear_logs() result = rf_utils.clear_logs()
elif command == 'VirtualMediaInsert': elif command == 'VirtualMediaInsert':