1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-04-30 23:48:54 +00:00

Reformat everything.

This commit is contained in:
Felix Fontein 2025-11-01 12:08:41 +01:00
parent 3f2213791a
commit 340ff8586d
1008 changed files with 61301 additions and 58309 deletions

View file

@ -398,22 +398,52 @@ result:
"""
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.community.general.plugins.module_utils.redfish_utils import RedfishUtils, REDFISH_COMMON_ARGUMENT_SPEC
from ansible_collections.community.general.plugins.module_utils.redfish_utils import (
RedfishUtils,
REDFISH_COMMON_ARGUMENT_SPEC,
)
CATEGORY_COMMANDS_ALL = {
"Systems": ["GetSystemInventory", "GetPsuInventory", "GetCpuInventory",
"GetMemoryInventory", "GetNicInventory", "GetHealthReport",
"GetStorageControllerInventory", "GetDiskInventory", "GetVolumeInventory",
"GetBiosAttributes", "GetBootOrder", "GetBootOverride", "GetVirtualMedia", "GetBiosRegistries",
"GetPowerRestorePolicy"],
"Chassis": ["GetFanInventory", "GetPsuInventory", "GetChassisPower",
"GetChassisThermals", "GetChassisInventory", "GetHealthReport", "GetHPEThermalConfig", "GetHPEFanPercentMin"],
"Systems": [
"GetSystemInventory",
"GetPsuInventory",
"GetCpuInventory",
"GetMemoryInventory",
"GetNicInventory",
"GetHealthReport",
"GetStorageControllerInventory",
"GetDiskInventory",
"GetVolumeInventory",
"GetBiosAttributes",
"GetBootOrder",
"GetBootOverride",
"GetVirtualMedia",
"GetBiosRegistries",
"GetPowerRestorePolicy",
],
"Chassis": [
"GetFanInventory",
"GetPsuInventory",
"GetChassisPower",
"GetChassisThermals",
"GetChassisInventory",
"GetHealthReport",
"GetHPEThermalConfig",
"GetHPEFanPercentMin",
],
"Accounts": ["ListUsers", "GetAccountServiceConfig"],
"Sessions": ["GetSessions"],
"Update": ["GetFirmwareInventory", "GetFirmwareUpdateCapabilities", "GetSoftwareInventory",
"GetUpdateStatus"],
"Manager": ["GetManagerNicInventory", "GetVirtualMedia", "GetLogs", "GetNetworkProtocols",
"GetHealthReport", "GetHostInterfaces", "GetManagerInventory", "GetServiceIdentification"],
"Update": ["GetFirmwareInventory", "GetFirmwareUpdateCapabilities", "GetSoftwareInventory", "GetUpdateStatus"],
"Manager": [
"GetManagerNicInventory",
"GetVirtualMedia",
"GetLogs",
"GetNetworkProtocols",
"GetHealthReport",
"GetHostInterfaces",
"GetManagerInventory",
"GetServiceIdentification",
],
"Service": ["CheckAvailability"],
}
@ -432,13 +462,13 @@ def main():
result = {}
category_list = []
argument_spec = dict(
category=dict(type='list', elements='str', default=['Systems']),
command=dict(type='list', elements='str'),
category=dict(type="list", elements="str", default=["Systems"]),
command=dict(type="list", elements="str"),
baseuri=dict(required=True),
username=dict(),
password=dict(no_log=True),
auth_token=dict(no_log=True),
timeout=dict(type='int', default=60),
timeout=dict(type="int", default=60),
update_handle=dict(),
manager=dict(),
)
@ -446,56 +476,54 @@ def main():
module = AnsibleModule(
argument_spec,
required_together=[
('username', 'password'),
("username", "password"),
],
required_one_of=[
('username', 'auth_token'),
("username", "auth_token"),
],
mutually_exclusive=[
('username', 'auth_token'),
("username", "auth_token"),
],
supports_check_mode=True,
)
# admin credentials used for authentication
creds = {'user': module.params['username'],
'pswd': module.params['password'],
'token': module.params['auth_token']}
creds = {"user": module.params["username"], "pswd": module.params["password"], "token": module.params["auth_token"]}
# timeout
timeout = module.params['timeout']
timeout = module.params["timeout"]
# update handle
update_handle = module.params['update_handle']
update_handle = module.params["update_handle"]
# manager
manager = module.params['manager']
manager = module.params["manager"]
# Build root URI
root_uri = f"https://{module.params['baseuri']}"
rf_utils = RedfishUtils(creds, root_uri, timeout, module)
# Build Category list
if "all" in module.params['category']:
if "all" in module.params["category"]:
for entry in CATEGORY_COMMANDS_ALL:
category_list.append(entry)
else:
# one or more categories specified
category_list = module.params['category']
category_list = module.params["category"]
for category in category_list:
command_list = []
# Build Command list for each Category
if category in CATEGORY_COMMANDS_ALL:
if not module.params['command']:
if not module.params["command"]:
# True if we don't specify a command --> use default
command_list.append(CATEGORY_COMMANDS_DEFAULT[category])
elif "all" in module.params['command']:
elif "all" in module.params["command"]:
for entry in range(len(CATEGORY_COMMANDS_ALL[category])):
command_list.append(CATEGORY_COMMANDS_ALL[category][entry])
# one or more commands
else:
command_list = module.params['command']
command_list = module.params["command"]
# Verify that all commands are valid
for cmd in command_list:
# Fail if even one command given is invalid
@ -515,8 +543,8 @@ def main():
elif category == "Systems":
# execute only if we find a Systems resource
resource = rf_utils._find_systems_resource()
if resource['ret'] is False:
module.fail_json(msg=resource['msg'])
if resource["ret"] is False:
module.fail_json(msg=resource["msg"])
for command in command_list:
if command == "GetSystemInventory":
@ -551,8 +579,8 @@ def main():
elif category == "Chassis":
# execute only if we find Chassis resource
resource = rf_utils._find_chassis_resource()
if resource['ret'] is False:
module.fail_json(msg=resource['msg'])
if resource["ret"] is False:
module.fail_json(msg=resource["msg"])
for command in command_list:
if command == "GetFanInventory":
@ -575,8 +603,8 @@ def main():
elif category == "Accounts":
# execute only if we find an Account service resource
resource = rf_utils._find_accountservice_resource()
if resource['ret'] is False:
module.fail_json(msg=resource['msg'])
if resource["ret"] is False:
module.fail_json(msg=resource["msg"])
for command in command_list:
if command == "ListUsers":
@ -587,8 +615,8 @@ def main():
elif category == "Update":
# execute only if we find UpdateService resources
resource = rf_utils._find_updateservice_resource()
if resource['ret'] is False:
module.fail_json(msg=resource['msg'])
if resource["ret"] is False:
module.fail_json(msg=resource["msg"])
for command in command_list:
if command == "GetFirmwareInventory":
@ -603,8 +631,8 @@ def main():
elif category == "Sessions":
# execute only if we find SessionService resources
resource = rf_utils._find_sessionservice_resource()
if resource['ret'] is False:
module.fail_json(msg=resource['msg'])
if resource["ret"] is False:
module.fail_json(msg=resource["msg"])
for command in command_list:
if command == "GetSessions":
@ -613,8 +641,8 @@ def main():
elif category == "Manager":
# execute only if we find a Manager service resource
resource = rf_utils._find_managers_resource()
if resource['ret'] is False:
module.fail_json(msg=resource['msg'])
if resource["ret"] is False:
module.fail_json(msg=resource["msg"])
for command in command_list:
if command == "GetManagerNicInventory":
@ -638,5 +666,5 @@ def main():
module.exit_json(redfish_facts=result)
if __name__ == '__main__':
if __name__ == "__main__":
main()