-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathpython_repository.py
More file actions
113 lines (96 loc) · 2.87 KB
/
python_repository.py
File metadata and controls
113 lines (96 loc) · 2.87 KB
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
#!/usr/bin/python
# copyright (c) 2020, Matthias Dellweg
# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
DOCUMENTATION = r"""
---
module: python_repository
short_description: Manage python repositories of a pulp api server instance
description:
- "This performs CRUD operations on python repositories in a pulp api server instance."
options:
name:
description:
- Name of the repository to query or manipulate
type: str
description:
description:
- Description of the repository
type: str
autopublish:
description:
- Publish new versions automatically.
required: false
type: bool
default: false
extends_documentation_fragment:
- pulp.squeezer.pulp.entity_state
- pulp.squeezer.pulp
author:
- Matthias Dellweg (@mdellweg)
"""
EXAMPLES = r"""
- name: Read list of python repositories from pulp api server
pulp.squeezer.python_repository:
pulp_url: https://pulp.example.org
username: admin
password: password
register: repo_status
- name: Report pulp python repositories
debug:
var: repo_status
- name: Create a python repository
pulp.squeezer.python_repository:
pulp_url: https://pulp.example.org
username: admin
password: password
name: new_repo
description: A brand new repository with a description
state: present
- name: Delete a python repository
pulp.squeezer.python_repository:
pulp_url: https://pulp.example.org
username: admin
password: password
name: new_repo
state: absent
"""
RETURN = r"""
repositories:
description: List of python repositories
type: list
returned: when no name is given
repository:
description: Python repository details
type: dict
returned: when name is given
"""
import traceback
from ansible_collections.pulp.squeezer.plugins.module_utils.pulp_glue import PulpEntityAnsibleModule
try:
from pulp_glue.python.context import PulpPythonRepositoryContext
PULP_GLUE_IMPORT_ERR = None
except ImportError:
PULP_GLUE_IMPORT_ERR = traceback.format_exc()
PulpPythonRepositoryContext = None
def main():
with PulpEntityAnsibleModule(
context_class=PulpPythonRepositoryContext,
entity_singular="repository",
entity_plural="repositories",
import_errors=[("pulp-glue", PULP_GLUE_IMPORT_ERR)],
argument_spec={
"name": {},
"description": {},
"autopublish": {"type": "bool"},
},
required_if=[("state", "present", ["name"]), ("state", "absent", ["name"])],
) as module:
natural_key = {"name": module.params["name"]}
desired_attributes = {
k: module.params[k]
for k in ("description", "autopublish")
if module.params.get(k) is not None
}
module.process(natural_key, desired_attributes)
if __name__ == "__main__":
main()