-
Notifications
You must be signed in to change notification settings - Fork 6
/
memsource_project.py
121 lines (101 loc) · 2.81 KB
/
memsource_project.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/env python
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = """
module: memsource_project
short_description: Manage a Memsource project
version_added: 0.0.1
description:
- Manage a Memsource project
author: 'Yanis Guenane (@Spredzy)'
options:
uid:
description:
- UID of the project
type: str
name:
description:
- A dict of filters to apply
required: false
default: {}
type: dict
template_id:
description:
- A dict of filters to apply
required: false
default: {}
type: dict
purge_on_delete:
description:
- Whether to purge the content of the project on delete
type: bool
extends_documentation_fragment:
- ansible.memsource.memsource
requirements: [memsource]
"""
EXAMPLES = """
- name: Create project from template id
ansible.memsource.memsource_project:
name: My Project
template_id: 12345
- name: Retrieve project information
ansible.memsource.memsource_project:
uid: uid
- name: Delete project
ansible.memsource.memsource_project:
uid: uid
state: absent
"""
RETURN = """
project:
returned: on success
description: >
Project's up to date information
type: dict
"""
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.ansible.memsource.plugins.module_utils.memsource import (
get_action,
get_default_argspec,
get_memsource_client,
)
def main():
argument_spec = get_default_argspec()
argument_spec.update(
dict(
uid=dict(type="str"),
name=dict(type="str"),
template_id=dict(type="int"),
purge_on_delete=dict(type="bool"),
state=dict(type="str", default="present", choices=["absent", "present"]),
),
)
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=False)
_memsource = get_memsource_client(module.params)
_action = get_action(module.params)
_result = {}
project = {}
if _action == "create":
if module.params.get("template_id"):
project = _memsource.create_project_from_template(
module.params.get("name"), module.params.get("template_id")
)
else:
pass
_result.update({"changed": True})
elif _action == "read":
project = _memsource.get_project_by_id(module.params["uid"])
elif _action == "update":
pass
else:
res = _memsource.delete_project(
module.params["uid"],
purge=module.params.get("purge_on_delete", False),
do_not_fail_on_404=True,
)
if res.status_code == 204:
_result.update({"changed": True})
_result.update({"project": project})
module.exit_json(**_result)
if __name__ == "__main__":
main()