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

@@ -196,35 +196,43 @@ mac_address:
"""
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()),
subnet_id=dict(type='str', required=True),
admin_state_up=dict(type='bool'),
allowed_address_pairs=dict(
type='list', elements='dict',
state=dict(default="present", choices=["present", "absent"], type="str"),
timeouts=dict(
type="dict",
options=dict(
ip_address=dict(type='str'),
mac_address=dict(type='str')
create=dict(default="15m", type="str"),
),
default=dict(),
),
extra_dhcp_opts=dict(type='list', elements='dict', options=dict(
name=dict(type='str'),
value=dict(type='str')
)),
ip_address=dict(type='str'),
name=dict(type='str'),
security_groups=dict(type='list', elements='str')
subnet_id=dict(type="str", required=True),
admin_state_up=dict(type="bool"),
allowed_address_pairs=dict(
type="list",
elements="dict",
options=dict(ip_address=dict(type="str"), mac_address=dict(type="str")),
),
extra_dhcp_opts=dict(
type="list", elements="dict", options=dict(name=dict(type="str"), value=dict(type="str"))
),
ip_address=dict(type="str"),
name=dict(type="str"),
security_groups=dict(type="list", elements="str"),
),
supports_check_mode=True,
)
@@ -238,7 +246,7 @@ def main():
try:
resource = None
if module.params['id']:
if module.params["id"]:
resource = True
else:
v = search_resource(config)
@@ -247,11 +255,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)
@@ -265,7 +273,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:
@@ -276,7 +284,7 @@ def main():
module.fail_json(msg=str(ex))
else:
result['changed'] = changed
result["changed"] = changed
module.exit_json(**result)
@@ -295,13 +303,13 @@ def user_input_parameters(module):
def create(config):
module = config.module
client = config.client(get_region(module), "vpc", "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, ["port", "id"])
module.params["id"] = navigate_value(obj, ["port", "id"])
def update(config):
@@ -333,7 +341,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:
@@ -387,7 +395,7 @@ def search_resource(config):
link = f"ports{query_link}"
result = []
p = {'marker': ''}
p = {"marker": ""}
while True:
url = link.format(**p)
r = send_list_request(module, client, url)
@@ -402,7 +410,7 @@ def search_resource(config):
if len(result) > 1:
break
p['marker'] = r[-1].get('id')
p["marker"] = r[-1].get("id")
return result
@@ -453,8 +461,7 @@ def expand_create_allowed_address_pairs(d, array_index):
req = []
v = navigate_value(d, ["allowed_address_pairs"],
new_array_index)
v = navigate_value(d, ["allowed_address_pairs"], new_array_index)
if not v:
return req
n = len(v)
@@ -462,13 +469,11 @@ def expand_create_allowed_address_pairs(d, array_index):
new_array_index["allowed_address_pairs"] = i
transformed = dict()
v = navigate_value(d, ["allowed_address_pairs", "ip_address"],
new_array_index)
v = navigate_value(d, ["allowed_address_pairs", "ip_address"], new_array_index)
if not is_empty_value(v):
transformed["ip_address"] = v
v = navigate_value(d, ["allowed_address_pairs", "mac_address"],
new_array_index)
v = navigate_value(d, ["allowed_address_pairs", "mac_address"], new_array_index)
if not is_empty_value(v):
transformed["mac_address"] = v
@@ -485,8 +490,7 @@ def expand_create_extra_dhcp_opts(d, array_index):
req = []
v = navigate_value(d, ["extra_dhcp_opts"],
new_array_index)
v = navigate_value(d, ["extra_dhcp_opts"], new_array_index)
if not v:
return req
n = len(v)
@@ -564,10 +568,7 @@ def async_wait_create(config, result, client, timeout):
return None, ""
try:
return wait_to_finish(
["ACTIVE", "DOWN"],
["BUILD"],
_query_status, timeout)
return wait_to_finish(["ACTIVE", "DOWN"], ["BUILD"], _query_status, timeout)
except Exception as ex:
module.fail_json(msg=f"module(hwc_vpc_port): error waiting for api(create) to be done, error= {ex}")
@@ -606,8 +607,7 @@ def expand_update_allowed_address_pairs(d, array_index):
req = []
v = navigate_value(d, ["allowed_address_pairs"],
new_array_index)
v = navigate_value(d, ["allowed_address_pairs"], new_array_index)
if not v:
return req
n = len(v)
@@ -615,13 +615,11 @@ def expand_update_allowed_address_pairs(d, array_index):
new_array_index["allowed_address_pairs"] = i
transformed = dict()
v = navigate_value(d, ["allowed_address_pairs", "ip_address"],
new_array_index)
v = navigate_value(d, ["allowed_address_pairs", "ip_address"], new_array_index)
if not is_empty_value(v):
transformed["ip_address"] = v
v = navigate_value(d, ["allowed_address_pairs", "mac_address"],
new_array_index)
v = navigate_value(d, ["allowed_address_pairs", "mac_address"], new_array_index)
if not is_empty_value(v):
transformed["mac_address"] = v
@@ -638,8 +636,7 @@ def expand_update_extra_dhcp_opts(d, array_index):
req = []
v = navigate_value(d, ["extra_dhcp_opts"],
new_array_index)
v = navigate_value(d, ["extra_dhcp_opts"], new_array_index)
if not v:
return req
n = len(v)
@@ -802,8 +799,7 @@ def update_properties(module, response, array_index, exclude_output=False):
v = flatten_extra_dhcp_opts(response, array_index, v, exclude_output)
r["extra_dhcp_opts"] = v
v = navigate_value(response, ["read", "fixed_ips", "ip_address"],
array_index)
v = navigate_value(response, ["read", "fixed_ips", "ip_address"], array_index)
r["ip_address"] = v
if not exclude_output:
@@ -822,8 +818,7 @@ def update_properties(module, response, array_index, exclude_output=False):
return r
def flatten_allowed_address_pairs(d, array_index,
current_value, exclude_output):
def flatten_allowed_address_pairs(d, array_index, current_value, exclude_output):
n = 0
result = current_value
has_init_value = True
@@ -832,8 +827,7 @@ def flatten_allowed_address_pairs(d, array_index,
else:
has_init_value = False
result = []
v = navigate_value(d, ["read", "allowed_address_pairs"],
array_index)
v = navigate_value(d, ["read", "allowed_address_pairs"], array_index)
if not v:
return current_value
n = len(v)
@@ -849,12 +843,10 @@ def flatten_allowed_address_pairs(d, array_index,
if len(result) >= (i + 1) and result[i]:
val = result[i]
v = navigate_value(d, ["read", "allowed_address_pairs", "ip_address"],
new_array_index)
v = navigate_value(d, ["read", "allowed_address_pairs", "ip_address"], new_array_index)
val["ip_address"] = v
v = navigate_value(d, ["read", "allowed_address_pairs", "mac_address"],
new_array_index)
v = navigate_value(d, ["read", "allowed_address_pairs", "mac_address"], new_array_index)
val["mac_address"] = v
if len(result) >= (i + 1):
@@ -877,8 +869,7 @@ def flatten_extra_dhcp_opts(d, array_index, current_value, exclude_output):
else:
has_init_value = False
result = []
v = navigate_value(d, ["read", "extra_dhcp_opts"],
array_index)
v = navigate_value(d, ["read", "extra_dhcp_opts"], array_index)
if not v:
return current_value
n = len(v)
@@ -894,12 +885,10 @@ def flatten_extra_dhcp_opts(d, array_index, current_value, exclude_output):
if len(result) >= (i + 1) and result[i]:
val = result[i]
v = navigate_value(d, ["read", "extra_dhcp_opts", "opt_name"],
new_array_index)
v = navigate_value(d, ["read", "extra_dhcp_opts", "opt_name"], new_array_index)
val["name"] = v
v = navigate_value(d, ["read", "extra_dhcp_opts", "opt_value"],
new_array_index)
v = navigate_value(d, ["read", "extra_dhcp_opts", "opt_value"], new_array_index)
val["value"] = v
if len(result) >= (i + 1):
@@ -914,7 +903,6 @@ def flatten_extra_dhcp_opts(d, array_index, current_value, exclude_output):
def send_list_request(module, client, url):
r = None
try:
r = client.get(url)
@@ -977,20 +965,17 @@ def expand_list_allowed_address_pairs(d, array_index):
req = []
v = navigate_value(d, ["allowed_address_pairs"],
new_array_index)
v = navigate_value(d, ["allowed_address_pairs"], new_array_index)
n = len(v) if v else 1
for i in range(n):
new_array_index["allowed_address_pairs"] = i
transformed = dict()
v = navigate_value(d, ["allowed_address_pairs", "ip_address"],
new_array_index)
v = navigate_value(d, ["allowed_address_pairs", "ip_address"], new_array_index)
transformed["ip_address"] = v
v = navigate_value(d, ["allowed_address_pairs", "mac_address"],
new_array_index)
v = navigate_value(d, ["allowed_address_pairs", "mac_address"], new_array_index)
transformed["mac_address"] = v
for v in transformed.values():
@@ -1008,8 +993,7 @@ def expand_list_extra_dhcp_opts(d, array_index):
req = []
v = navigate_value(d, ["extra_dhcp_opts"],
new_array_index)
v = navigate_value(d, ["extra_dhcp_opts"], new_array_index)
n = len(v) if v else 1
for i in range(n):
@@ -1142,5 +1126,5 @@ def fill_list_resp_fixed_ips(value):
return result
if __name__ == '__main__':
if __name__ == "__main__":
main()