mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Add IndicatorLED control commands to redfish_command module (#53752)
* Add Chassis commands IndicatorLedOn, IndicatorLedOff, and IndicatorLedBlink * Add manage_indicator_led function to redfish_utils * Add Chassis command category with IndicatorLedOn/Off/Blink commands to redfish_command * Add IndicatorLedBlink example to EXAMPLES docstring, and make the category == 'Chassis' section more generic for future development
This commit is contained in:
parent
eebebb1a83
commit
31b02fdd58
2 changed files with 51 additions and 0 deletions
|
@ -438,6 +438,32 @@ class RedfishUtils(object):
|
||||||
return response
|
return response
|
||||||
return {'ret': True}
|
return {'ret': True}
|
||||||
|
|
||||||
|
def manage_indicator_led(self, command):
|
||||||
|
result = {}
|
||||||
|
key = 'IndicatorLED'
|
||||||
|
|
||||||
|
payloads = {'IndicatorLedOn': 'Lit', 'IndicatorLedOff': 'Off', "IndicatorLedBlink": 'Blinking'}
|
||||||
|
|
||||||
|
result = {}
|
||||||
|
for chassis_uri in self.chassis_uri_list:
|
||||||
|
response = self.get_request(self.root_uri + chassis_uri)
|
||||||
|
if response['ret'] is False:
|
||||||
|
return response
|
||||||
|
result['ret'] = True
|
||||||
|
data = response['data']
|
||||||
|
if key not in data:
|
||||||
|
return {'ret': False, 'msg': "Key %s not found" % key}
|
||||||
|
|
||||||
|
if command in payloads.keys():
|
||||||
|
payload = {'IndicatorLED': payloads[command]}
|
||||||
|
response = self.patch_request(self.root_uri + chassis_uri, payload, HEADERS)
|
||||||
|
if response['ret'] is False:
|
||||||
|
return response
|
||||||
|
else:
|
||||||
|
return {'ret': False, 'msg': 'Invalid command'}
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
def manage_system_power(self, command):
|
def manage_system_power(self, command):
|
||||||
result = {}
|
result = {}
|
||||||
key = "Actions"
|
key = "Actions"
|
||||||
|
|
|
@ -96,6 +96,14 @@ EXAMPLES = '''
|
||||||
username: "{{ username }}"
|
username: "{{ username }}"
|
||||||
password: "{{ password }}"
|
password: "{{ password }}"
|
||||||
|
|
||||||
|
- name: Set chassis indicator LED to blink
|
||||||
|
redfish_command:
|
||||||
|
category: Chassis
|
||||||
|
command: IndicatorLedBlink
|
||||||
|
baseuri: "{{ baseuri }}"
|
||||||
|
username: "{{ username }}"
|
||||||
|
password: "{{ password }}"
|
||||||
|
|
||||||
- name: Add and enable user
|
- name: Add and enable user
|
||||||
redfish_command:
|
redfish_command:
|
||||||
category: Accounts
|
category: Accounts
|
||||||
|
@ -154,6 +162,7 @@ from ansible.module_utils._text import to_native
|
||||||
CATEGORY_COMMANDS_ALL = {
|
CATEGORY_COMMANDS_ALL = {
|
||||||
"Systems": ["PowerOn", "PowerForceOff", "PowerGracefulRestart",
|
"Systems": ["PowerOn", "PowerForceOff", "PowerGracefulRestart",
|
||||||
"PowerGracefulShutdown", "PowerReboot", "SetOneTimeBoot"],
|
"PowerGracefulShutdown", "PowerReboot", "SetOneTimeBoot"],
|
||||||
|
"Chassis": ["IndicatorLedOn", "IndicatorLedOff", "IndicatorLedBlink"],
|
||||||
"Accounts": ["AddUser", "EnableUser", "DeleteUser", "DisableUser",
|
"Accounts": ["AddUser", "EnableUser", "DeleteUser", "DisableUser",
|
||||||
"UpdateUserRole", "UpdateUserPassword"],
|
"UpdateUserRole", "UpdateUserPassword"],
|
||||||
"Manager": ["GracefulRestart", "ClearLogs"],
|
"Manager": ["GracefulRestart", "ClearLogs"],
|
||||||
|
@ -241,6 +250,22 @@ def main():
|
||||||
elif command == "SetOneTimeBoot":
|
elif command == "SetOneTimeBoot":
|
||||||
result = rf_utils.set_one_time_boot_device(module.params['bootdevice'])
|
result = rf_utils.set_one_time_boot_device(module.params['bootdevice'])
|
||||||
|
|
||||||
|
elif category == "Chassis":
|
||||||
|
result = rf_utils._find_chassis_resource(rf_uri)
|
||||||
|
if result['ret'] is False:
|
||||||
|
module.fail_json(msg=to_native(result['msg']))
|
||||||
|
|
||||||
|
led_commands = ["IndicatorLedOn", "IndicatorLedOff", "IndicatorLedBlink"]
|
||||||
|
|
||||||
|
# Check if more than one led_command is present
|
||||||
|
num_led_commands = sum([command in led_commands for command in command_list])
|
||||||
|
if num_led_commands > 1:
|
||||||
|
result = {'ret': False, 'msg': "Only one IndicatorLed command should be sent at a time."}
|
||||||
|
else:
|
||||||
|
for command in command_list:
|
||||||
|
if command in led_commands:
|
||||||
|
result = rf_utils.manage_indicator_led(command)
|
||||||
|
|
||||||
elif category == "Manager":
|
elif category == "Manager":
|
||||||
MANAGER_COMMANDS = {
|
MANAGER_COMMANDS = {
|
||||||
"GracefulRestart": rf_utils.restart_manager_gracefully,
|
"GracefulRestart": rf_utils.restart_manager_gracefully,
|
||||||
|
|
Loading…
Reference in a new issue