1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-04-21 19:29:05 +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

@ -295,33 +295,44 @@ tags:
"""
from ansible_collections.community.general.plugins.module_utils.hwc_utils import (
Config, HwcClientException, HwcModule, are_different_dicts, build_path,
get_region, is_empty_value, navigate_value, wait_to_finish)
Config,
HwcClientException,
HwcModule,
are_different_dicts,
build_path,
get_region,
is_empty_value,
navigate_value,
wait_to_finish,
)
def build_module():
return HwcModule(
argument_spec=dict(
state=dict(default='present', choices=['present', 'absent'],
type='str'),
timeouts=dict(type='dict', options=dict(
create=dict(default='30m', type='str'),
update=dict(default='30m', type='str'),
delete=dict(default='30m', type='str'),
), default=dict()),
availability_zone=dict(type='str', required=True),
name=dict(type='str', required=True),
volume_type=dict(type='str', required=True),
backup_id=dict(type='str'),
description=dict(type='str'),
enable_full_clone=dict(type='bool'),
enable_scsi=dict(type='bool'),
enable_share=dict(type='bool'),
encryption_id=dict(type='str'),
enterprise_project_id=dict(type='str'),
image_id=dict(type='str'),
size=dict(type='int'),
snapshot_id=dict(type='str')
state=dict(default="present", choices=["present", "absent"], type="str"),
timeouts=dict(
type="dict",
options=dict(
create=dict(default="30m", type="str"),
update=dict(default="30m", type="str"),
delete=dict(default="30m", type="str"),
),
default=dict(),
),
availability_zone=dict(type="str", required=True),
name=dict(type="str", required=True),
volume_type=dict(type="str", required=True),
backup_id=dict(type="str"),
description=dict(type="str"),
enable_full_clone=dict(type="bool"),
enable_scsi=dict(type="bool"),
enable_share=dict(type="bool"),
encryption_id=dict(type="str"),
enterprise_project_id=dict(type="str"),
image_id=dict(type="str"),
size=dict(type="int"),
snapshot_id=dict(type="str"),
),
supports_check_mode=True,
)
@ -335,11 +346,11 @@ def main():
try:
_init(config)
is_exist = module.params.get('id')
is_exist = module.params.get("id")
result = None
changed = False
if module.params['state'] == 'present':
if module.params["state"] == "present":
if not is_exist:
if not module.check_mode:
create(config)
@ -358,12 +369,11 @@ def main():
result = build_state(inputv, resp, array_index)
set_readonly_options(inputv, result)
if are_different_dicts(inputv, result):
raise Exception("Update resource failed, "
"some attributes are not updated")
raise Exception("Update resource failed, some attributes are not updated")
changed = True
result['id'] = module.params.get('id')
result["id"] = module.params.get("id")
else:
result = dict()
if is_exist:
@ -375,13 +385,13 @@ def main():
module.fail_json(msg=str(ex))
else:
result['changed'] = changed
result["changed"] = changed
module.exit_json(**result)
def _init(config):
module = config.module
if module.params.get('id'):
if module.params.get("id"):
return
v = search_resource(config)
@ -390,7 +400,7 @@ def _init(config):
raise Exception(f"find more than one resources({', '.join([navigate_value(i, ['id']) for i in v])})")
if n == 1:
module.params['id'] = navigate_value(v[0], ["id"])
module.params["id"] = navigate_value(v[0], ["id"])
def user_input_parameters(module):
@ -414,7 +424,7 @@ def user_input_parameters(module):
def create(config):
module = config.module
client = config.client(get_region(module), "volumev3", "project")
timeout = 60 * int(module.params['timeouts']['create'].rstrip('m'))
timeout = 60 * int(module.params["timeouts"]["create"].rstrip("m"))
opts = user_input_parameters(module)
opts["ansible_module"] = module
@ -424,7 +434,7 @@ def create(config):
client1 = config.client(get_region(module), "volume", "project")
client1.endpoint = client1.endpoint.replace("/v2/", "/v1/")
obj = async_wait(config, r, client1, timeout)
module.params['id'] = navigate_value(obj, ["entities", "volume_id"])
module.params["id"] = navigate_value(obj, ["entities", "volume_id"])
def update(config, expect_state, current_state):
@ -432,7 +442,7 @@ def update(config, expect_state, current_state):
expect_state["current_state"] = current_state
current_state["current_state"] = current_state
client = config.client(get_region(module), "evs", "project")
timeout = 60 * int(module.params['timeouts']['update'].rstrip('m'))
timeout = 60 * int(module.params["timeouts"]["update"].rstrip("m"))
params = build_update_parameters(expect_state)
params1 = build_update_parameters(current_state)
@ -453,7 +463,7 @@ def update(config, expect_state, current_state):
def delete(config):
module = config.module
client = config.client(get_region(module), "evs", "project")
timeout = 60 * int(module.params['timeouts']['delete'].rstrip('m'))
timeout = 60 * int(module.params["timeouts"]["delete"].rstrip("m"))
r = send_delete_request(module, None, client)
@ -485,18 +495,15 @@ def _build_query_link(opts):
v = navigate_value(opts, ["enable_share"])
if v or v in [False, 0]:
query_params.append(
f"multiattach={str(v) if v else str(v).lower()}")
query_params.append(f"multiattach={str(v) if v else str(v).lower()}")
v = navigate_value(opts, ["name"])
if v or v in [False, 0]:
query_params.append(
f"name={str(v) if v else str(v).lower()}")
query_params.append(f"name={str(v) if v else str(v).lower()}")
v = navigate_value(opts, ["availability_zone"])
if v or v in [False, 0]:
query_params.append(
f"availability_zone={str(v) if v else str(v).lower()}")
query_params.append(f"availability_zone={str(v) if v else str(v).lower()}")
query_link = "?limit=10&offset={start}"
if query_params:
@ -514,7 +521,7 @@ def search_resource(config):
link = f"os-vendor-volumes/detail{query_link}"
result = []
p = {'start': 0}
p = {"start": 0}
while True:
url = link.format(**p)
r = send_list_request(module, client, url)
@ -528,7 +535,7 @@ def search_resource(config):
if len(result) > 1:
break
p['start'] += len(r)
p["start"] += len(r)
return result
@ -737,10 +744,7 @@ def async_wait(config, result, client, timeout):
return None, ""
try:
return wait_to_finish(
["SUCCESS"],
["RUNNING", "INIT"],
_query_status, timeout)
return wait_to_finish(["SUCCESS"], ["RUNNING", "INIT"], _query_status, timeout)
except Exception as ex:
module.fail_json(msg=f"module(hwc_evs_disk): error waiting to be done, error= {ex}")
@ -881,16 +885,13 @@ def flatten_options(response, array_index):
v = navigate_value(response, ["read", "multiattach"], array_index)
r["enable_share"] = v
v = navigate_value(
response, ["read", "metadata", "__system__cmkid"], array_index)
v = navigate_value(response, ["read", "metadata", "__system__cmkid"], array_index)
r["encryption_id"] = v
v = navigate_value(
response, ["read", "enterprise_project_id"], array_index)
v = navigate_value(response, ["read", "enterprise_project_id"], array_index)
r["enterprise_project_id"] = v
v = navigate_value(
response, ["read", "volume_image_metadata", "id"], array_index)
v = navigate_value(response, ["read", "volume_image_metadata", "id"], array_index)
r["image_id"] = v
v = flatten_is_bootable(response, array_index)
@ -924,8 +925,7 @@ def flatten_options(response, array_index):
def flatten_attachments(d, array_index):
v = navigate_value(d, ["read", "attachments"],
array_index)
v = navigate_value(d, ["read", "attachments"], array_index)
if not v:
return None
n = len(v)
@ -961,16 +961,14 @@ def flatten_attachments(d, array_index):
def flatten_enable_full_clone(d, array_index):
v = navigate_value(d, ["read", "metadata", "full_clone"],
array_index)
v = navigate_value(d, ["read", "metadata", "full_clone"], array_index)
if v is None:
return v
return True if v == "0" else False
def flatten_enable_scsi(d, array_index):
v = navigate_value(d, ["read", "metadata", "hw:passthrough"],
array_index)
v = navigate_value(d, ["read", "metadata", "hw:passthrough"], array_index)
if v is None:
return v
return True if v in ["true", "True"] else False
@ -984,8 +982,7 @@ def flatten_is_bootable(d, array_index):
def flatten_is_readonly(d, array_index):
v = navigate_value(d, ["read", "metadata", "readonly"],
array_index)
v = navigate_value(d, ["read", "metadata", "readonly"], array_index)
if v is None:
return v
return True if v in ["true", "True"] else False
@ -1014,7 +1011,6 @@ def set_readonly_options(opts, states):
def send_list_request(module, client, url):
r = None
try:
r = client.get(url)
@ -1157,5 +1153,5 @@ def fill_list_resp_volume_image_metadata(value):
return result
if __name__ == '__main__':
if __name__ == "__main__":
main()