mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-21 03:09:04 +00:00
Reformat everything.
This commit is contained in:
parent
3f2213791a
commit
340ff8586d
1008 changed files with 61301 additions and 58309 deletions
|
|
@ -133,22 +133,18 @@ container_namespace:
|
|||
from copy import deepcopy
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils.scaleway import (
|
||||
SCALEWAY_REGIONS, scaleway_argument_spec, Scaleway,
|
||||
SCALEWAY_REGIONS,
|
||||
scaleway_argument_spec,
|
||||
Scaleway,
|
||||
scaleway_waitable_resource_argument_spec,
|
||||
resource_attributes_should_be_changed, SecretVariables
|
||||
resource_attributes_should_be_changed,
|
||||
SecretVariables,
|
||||
)
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
STABLE_STATES = (
|
||||
"ready",
|
||||
"absent"
|
||||
)
|
||||
STABLE_STATES = ("ready", "absent")
|
||||
|
||||
MUTABLE_ATTRIBUTES = (
|
||||
"description",
|
||||
"environment_variables",
|
||||
"secret_environment_variables"
|
||||
)
|
||||
MUTABLE_ATTRIBUTES = ("description", "environment_variables", "secret_environment_variables")
|
||||
|
||||
|
||||
def payload_from_wished_cn(wished_cn):
|
||||
|
|
@ -157,7 +153,7 @@ def payload_from_wished_cn(wished_cn):
|
|||
"name": wished_cn["name"],
|
||||
"description": wished_cn["description"],
|
||||
"environment_variables": wished_cn["environment_variables"],
|
||||
"secret_environment_variables": SecretVariables.dict_to_list(wished_cn["secret_environment_variables"])
|
||||
"secret_environment_variables": SecretVariables.dict_to_list(wished_cn["secret_environment_variables"]),
|
||||
}
|
||||
|
||||
return payload
|
||||
|
|
@ -180,7 +176,7 @@ def absent_strategy(api, wished_cn):
|
|||
api.wait_to_complete_state_transition(resource=target_cn, stable_states=STABLE_STATES, force_wait=True)
|
||||
response = api.delete(path=f"{api.api_path}/{target_cn['id']}")
|
||||
if not response.ok:
|
||||
api.module.fail_json(msg=f'Error deleting container namespace [{response.status_code}: {response.json}]')
|
||||
api.module.fail_json(msg=f"Error deleting container namespace [{response.status_code}: {response.json}]")
|
||||
|
||||
api.wait_to_complete_state_transition(resource=target_cn, stable_states=STABLE_STATES)
|
||||
return changed, response.json
|
||||
|
|
@ -201,12 +197,13 @@ def present_strategy(api, wished_cn):
|
|||
|
||||
# Create container namespace
|
||||
api.warn(payload_cn)
|
||||
creation_response = api.post(path=api.api_path,
|
||||
data=payload_cn)
|
||||
creation_response = api.post(path=api.api_path, data=payload_cn)
|
||||
|
||||
if not creation_response.ok:
|
||||
msg = (f"Error during container namespace creation: {creation_response.info['msg']}: "
|
||||
f"'{creation_response.json['message']}' ({creation_response.json})")
|
||||
msg = (
|
||||
f"Error during container namespace creation: {creation_response.info['msg']}: "
|
||||
f"'{creation_response.json['message']}' ({creation_response.json})"
|
||||
)
|
||||
api.module.fail_json(msg=msg)
|
||||
|
||||
api.wait_to_complete_state_transition(resource=creation_response.json, stable_states=STABLE_STATES)
|
||||
|
|
@ -215,12 +212,15 @@ def present_strategy(api, wished_cn):
|
|||
|
||||
target_cn = cn_lookup[wished_cn["name"]]
|
||||
decoded_target_cn = deepcopy(target_cn)
|
||||
decoded_target_cn["secret_environment_variables"] = SecretVariables.decode(decoded_target_cn["secret_environment_variables"],
|
||||
payload_cn["secret_environment_variables"])
|
||||
patch_payload = resource_attributes_should_be_changed(target=decoded_target_cn,
|
||||
wished=payload_cn,
|
||||
verifiable_mutable_attributes=MUTABLE_ATTRIBUTES,
|
||||
mutable_attributes=MUTABLE_ATTRIBUTES)
|
||||
decoded_target_cn["secret_environment_variables"] = SecretVariables.decode(
|
||||
decoded_target_cn["secret_environment_variables"], payload_cn["secret_environment_variables"]
|
||||
)
|
||||
patch_payload = resource_attributes_should_be_changed(
|
||||
target=decoded_target_cn,
|
||||
wished=payload_cn,
|
||||
verifiable_mutable_attributes=MUTABLE_ATTRIBUTES,
|
||||
mutable_attributes=MUTABLE_ATTRIBUTES,
|
||||
)
|
||||
|
||||
if not patch_payload:
|
||||
return changed, target_cn
|
||||
|
|
@ -229,21 +229,19 @@ def present_strategy(api, wished_cn):
|
|||
if api.module.check_mode:
|
||||
return changed, {"status": "Container namespace attributes would be changed."}
|
||||
|
||||
cn_patch_response = api.patch(path=f"{api.api_path}/{target_cn['id']}",
|
||||
data=patch_payload)
|
||||
cn_patch_response = api.patch(path=f"{api.api_path}/{target_cn['id']}", data=patch_payload)
|
||||
|
||||
if not cn_patch_response.ok:
|
||||
api.module.fail_json(msg=f"Error during container namespace attributes update: [{cn_patch_response.status_code}: {cn_patch_response.json['message']}]")
|
||||
api.module.fail_json(
|
||||
msg=f"Error during container namespace attributes update: [{cn_patch_response.status_code}: {cn_patch_response.json['message']}]"
|
||||
)
|
||||
|
||||
api.wait_to_complete_state_transition(resource=target_cn, stable_states=STABLE_STATES)
|
||||
response = api.get(path=f"{api.api_path}/{target_cn['id']}")
|
||||
return changed, cn_patch_response.json
|
||||
|
||||
|
||||
state_strategy = {
|
||||
"present": present_strategy,
|
||||
"absent": absent_strategy
|
||||
}
|
||||
state_strategy = {"present": present_strategy, "absent": absent_strategy}
|
||||
|
||||
|
||||
def core(module):
|
||||
|
|
@ -254,15 +252,17 @@ def core(module):
|
|||
"state": module.params["state"],
|
||||
"project_id": module.params["project_id"],
|
||||
"name": module.params["name"],
|
||||
"description": module.params['description'],
|
||||
"environment_variables": module.params['environment_variables'],
|
||||
"secret_environment_variables": module.params['secret_environment_variables']
|
||||
"description": module.params["description"],
|
||||
"environment_variables": module.params["environment_variables"],
|
||||
"secret_environment_variables": module.params["secret_environment_variables"],
|
||||
}
|
||||
|
||||
api = Scaleway(module=module)
|
||||
api.api_path = f"containers/v1beta1/regions/{region}/namespaces"
|
||||
|
||||
changed, summary = state_strategy[wished_container_namespace["state"]](api=api, wished_cn=wished_container_namespace)
|
||||
changed, summary = state_strategy[wished_container_namespace["state"]](
|
||||
api=api, wished_cn=wished_container_namespace
|
||||
)
|
||||
|
||||
module.exit_json(changed=changed, container_namespace=summary)
|
||||
|
||||
|
|
@ -270,15 +270,17 @@ 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']),
|
||||
project_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=''),
|
||||
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"]),
|
||||
project_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=""),
|
||||
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,
|
||||
|
|
@ -287,5 +289,5 @@ def main():
|
|||
core(module)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue