mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-02-04 07:51:50 +00:00
Reformat everything.
This commit is contained in:
parent
3f2213791a
commit
340ff8586d
1008 changed files with 61301 additions and 58309 deletions
|
|
@ -193,17 +193,16 @@ function:
|
|||
from copy import deepcopy
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils.scaleway import (
|
||||
SCALEWAY_REGIONS, scaleway_argument_spec, Scaleway,
|
||||
scaleway_waitable_resource_argument_spec, resource_attributes_should_be_changed,
|
||||
SecretVariables
|
||||
SCALEWAY_REGIONS,
|
||||
scaleway_argument_spec,
|
||||
Scaleway,
|
||||
scaleway_waitable_resource_argument_spec,
|
||||
resource_attributes_should_be_changed,
|
||||
SecretVariables,
|
||||
)
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
STABLE_STATES = (
|
||||
"ready",
|
||||
"created",
|
||||
"absent"
|
||||
)
|
||||
STABLE_STATES = ("ready", "created", "absent")
|
||||
|
||||
VERIFIABLE_MUTABLE_ATTRIBUTES = (
|
||||
"description",
|
||||
|
|
@ -215,12 +214,10 @@ VERIFIABLE_MUTABLE_ATTRIBUTES = (
|
|||
"timeout",
|
||||
"handler",
|
||||
"privacy",
|
||||
"secret_environment_variables"
|
||||
"secret_environment_variables",
|
||||
)
|
||||
|
||||
MUTABLE_ATTRIBUTES = VERIFIABLE_MUTABLE_ATTRIBUTES + (
|
||||
"redeploy",
|
||||
)
|
||||
MUTABLE_ATTRIBUTES = VERIFIABLE_MUTABLE_ATTRIBUTES + ("redeploy",)
|
||||
|
||||
|
||||
def payload_from_wished_fn(wished_fn):
|
||||
|
|
@ -237,7 +234,7 @@ def payload_from_wished_fn(wished_fn):
|
|||
"privacy": wished_fn["privacy"],
|
||||
"redeploy": wished_fn["redeploy"],
|
||||
"environment_variables": wished_fn["environment_variables"],
|
||||
"secret_environment_variables": SecretVariables.dict_to_list(wished_fn["secret_environment_variables"])
|
||||
"secret_environment_variables": SecretVariables.dict_to_list(wished_fn["secret_environment_variables"]),
|
||||
}
|
||||
|
||||
return payload
|
||||
|
|
@ -260,7 +257,7 @@ def absent_strategy(api, wished_fn):
|
|||
api.wait_to_complete_state_transition(resource=target_fn, stable_states=STABLE_STATES, force_wait=True)
|
||||
response = api.delete(path=f"{api.api_path}/{target_fn['id']}")
|
||||
if not response.ok:
|
||||
api.module.fail_json(msg=f'Error deleting function [{response.status_code}: {response.json}]')
|
||||
api.module.fail_json(msg=f"Error deleting function [{response.status_code}: {response.json}]")
|
||||
|
||||
api.wait_to_complete_state_transition(resource=target_fn, stable_states=STABLE_STATES)
|
||||
return changed, response.json
|
||||
|
|
@ -284,8 +281,7 @@ def present_strategy(api, wished_fn):
|
|||
|
||||
# Create function
|
||||
api.warn(payload_fn)
|
||||
creation_response = api.post(path=api.api_path,
|
||||
data=payload_fn)
|
||||
creation_response = api.post(path=api.api_path, data=payload_fn)
|
||||
|
||||
if not creation_response.ok:
|
||||
msg = f"Error during function creation: {creation_response.info['msg']}: '{creation_response.json['message']}' ({creation_response.json})"
|
||||
|
|
@ -297,13 +293,16 @@ def present_strategy(api, wished_fn):
|
|||
|
||||
target_fn = fn_lookup[wished_fn["name"]]
|
||||
decoded_target_fn = deepcopy(target_fn)
|
||||
decoded_target_fn["secret_environment_variables"] = SecretVariables.decode(decoded_target_fn["secret_environment_variables"],
|
||||
payload_fn["secret_environment_variables"])
|
||||
decoded_target_fn["secret_environment_variables"] = SecretVariables.decode(
|
||||
decoded_target_fn["secret_environment_variables"], payload_fn["secret_environment_variables"]
|
||||
)
|
||||
|
||||
patch_payload = resource_attributes_should_be_changed(target=decoded_target_fn,
|
||||
wished=payload_fn,
|
||||
verifiable_mutable_attributes=VERIFIABLE_MUTABLE_ATTRIBUTES,
|
||||
mutable_attributes=MUTABLE_ATTRIBUTES)
|
||||
patch_payload = resource_attributes_should_be_changed(
|
||||
target=decoded_target_fn,
|
||||
wished=payload_fn,
|
||||
verifiable_mutable_attributes=VERIFIABLE_MUTABLE_ATTRIBUTES,
|
||||
mutable_attributes=MUTABLE_ATTRIBUTES,
|
||||
)
|
||||
|
||||
if not patch_payload:
|
||||
return changed, target_fn
|
||||
|
|
@ -312,21 +311,19 @@ def present_strategy(api, wished_fn):
|
|||
if api.module.check_mode:
|
||||
return changed, {"status": "Function attributes would be changed."}
|
||||
|
||||
fn_patch_response = api.patch(path=f"{api.api_path}/{target_fn['id']}",
|
||||
data=patch_payload)
|
||||
fn_patch_response = api.patch(path=f"{api.api_path}/{target_fn['id']}", data=patch_payload)
|
||||
|
||||
if not fn_patch_response.ok:
|
||||
api.module.fail_json(msg=f"Error during function attributes update: [{fn_patch_response.status_code}: {fn_patch_response.json['message']}]")
|
||||
api.module.fail_json(
|
||||
msg=f"Error during function attributes update: [{fn_patch_response.status_code}: {fn_patch_response.json['message']}]"
|
||||
)
|
||||
|
||||
api.wait_to_complete_state_transition(resource=target_fn, stable_states=STABLE_STATES)
|
||||
response = api.get(path=f"{api.api_path}/{target_fn['id']}")
|
||||
return changed, response.json
|
||||
|
||||
|
||||
state_strategy = {
|
||||
"present": present_strategy,
|
||||
"absent": absent_strategy
|
||||
}
|
||||
state_strategy = {"present": present_strategy, "absent": absent_strategy}
|
||||
|
||||
|
||||
def core(module):
|
||||
|
|
@ -337,17 +334,17 @@ def core(module):
|
|||
"state": module.params["state"],
|
||||
"namespace_id": module.params["namespace_id"],
|
||||
"name": module.params["name"],
|
||||
"description": module.params['description'],
|
||||
"min_scale": module.params['min_scale'],
|
||||
"max_scale": module.params['max_scale'],
|
||||
"description": module.params["description"],
|
||||
"min_scale": module.params["min_scale"],
|
||||
"max_scale": module.params["max_scale"],
|
||||
"runtime": module.params["runtime"],
|
||||
"memory_limit": module.params["memory_limit"],
|
||||
"timeout": module.params["function_timeout"],
|
||||
"handler": module.params["handler"],
|
||||
"privacy": module.params["privacy"],
|
||||
"redeploy": module.params["redeploy"],
|
||||
"environment_variables": module.params['environment_variables'],
|
||||
"secret_environment_variables": module.params['secret_environment_variables']
|
||||
"environment_variables": module.params["environment_variables"],
|
||||
"secret_environment_variables": module.params["secret_environment_variables"],
|
||||
}
|
||||
|
||||
api = Scaleway(module=module)
|
||||
|
|
@ -361,23 +358,25 @@ def core(module):
|
|||
def main():
|
||||
argument_spec = scaleway_argument_spec()
|
||||
argument_spec.update(scaleway_waitable_resource_argument_spec())
|
||||
argument_spec.update(dict(
|
||||
state=dict(type='str', default='present', choices=['absent', 'present']),
|
||||
namespace_id=dict(type='str', required=True),
|
||||
region=dict(type='str', required=True, choices=SCALEWAY_REGIONS),
|
||||
name=dict(type='str', required=True),
|
||||
description=dict(type='str', default=''),
|
||||
min_scale=dict(type='int'),
|
||||
max_scale=dict(type='int'),
|
||||
runtime=dict(type='str', required=True),
|
||||
memory_limit=dict(type='int'),
|
||||
function_timeout=dict(type='str'),
|
||||
handler=dict(type='str'),
|
||||
privacy=dict(type='str', default='public', choices=['public', 'private']),
|
||||
redeploy=dict(type='bool', default=False),
|
||||
environment_variables=dict(type='dict', default={}),
|
||||
secret_environment_variables=dict(type='dict', default={}, no_log=True)
|
||||
))
|
||||
argument_spec.update(
|
||||
dict(
|
||||
state=dict(type="str", default="present", choices=["absent", "present"]),
|
||||
namespace_id=dict(type="str", required=True),
|
||||
region=dict(type="str", required=True, choices=SCALEWAY_REGIONS),
|
||||
name=dict(type="str", required=True),
|
||||
description=dict(type="str", default=""),
|
||||
min_scale=dict(type="int"),
|
||||
max_scale=dict(type="int"),
|
||||
runtime=dict(type="str", required=True),
|
||||
memory_limit=dict(type="int"),
|
||||
function_timeout=dict(type="str"),
|
||||
handler=dict(type="str"),
|
||||
privacy=dict(type="str", default="public", choices=["public", "private"]),
|
||||
redeploy=dict(type="bool", default=False),
|
||||
environment_variables=dict(type="dict", default={}),
|
||||
secret_environment_variables=dict(type="dict", default={}, no_log=True),
|
||||
)
|
||||
)
|
||||
module = AnsibleModule(
|
||||
argument_spec=argument_spec,
|
||||
supports_check_mode=True,
|
||||
|
|
@ -386,5 +385,5 @@ def main():
|
|||
core(module)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue