Skip to content

Commit 4d5da24

Browse files
committed
ostree support
Signed-off-by: Andrew Block <andy.block@gmail.com>
1 parent 3b2345c commit 4d5da24

File tree

6 files changed

+673
-0
lines changed

6 files changed

+673
-0
lines changed

plugins/module_utils/pulp.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,3 +1203,89 @@ def _href(self):
12031203
if self.module.pulp_api.openapi_version == 2
12041204
else "container_container_repository_href"
12051205
)
1206+
1207+
1208+
# Ostree entities
1209+
1210+
1211+
class PulpOstreeRepository(PulpRepository):
1212+
_list_id = "repositories_ostree_ostree_list"
1213+
_read_id = "repositories_ostree_ostree_read"
1214+
_create_id = "repositories_ostree_ostree_create"
1215+
_update_id = "repositories_ostree_ostree_update"
1216+
_partial_update_id = "repositories_ostree_ostree_partial_update"
1217+
_delete_id = "repositories_ostree_ostree_delete"
1218+
_sync_id = "repositories_ostree_ostree_sync"
1219+
_import_commits_id = "repositories_ostree_ostree_import_commits"
1220+
1221+
_name_singular = "repository"
1222+
_name_plural = "repositories"
1223+
1224+
@property
1225+
def _href(self):
1226+
return (
1227+
"ostree_repository_href"
1228+
if self.module.pulp_api.openapi_version == 2
1229+
else "ostree_ostree_repository_href"
1230+
)
1231+
1232+
def import_commits(self, parameters=None):
1233+
1234+
repository_version = self.entity["latest_version_href"]
1235+
1236+
# In check_mode, assume nothing changed
1237+
if not self.module.check_mode:
1238+
1239+
response = self.module.pulp_api.call(
1240+
self._import_commits_id, parameters=self.primary_key, body=parameters
1241+
)
1242+
1243+
PulpTask(self.module, {"pulp_href": response["task"]}).wait_for()
1244+
1245+
self.find()
1246+
1247+
if repository_version != self.entity["latest_version_href"]:
1248+
repository_version = self.entity["latest_version_href"]
1249+
self.module.set_changed()
1250+
1251+
self.module.set_result("repository_version", repository_version)
1252+
1253+
1254+
class PulpOstreeDistribution(PulpEntity):
1255+
_list_id = "distributions_ostree_ostree_list"
1256+
_read_id = "distributions_ostree_ostree_read"
1257+
_create_id = "distributions_ostree_ostree_create"
1258+
_update_id = "distributions_ostree_ostree_update"
1259+
_partial_update_id = "distributions_ostree_ostree_partial_update"
1260+
_delete_id = "distributions_ostree_ostree_delete"
1261+
1262+
_name_singular = "distribution"
1263+
_name_plural = "distributions"
1264+
1265+
@property
1266+
def _href(self):
1267+
return (
1268+
"ostree_distribution_href"
1269+
if self.module.pulp_api.openapi_version == 2
1270+
else "ostree_ostree_distribution_href"
1271+
)
1272+
1273+
1274+
class PulpOstreeRemote(PulpRemote):
1275+
_list_id = "remotes_ostree_ostree_list"
1276+
_read_id = "remotes_ostree_ostree_read"
1277+
_create_id = "remotes_ostree_ostree_create"
1278+
_update_id = "remotes_ostree_ostree_update"
1279+
_partial_update_id = "remotes_ostree_ostree_partial_update"
1280+
_delete_id = "remotes_ostree_ostree_delete"
1281+
1282+
_name_singular = "remote"
1283+
_name_plural = "remotes"
1284+
1285+
@property
1286+
def _href(self):
1287+
return (
1288+
"ostree_remote_href"
1289+
if self.module.pulp_api.openapi_version == 2
1290+
else "ostree_ostree_remote_href"
1291+
)
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
#!/usr/bin/python
2+
# -*- coding: utf-8 -*-
3+
4+
# copyright (c) 2019, Matthias Dellweg
5+
# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
6+
7+
from __future__ import absolute_import, division, print_function
8+
9+
__metaclass__ = type
10+
11+
12+
DOCUMENTATION = r"""
13+
---
14+
module: ostree_distribution
15+
short_description: Manage ostree distributions of a pulp api server instance
16+
description:
17+
- "This performs CRUD operations on ostree distributions in a pulp api server instance."
18+
options:
19+
name:
20+
description:
21+
- Name of the distribution to query or manipulate
22+
type: str
23+
required: true
24+
base_path:
25+
description:
26+
- Base path to the distribution
27+
type: str
28+
required: true
29+
repository:
30+
description:
31+
- Name of the repository
32+
type: str
33+
required: false
34+
version:
35+
description:
36+
- Repository version number
37+
type: str
38+
required: false
39+
content_guard:
40+
description:
41+
- Name of the content guard for the served content
42+
- "Warning: This feature is not yet supported."
43+
type: str
44+
required: false
45+
extends_documentation_fragment:
46+
- pulp.squeezer.pulp
47+
- pulp.squeezer.pulp.entity_state
48+
author:
49+
- Andrew Block (@sabre1041)
50+
"""
51+
52+
EXAMPLES = r"""
53+
- name: Read list of ostree distributions from pulp api server
54+
pulp.squeezer.ostree_distribution:
55+
pulp_url: https://pulp.example.org
56+
username: admin
57+
password: password
58+
register: distribution_status
59+
- name: Report pulp ostree distributions
60+
debug:
61+
var: distribution_status
62+
63+
- name: Create a ostree distribution
64+
pulp.squeezer.ostree_distribution:
65+
pulp_url: https://pulp.example.org
66+
username: admin
67+
password: password
68+
name: new_ostree_distribution
69+
base_path: new/ostree/dist
70+
repository: ostree_repository
71+
state: present
72+
73+
- name: Delete a ostree distribution
74+
pulp.squeezer.ostree_distribution:
75+
pulp_url: https://pulp.example.org
76+
username: admin
77+
password: password
78+
name: new_ostree_distribution
79+
state: absent
80+
"""
81+
82+
RETURN = r"""
83+
distributions:
84+
description: List of ostree distributions
85+
type: list
86+
returned: when no name is given
87+
distribution:
88+
description: Ostree distribution details
89+
type: dict
90+
returned: when name is given
91+
"""
92+
93+
94+
from ansible_collections.pulp.squeezer.plugins.module_utils.pulp import (
95+
PulpEntityAnsibleModule,
96+
PulpOstreeDistribution,
97+
PulpContentGuard,
98+
)
99+
100+
101+
def main():
102+
with PulpEntityAnsibleModule(
103+
argument_spec=dict(
104+
name=dict(required=True),
105+
base_path=dict(required=True),
106+
repository=dict(),
107+
version=dict(),
108+
content_guard=dict(),
109+
),
110+
required_if=[
111+
("state", "present", ["name", "base_path"]),
112+
("state", "absent", ["name"]),
113+
],
114+
) as module:
115+
116+
content_guard_name = module.params["content_guard"]
117+
118+
natural_key = {
119+
"name": module.params["name"],
120+
}
121+
desired_attributes = {
122+
key: module.params[key]
123+
for key in ["base_path", "repository"]
124+
if module.params[key] is not None
125+
}
126+
127+
if content_guard_name is not None:
128+
if content_guard_name:
129+
content_guard = PulpContentGuard(module, {"name": content_guard_name})
130+
content_guard.find(failsafe=False)
131+
desired_attributes["content_guard"] = content_guard.href
132+
else:
133+
desired_attributes["content_guard"] = None
134+
135+
if module.params["version"] is not None:
136+
desired_attributes["version"] = module.params["version"] or None
137+
138+
PulpOstreeDistribution(module, natural_key, desired_attributes).process()
139+
140+
141+
if __name__ == "__main__":
142+
main()

