-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathdeb_distribution.py
More file actions
169 lines (147 loc) · 4.71 KB
/
deb_distribution.py
File metadata and controls
169 lines (147 loc) · 4.71 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/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: deb_distribution
short_description: Manage deb distributions of a pulp api server instance
description:
- "This performs CRUD operations on deb distributions in a pulp api server instance."
options:
name:
description:
- Name of the distribution to query or manipulate
type: str
required: false
base_path:
description:
- Base path to distribute a publication
type: str
required: false
publication:
description:
- Href of the publication to be served
type: str
required: false
repository:
description:
- Name of the repository to be served
type: str
required: false
version_added: "0.2.4"
content_guard:
description:
- Name of the content guard for the served content
- "Warning: This feature is not yet supported."
type: str
required: false
extends_documentation_fragment:
- pulp.squeezer.pulp.entity_state
- pulp.squeezer.pulp
author:
- Matthias Dellweg (@mdellweg)
"""
EXAMPLES = r"""
- name: Read list of deb distributions from pulp api server
pulp.squeezer.deb_distribution:
pulp_url: https://pulp.example.org
username: admin
password: password
register: distribution_status
- name: Report pulp deb distributions
debug:
var: distribution_status
- name: Create a deb distribution
pulp.squeezer.deb_distribution:
pulp_url: https://pulp.example.org
username: admin
password: password
name: new_deb_distribution
base_path: new/deb/dist
publication: /pub/api/v3/publications/deb/deb/aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa/
state: present
- name: Delete a deb distribution
pulp.squeezer.deb_distribution:
pulp_url: https://pulp.example.org
username: admin
password: password
name: new_deb_distribution
state: absent
"""
RETURN = r"""
distributions:
description: List of deb distributions
type: list
returned: when no name is given
distribution:
description: Deb distribution details
type: dict
returned: when name is given
"""
import traceback
from ansible_collections.pulp.squeezer.plugins.module_utils.pulp_glue import (
GLUE_DEB_VERSION_SPEC,
PulpEntityAnsibleModule,
assert_version,
)
try:
from pulp_glue.core.context import PulpContentGuardContext
PULP_GLUE_IMPORT_ERR = None
except ImportError:
PULP_GLUE_IMPORT_ERR = traceback.format_exc()
try:
from pulp_glue.deb import __version__ as pulp_glue_deb_version
from pulp_glue.deb.context import PulpAptDistributionContext, PulpAptRepositoryContext
assert_version(GLUE_DEB_VERSION_SPEC, pulp_glue_deb_version, "pulp-glue-deb")
PULP_GLUE_DEB_IMPORT_ERR = None
except ImportError:
PULP_GLUE_DEB_IMPORT_ERR = traceback.format_exc()
PulpAptDistributionContext = None
def main():
with PulpEntityAnsibleModule(
context_class=PulpAptDistributionContext,
entity_singular="distribution",
entity_plural="distributions",
import_errors=[
("pulp-glue", PULP_GLUE_IMPORT_ERR),
("pulp-glue-deb", PULP_GLUE_DEB_IMPORT_ERR),
],
argument_spec={
"name": {},
"base_path": {},
"publication": {},
"repository": {},
"content_guard": {},
},
required_if=[
("state", "present", ["name", "base_path"]),
("state", "absent", ["name"]),
],
) as module:
content_guard_name = module.params["content_guard"]
repository_name = module.params["repository"]
natural_key = {"name": module.params["name"]}
desired_attributes = {
key: module.params[key]
for key in ["base_path", "publication"]
if module.params[key] is not None
}
if repository_name is not None:
if repository_name:
repository_ctx = PulpAptRepositoryContext(
module.pulp_ctx, entity={"name": repository_name}
)
desired_attributes["repository"] = repository_ctx.pulp_href
else:
desired_attributes["repository"] = ""
if content_guard_name is not None:
if content_guard_name:
content_guard_ctx = PulpContentGuardContext(
module.pulp_ctx, entity={"name": content_guard_name}
)
desired_attributes["content_guard"] = content_guard_ctx.pulp_href
else:
desired_attributes["content_guard"] = ""
module.process(natural_key, desired_attributes)
if __name__ == "__main__":
main()