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

@@ -134,26 +134,38 @@ description:
"""
from ansible_collections.community.general.plugins.module_utils.hwc_utils import (
Config, HwcClientException, HwcClientException404, HwcModule,
are_different_dicts, build_path, get_region, is_empty_value,
navigate_value, wait_to_finish)
Config,
HwcClientException,
HwcClientException404,
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='15m', type='str'),
), default=dict()),
local_vpc_id=dict(type='str', required=True),
name=dict(type='str', required=True),
peering_vpc=dict(type='dict', required=True, options=dict(
vpc_id=dict(type='str', required=True),
project_id=dict(type='str')
)),
description=dict(type='str')
state=dict(default="present", choices=["present", "absent"], type="str"),
timeouts=dict(
type="dict",
options=dict(
create=dict(default="15m", type="str"),
),
default=dict(),
),
local_vpc_id=dict(type="str", required=True),
name=dict(type="str", required=True),
peering_vpc=dict(
type="dict",
required=True,
options=dict(vpc_id=dict(type="str", required=True), project_id=dict(type="str")),
),
description=dict(type="str"),
),
supports_check_mode=True,
)
@@ -167,7 +179,7 @@ def main():
try:
resource = None
if module.params['id']:
if module.params["id"]:
resource = True
else:
v = search_resource(config)
@@ -176,11 +188,11 @@ def main():
if len(v) == 1:
resource = v[0]
module.params['id'] = navigate_value(resource, ["id"])
module.params["id"] = navigate_value(resource, ["id"])
result = {}
changed = False
if module.params['state'] == 'present':
if module.params["state"] == "present":
if resource is None:
if not module.check_mode:
create(config)
@@ -194,7 +206,7 @@ def main():
changed = True
result = read_resource(config)
result['id'] = module.params.get('id')
result["id"] = module.params.get("id")
else:
if resource:
if not module.check_mode:
@@ -205,7 +217,7 @@ def main():
module.fail_json(msg=str(ex))
else:
result['changed'] = changed
result["changed"] = changed
module.exit_json(**result)
@@ -221,13 +233,13 @@ def user_input_parameters(module):
def create(config):
module = config.module
client = config.client(get_region(module), "network", "project")
timeout = 60 * int(module.params['timeouts']['create'].rstrip('m'))
timeout = 60 * int(module.params["timeouts"]["create"].rstrip("m"))
opts = user_input_parameters(module)
params = build_create_parameters(opts)
r = send_create_request(module, params, client)
obj = async_wait_create(config, r, client, timeout)
module.params['id'] = navigate_value(obj, ["peering", "id"])
module.params["id"] = navigate_value(obj, ["peering", "id"])
def update(config):
@@ -259,7 +271,7 @@ def delete(config):
return True, "Pending"
timeout = 60 * int(module.params['timeouts']['create'].rstrip('m'))
timeout = 60 * int(module.params["timeouts"]["create"].rstrip("m"))
try:
wait_to_finish(["Done"], ["Pending"], _refresh_status, timeout)
except Exception as ex:
@@ -305,7 +317,7 @@ def search_resource(config):
link = f"v2.0/vpc/peerings{query_link}"
result = []
p = {'marker': ''}
p = {"marker": ""}
while True:
url = link.format(**p)
r = send_list_request(module, client, url)
@@ -320,7 +332,7 @@ def search_resource(config):
if len(result) > 1:
break
p['marker'] = r[-1].get('id')
p["marker"] = r[-1].get("id")
return result
@@ -413,10 +425,7 @@ def async_wait_create(config, result, client, timeout):
return None, ""
try:
return wait_to_finish(
["ACTIVE"],
["PENDING_ACCEPTANCE"],
_query_status, timeout)
return wait_to_finish(["ACTIVE"], ["PENDING_ACCEPTANCE"], _query_status, timeout)
except Exception as ex:
module.fail_json(msg=f"module(hwc_vpc_peering_connect): error waiting for api(create) to be done, error= {ex}")
@@ -529,8 +538,7 @@ def update_properties(module, response, array_index, exclude_output=False):
v = navigate_value(response, ["read", "description"], array_index)
r["description"] = v
v = navigate_value(response, ["read", "request_vpc_info", "vpc_id"],
array_index)
v = navigate_value(response, ["read", "request_vpc_info", "vpc_id"], array_index)
r["local_vpc_id"] = v
v = navigate_value(response, ["read", "name"], array_index)
@@ -550,8 +558,7 @@ def flatten_peering_vpc(d, array_index, current_value, exclude_output):
result = dict()
has_init_value = False
v = navigate_value(d, ["read", "accept_vpc_info", "tenant_id"],
array_index)
v = navigate_value(d, ["read", "accept_vpc_info", "tenant_id"], array_index)
result["project_id"] = v
v = navigate_value(d, ["read", "accept_vpc_info", "vpc_id"], array_index)
@@ -567,7 +574,6 @@ def flatten_peering_vpc(d, array_index, current_value, exclude_output):
def send_list_request(module, client, url):
r = None
try:
r = client.get(url)
@@ -675,5 +681,5 @@ def fill_list_resp_request_vpc_info(value):
return result
if __name__ == '__main__':
if __name__ == "__main__":
main()