mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 06:12:51 +00:00
Reformat everything.
This commit is contained in:
@@ -89,17 +89,23 @@ ip_address:
|
||||
"""
|
||||
|
||||
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)
|
||||
Config,
|
||||
HwcClientException,
|
||||
HwcModule,
|
||||
are_different_dicts,
|
||||
build_path,
|
||||
get_region,
|
||||
is_empty_value,
|
||||
navigate_value,
|
||||
)
|
||||
|
||||
|
||||
def build_module():
|
||||
return HwcModule(
|
||||
argument_spec=dict(
|
||||
state=dict(default='present', choices=['present', 'absent'],
|
||||
type='str'),
|
||||
subnet_id=dict(type='str', required=True),
|
||||
ip_address=dict(type='str')
|
||||
state=dict(default="present", choices=["present", "absent"], type="str"),
|
||||
subnet_id=dict(type="str", required=True),
|
||||
ip_address=dict(type="str"),
|
||||
),
|
||||
supports_check_mode=True,
|
||||
)
|
||||
@@ -113,7 +119,7 @@ def main():
|
||||
|
||||
try:
|
||||
resource = None
|
||||
if module.params['id']:
|
||||
if module.params["id"]:
|
||||
resource = True
|
||||
else:
|
||||
v = search_resource(config)
|
||||
@@ -122,11 +128,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)
|
||||
@@ -136,10 +142,11 @@ def main():
|
||||
expect = user_input_parameters(module)
|
||||
if are_different_dicts(expect, current):
|
||||
raise Exception(
|
||||
f"Cannot change option from ({current}) to ({expect})of an existing resource.({module.params.get('id')})")
|
||||
f"Cannot change option from ({current}) to ({expect})of an existing resource.({module.params.get('id')})"
|
||||
)
|
||||
|
||||
result = read_resource(config)
|
||||
result['id'] = module.params.get('id')
|
||||
result["id"] = module.params.get("id")
|
||||
else:
|
||||
if resource:
|
||||
if not module.check_mode:
|
||||
@@ -150,7 +157,7 @@ def main():
|
||||
module.fail_json(msg=str(ex))
|
||||
|
||||
else:
|
||||
result['changed'] = changed
|
||||
result["changed"] = changed
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
@@ -168,8 +175,7 @@ def create(config):
|
||||
|
||||
params = build_create_parameters(opts)
|
||||
r = send_create_request(module, params, client)
|
||||
module.params['id'] = navigate_value(r, ["privateips", "id"],
|
||||
{"privateips": 0})
|
||||
module.params["id"] = navigate_value(r, ["privateips", "id"], {"privateips": 0})
|
||||
|
||||
|
||||
def delete(config):
|
||||
@@ -206,7 +212,7 @@ def search_resource(config):
|
||||
link = build_path(module, "subnets/{subnet_id}/privateips") + query_link
|
||||
|
||||
result = []
|
||||
p = {'marker': ''}
|
||||
p = {"marker": ""}
|
||||
while True:
|
||||
url = link.format(**p)
|
||||
r = send_list_request(module, client, url)
|
||||
@@ -221,7 +227,7 @@ def search_resource(config):
|
||||
if len(result) > 1:
|
||||
break
|
||||
|
||||
p['marker'] = r[-1].get('id')
|
||||
p["marker"] = r[-1].get("id")
|
||||
|
||||
return result
|
||||
|
||||
@@ -306,7 +312,6 @@ def update_properties(module, response, array_index, exclude_output=False):
|
||||
|
||||
|
||||
def send_list_request(module, client, url):
|
||||
|
||||
r = None
|
||||
try:
|
||||
r = client.get(url)
|
||||
@@ -343,5 +348,5 @@ def fill_list_resp_body(body):
|
||||
return result
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user