plugins/modules/ostree_remote.py

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#!/usr/bin/python
2+
# -*- coding: utf-8 -*-
3+
4+
# copyright (c) 2022, Andrew Block
5+
# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
6+
7+
from __future__ import absolute_import, division, print_function
8+
9+
__metaclass__ = type
10+
11+
12+
DOCUMENTATION = r"""
13+
---
14+
module: ostree_remote
15+
short_description: Manage ostree remotes of a pulp api server instance
16+
description:
17+
- "This performs CRUD operations on ostree remotes in a pulp api server instance."
18+
options:
19+
policy:
20+
description:
21+
- Whether downloads should be performed immediately, or lazy.
22+
type: str
23+
choices:
24+
- immediate
25+
- on_demand
26+
- streamed
27+
extends_documentation_fragment:
28+
- pulp.squeezer.pulp
29+
- pulp.squeezer.pulp.entity_state
30+
- pulp.squeezer.pulp.remote
31+
author:
32+
- Andrew Block (@sabre1041)
33+
"""
34+
35+
EXAMPLES = r"""
36+
- name: Read list of ostree remotes from pulp api server
37+
pulp.squeezer.ostree_remote:
38+
pulp_url: https://pulp.example.org
39+
username: admin
40+
password: password
41+
register: remote_status
42+
- name: Report pulp ostree remotes
43+
debug:
44+
var: remote_status
45+
46+
- name: Create a ostree remote
47+
pulp.squeezer.ostree_remote:
48+
pulp_url: https://pulp.example.org
49+
username: admin
50+
password: password
51+
name: new_ostree_remote
52+
url: http://localhost/pub//pulp_manifest
53+
state: present
54+
55+
- name: Delete a ostree remote
56+
pulp.squeezer.ostree_remote:
57+
pulp_url: https://pulp.example.org
58+
username: admin
59+
password: password
60+
name: new_ostree_remote
61+
state: absent
62+
"""
63+
64+
RETURN = r"""
65+
remotes:
66+
description: List of ostree remotes
67+
type: list
68+
returned: when no name is given
69+
remote:
70+
description: Ostree remote details
71+
type: dict
72+
returned: when name is given
73+
"""
74+
75+
76+
from ansible_collections.pulp.squeezer.plugins.module_utils.pulp import (
77+
PulpRemoteAnsibleModule,
78+
PulpOstreeRemote,
79+
)
80+
81+
82+
def main():
83+
with PulpRemoteAnsibleModule(
84+
argument_spec=dict(
85+
policy=dict(choices=["immediate", "on_demand", "streamed"]),
86+
),
87+
required_if=[("state", "present", ["name"]), ("state", "absent", ["name"])],
88+
) as module:
89+
90+
natural_key = {"name": module.params["name"]}
91+
desired_attributes = {
92+
key: module.params[key]
93+
for key in ["url", "download_concurrency", "policy", "tls_validation"]
94+
if module.params[key] is not None
95+
}
96+
97+
# Nullifiable values
98+
if module.params["remote_username"] is not None:
99+
desired_attributes["username"] = module.params["remote_username"] or None
100+
if module.params["remote_password"] is not None:
101+
desired_attributes["password"] = module.params["remote_password"] or None
102+
desired_attributes.update(
103+
{
104+
key: module.params[key] or None
105+
for key in [
106+
"proxy_url",
107+
"proxy_username",
108+
"proxy_password",
109+
"ca_cert",
110+
"client_cert",
111+
"client_key",
112+
]
113+
if module.params[key] is not None
114+
}
115+
)
116+
117+
PulpOstreeRemote(module, natural_key, desired_attributes).process()
118+
119+
120+
if __name__ == "__main__":
121+
main()

0 commit comments

Comments
 (0)