mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-14 07:55:05 +00:00
Reformat everything.
This commit is contained in:
parent
3f2213791a
commit
340ff8586d
1008 changed files with 61301 additions and 58309 deletions
|
|
@ -98,12 +98,14 @@ return_values:
|
|||
|
||||
import re
|
||||
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,
|
||||
)
|
||||
from ansible.module_utils.common.text.converters import to_native
|
||||
|
||||
|
||||
class IdracRedfishUtils(RedfishUtils):
|
||||
|
||||
def create_bios_config_job(self):
|
||||
result = {}
|
||||
key = "Bios"
|
||||
|
|
@ -111,42 +113,36 @@ class IdracRedfishUtils(RedfishUtils):
|
|||
|
||||
# Search for 'key' entry and extract URI from it
|
||||
response = self.get_request(self.root_uri + self.systems_uris[0])
|
||||
if response['ret'] is False:
|
||||
if response["ret"] is False:
|
||||
return response
|
||||
result['ret'] = True
|
||||
data = response['data']
|
||||
result["ret"] = True
|
||||
data = response["data"]
|
||||
|
||||
if key not in data:
|
||||
return {'ret': False, 'msg': f"Key {key} not found"}
|
||||
return {"ret": False, "msg": f"Key {key} not found"}
|
||||
|
||||
bios_uri = data[key]["@odata.id"]
|
||||
|
||||
# Extract proper URI
|
||||
response = self.get_request(self.root_uri + bios_uri)
|
||||
if response['ret'] is False:
|
||||
if response["ret"] is False:
|
||||
return response
|
||||
result['ret'] = True
|
||||
data = response['data']
|
||||
set_bios_attr_uri = data["@Redfish.Settings"]["SettingsObject"][
|
||||
"@odata.id"]
|
||||
result["ret"] = True
|
||||
data = response["data"]
|
||||
set_bios_attr_uri = data["@Redfish.Settings"]["SettingsObject"]["@odata.id"]
|
||||
|
||||
payload = {"TargetSettingsURI": set_bios_attr_uri}
|
||||
response = self.post_request(
|
||||
f"{self.root_uri}{self.manager_uri}/{jobs}", payload)
|
||||
if response['ret'] is False:
|
||||
response = self.post_request(f"{self.root_uri}{self.manager_uri}/{jobs}", payload)
|
||||
if response["ret"] is False:
|
||||
return response
|
||||
|
||||
response_output = response['resp'].__dict__
|
||||
response_output = response["resp"].__dict__
|
||||
job_id_full = response_output["headers"]["Location"]
|
||||
job_id = re.search("JID_.+", job_id_full).group()
|
||||
return {'ret': True, 'msg': f"Config job {job_id} created", 'job_id': job_id_full}
|
||||
return {"ret": True, "msg": f"Config job {job_id} created", "job_id": job_id_full}
|
||||
|
||||
|
||||
CATEGORY_COMMANDS_ALL = {
|
||||
"Systems": ["CreateBiosConfigJob"],
|
||||
"Accounts": [],
|
||||
"Manager": []
|
||||
}
|
||||
CATEGORY_COMMANDS_ALL = {"Systems": ["CreateBiosConfigJob"], "Accounts": [], "Manager": []}
|
||||
|
||||
|
||||
def main():
|
||||
|
|
@ -154,57 +150,58 @@ def main():
|
|||
return_values = {}
|
||||
argument_spec = dict(
|
||||
category=dict(required=True),
|
||||
command=dict(required=True, type='list', elements='str'),
|
||||
command=dict(required=True, 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=10),
|
||||
resource_id=dict()
|
||||
timeout=dict(type="int", default=10),
|
||||
resource_id=dict(),
|
||||
)
|
||||
argument_spec.update(REDFISH_COMMON_ARGUMENT_SPEC)
|
||||
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=False
|
||||
supports_check_mode=False,
|
||||
)
|
||||
|
||||
category = module.params['category']
|
||||
command_list = module.params['command']
|
||||
category = module.params["category"]
|
||||
command_list = module.params["command"]
|
||||
|
||||
# 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"]
|
||||
|
||||
# System, Manager or Chassis ID to modify
|
||||
resource_id = module.params['resource_id']
|
||||
resource_id = module.params["resource_id"]
|
||||
|
||||
# Build root URI
|
||||
root_uri = f"https://{module.params['baseuri']}"
|
||||
rf_utils = IdracRedfishUtils(creds, root_uri, timeout, module,
|
||||
resource_id=resource_id, data_modification=True)
|
||||
rf_utils = IdracRedfishUtils(creds, root_uri, timeout, module, resource_id=resource_id, data_modification=True)
|
||||
|
||||
# Check that Category is valid
|
||||
if category not in CATEGORY_COMMANDS_ALL:
|
||||
module.fail_json(msg=to_native(f"Invalid Category '{category}'. Valid Categories = {list(CATEGORY_COMMANDS_ALL.keys())}"))
|
||||
module.fail_json(
|
||||
msg=to_native(f"Invalid Category '{category}'. Valid Categories = {list(CATEGORY_COMMANDS_ALL.keys())}")
|
||||
)
|
||||
|
||||
# Check that all commands are valid
|
||||
for cmd in command_list:
|
||||
# Fail if even one command given is invalid
|
||||
if cmd not in CATEGORY_COMMANDS_ALL[category]:
|
||||
module.fail_json(msg=to_native(f"Invalid Command '{cmd}'. Valid Commands = {CATEGORY_COMMANDS_ALL[category]}"))
|
||||
module.fail_json(
|
||||
msg=to_native(f"Invalid Command '{cmd}'. Valid Commands = {CATEGORY_COMMANDS_ALL[category]}")
|
||||
)
|
||||
|
||||
# Organize by Categories / Commands
|
||||
|
||||
|
|
@ -224,26 +221,26 @@ def main():
|
|||
rf_utils.data_modification = False
|
||||
result = rf_utils._find_systems_resource()
|
||||
rf_utils.data_modification = True
|
||||
if result['ret'] is False:
|
||||
module.fail_json(msg=to_native(result['msg']))
|
||||
if result["ret"] is False:
|
||||
module.fail_json(msg=to_native(result["msg"]))
|
||||
|
||||
for command in command_list:
|
||||
if command == "CreateBiosConfigJob":
|
||||
# execute only if we find a Managers resource
|
||||
result = rf_utils._find_managers_resource()
|
||||
if result['ret'] is False:
|
||||
module.fail_json(msg=to_native(result['msg']))
|
||||
if result["ret"] is False:
|
||||
module.fail_json(msg=to_native(result["msg"]))
|
||||
result = rf_utils.create_bios_config_job()
|
||||
if 'job_id' in result:
|
||||
return_values['job_id'] = result['job_id']
|
||||
if "job_id" in result:
|
||||
return_values["job_id"] = result["job_id"]
|
||||
|
||||
# Return data back or fail with proper message
|
||||
if result['ret'] is True:
|
||||
del result['ret']
|
||||
module.exit_json(changed=True, msg='Action was successful', return_values=return_values)
|
||||
if result["ret"] is True:
|
||||
del result["ret"]
|
||||
module.exit_json(changed=True, msg="Action was successful", return_values=return_values)
|
||||
else:
|
||||
module.fail_json(msg=to_native(result['msg']))
|
||||
module.fail_json(msg=to_native(result["msg"]))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue