mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-30 15:38:53 +00:00
Reformat everything.
This commit is contained in:
parent
3f2213791a
commit
340ff8586d
1008 changed files with 61301 additions and 58309 deletions
|
|
@ -228,31 +228,45 @@ private_ip_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='5m', type='str'),
|
||||
update=dict(default='5m', type='str'),
|
||||
), default=dict()),
|
||||
type=dict(type='str', required=True),
|
||||
dedicated_bandwidth=dict(type='dict', options=dict(
|
||||
charge_mode=dict(type='str', required=True),
|
||||
name=dict(type='str', required=True),
|
||||
size=dict(type='int', required=True)
|
||||
)),
|
||||
enterprise_project_id=dict(type='str'),
|
||||
ip_version=dict(type='int'),
|
||||
ipv4_address=dict(type='str'),
|
||||
port_id=dict(type='str'),
|
||||
shared_bandwidth_id=dict(type='str')
|
||||
state=dict(default="present", choices=["present", "absent"], type="str"),
|
||||
timeouts=dict(
|
||||
type="dict",
|
||||
options=dict(
|
||||
create=dict(default="5m", type="str"),
|
||||
update=dict(default="5m", type="str"),
|
||||
),
|
||||
default=dict(),
|
||||
),
|
||||
type=dict(type="str", required=True),
|
||||
dedicated_bandwidth=dict(
|
||||
type="dict",
|
||||
options=dict(
|
||||
charge_mode=dict(type="str", required=True),
|
||||
name=dict(type="str", required=True),
|
||||
size=dict(type="int", required=True),
|
||||
),
|
||||
),
|
||||
enterprise_project_id=dict(type="str"),
|
||||
ip_version=dict(type="int"),
|
||||
ipv4_address=dict(type="str"),
|
||||
port_id=dict(type="str"),
|
||||
shared_bandwidth_id=dict(type="str"),
|
||||
),
|
||||
supports_check_mode=True,
|
||||
)
|
||||
|
|
@ -266,7 +280,7 @@ def main():
|
|||
|
||||
try:
|
||||
resource = None
|
||||
if module.params['id']:
|
||||
if module.params["id"]:
|
||||
resource = True
|
||||
else:
|
||||
v = search_resource(config)
|
||||
|
|
@ -275,11 +289,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)
|
||||
|
|
@ -293,7 +307,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:
|
||||
|
|
@ -304,7 +318,7 @@ def main():
|
|||
module.fail_json(msg=str(ex))
|
||||
|
||||
else:
|
||||
result['changed'] = changed
|
||||
result["changed"] = changed
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
|
|
@ -323,19 +337,19 @@ 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, ["publicip", "id"])
|
||||
module.params["id"] = navigate_value(obj, ["publicip", "id"])
|
||||
|
||||
|
||||
def update(config):
|
||||
module = config.module
|
||||
client = config.client(get_region(module), "vpc", "project")
|
||||
timeout = 60 * int(module.params['timeouts']['update'].rstrip('m'))
|
||||
timeout = 60 * int(module.params["timeouts"]["update"].rstrip("m"))
|
||||
opts = user_input_parameters(module)
|
||||
|
||||
params = build_update_parameters(opts)
|
||||
|
|
@ -367,7 +381,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:
|
||||
|
|
@ -413,7 +427,7 @@ def search_resource(config):
|
|||
link = f"publicips{query_link}"
|
||||
|
||||
result = []
|
||||
p = {'marker': ''}
|
||||
p = {"marker": ""}
|
||||
while True:
|
||||
url = link.format(**p)
|
||||
r = send_list_request(module, client, url)
|
||||
|
|
@ -428,7 +442,7 @@ def search_resource(config):
|
|||
if len(result) > 1:
|
||||
break
|
||||
|
||||
p['marker'] = r[-1].get('id')
|
||||
p["marker"] = r[-1].get("id")
|
||||
|
||||
return result
|
||||
|
||||
|
|
@ -455,23 +469,15 @@ def expand_create_bandwidth(d, array_index):
|
|||
v = navigate_value(d, ["dedicated_bandwidth"], array_index)
|
||||
sbwid = navigate_value(d, ["shared_bandwidth_id"], array_index)
|
||||
if v and sbwid:
|
||||
raise Exception("don't input shared_bandwidth_id and "
|
||||
"dedicated_bandwidth at same time")
|
||||
raise Exception("don't input shared_bandwidth_id and dedicated_bandwidth at same time")
|
||||
|
||||
if not (v or sbwid):
|
||||
raise Exception("must input shared_bandwidth_id or "
|
||||
"dedicated_bandwidth")
|
||||
raise Exception("must input shared_bandwidth_id or dedicated_bandwidth")
|
||||
|
||||
if sbwid:
|
||||
return {
|
||||
"id": sbwid,
|
||||
"share_type": "WHOLE"}
|
||||
return {"id": sbwid, "share_type": "WHOLE"}
|
||||
|
||||
return {
|
||||
"charge_mode": v["charge_mode"],
|
||||
"name": v["name"],
|
||||
"share_type": "PER",
|
||||
"size": v["size"]}
|
||||
return {"charge_mode": v["charge_mode"], "name": v["name"], "share_type": "PER", "size": v["size"]}
|
||||
|
||||
|
||||
def expand_create_publicip(d, array_index):
|
||||
|
|
@ -527,10 +533,7 @@ def async_wait_create(config, result, client, timeout):
|
|||
return None, ""
|
||||
|
||||
try:
|
||||
return wait_to_finish(
|
||||
["ACTIVE", "DOWN"],
|
||||
None,
|
||||
_query_status, timeout)
|
||||
return wait_to_finish(["ACTIVE", "DOWN"], None, _query_status, timeout)
|
||||
except Exception as ex:
|
||||
module.fail_json(msg=f"module(hwc_vpc_eip): error waiting for api(create) to be done, error= {ex}")
|
||||
|
||||
|
|
@ -585,10 +588,7 @@ def async_wait_update(config, result, client, timeout):
|
|||
return None, ""
|
||||
|
||||
try:
|
||||
return wait_to_finish(
|
||||
["ACTIVE", "DOWN"],
|
||||
None,
|
||||
_query_status, timeout)
|
||||
return wait_to_finish(["ACTIVE", "DOWN"], None, _query_status, timeout)
|
||||
except Exception as ex:
|
||||
module.fail_json(msg=f"module(hwc_vpc_eip): error waiting for api(update) to be done, error= {ex}")
|
||||
|
||||
|
|
@ -665,8 +665,7 @@ def update_properties(module, response, array_index, exclude_output=False):
|
|||
v = flatten_dedicated_bandwidth(response, array_index, v, exclude_output)
|
||||
r["dedicated_bandwidth"] = 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", "ip_version"], array_index)
|
||||
|
|
@ -676,16 +675,14 @@ def update_properties(module, response, array_index, exclude_output=False):
|
|||
r["ipv4_address"] = v
|
||||
|
||||
if not exclude_output:
|
||||
v = navigate_value(response, ["read", "public_ipv6_address"],
|
||||
array_index)
|
||||
v = navigate_value(response, ["read", "public_ipv6_address"], array_index)
|
||||
r["ipv6_address"] = v
|
||||
|
||||
v = navigate_value(response, ["read", "port_id"], array_index)
|
||||
r["port_id"] = v
|
||||
|
||||
if not exclude_output:
|
||||
v = navigate_value(response, ["read", "private_ip_address"],
|
||||
array_index)
|
||||
v = navigate_value(response, ["read", "private_ip_address"], array_index)
|
||||
r["private_ip_address"] = v
|
||||
|
||||
v = r.get("shared_bandwidth_id")
|
||||
|
|
@ -732,7 +729,6 @@ def flatten_shared_bandwidth_id(d, array_index, current_value, exclude_output):
|
|||
|
||||
|
||||
def send_list_request(module, client, url):
|
||||
|
||||
r = None
|
||||
try:
|
||||
r = client.get(url)
|
||||
|
|
@ -791,8 +787,7 @@ def expand_list_bandwidth_id(d, array_index):
|
|||
v = navigate_value(d, ["dedicated_bandwidth"], array_index)
|
||||
sbwid = navigate_value(d, ["shared_bandwidth_id"], array_index)
|
||||
if v and sbwid:
|
||||
raise Exception("don't input shared_bandwidth_id and "
|
||||
"dedicated_bandwidth at same time")
|
||||
raise Exception("don't input shared_bandwidth_id and dedicated_bandwidth at same time")
|
||||
|
||||
return sbwid
|
||||
|
||||
|
|
@ -833,5 +828,5 @@ def fill_list_resp_body(body):
|
|||
return result
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue