Skip to content

Commit

Permalink
ostree support
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Block <[email protected]>
  • Loading branch information
sabre1041 committed Jun 14, 2022
1 parent 3b2345c commit 4d5da24
Show file tree
Hide file tree
Showing 6 changed files with 673 additions and 0 deletions.
86 changes: 86 additions & 0 deletions plugins/module_utils/pulp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1203,3 +1203,89 @@ def _href(self):
if self.module.pulp_api.openapi_version == 2
else "container_container_repository_href"
)


# Ostree entities


class PulpOstreeRepository(PulpRepository):
_list_id = "repositories_ostree_ostree_list"
_read_id = "repositories_ostree_ostree_read"
_create_id = "repositories_ostree_ostree_create"
_update_id = "repositories_ostree_ostree_update"
_partial_update_id = "repositories_ostree_ostree_partial_update"
_delete_id = "repositories_ostree_ostree_delete"
_sync_id = "repositories_ostree_ostree_sync"
_import_commits_id = "repositories_ostree_ostree_import_commits"

_name_singular = "repository"
_name_plural = "repositories"

@property
def _href(self):
return (
"ostree_repository_href"
if self.module.pulp_api.openapi_version == 2
else "ostree_ostree_repository_href"
)

def import_commits(self, parameters=None):

repository_version = self.entity["latest_version_href"]

# In check_mode, assume nothing changed
if not self.module.check_mode:

response = self.module.pulp_api.call(
self._import_commits_id, parameters=self.primary_key, body=parameters
)

PulpTask(self.module, {"pulp_href": response["task"]}).wait_for()

self.find()

if repository_version != self.entity["latest_version_href"]:
repository_version = self.entity["latest_version_href"]
self.module.set_changed()

self.module.set_result("repository_version", repository_version)


class PulpOstreeDistribution(PulpEntity):
_list_id = "distributions_ostree_ostree_list"
_read_id = "distributions_ostree_ostree_read"
_create_id = "distributions_ostree_ostree_create"
_update_id = "distributions_ostree_ostree_update"
_partial_update_id = "distributions_ostree_ostree_partial_update"
_delete_id = "distributions_ostree_ostree_delete"

_name_singular = "distribution"
_name_plural = "distributions"

@property
def _href(self):
return (
"ostree_distribution_href"
if self.module.pulp_api.openapi_version == 2
else "ostree_ostree_distribution_href"
)


class PulpOstreeRemote(PulpRemote):
_list_id = "remotes_ostree_ostree_list"
_read_id = "remotes_ostree_ostree_read"
_create_id = "remotes_ostree_ostree_create"
_update_id = "remotes_ostree_ostree_update"
_partial_update_id = "remotes_ostree_ostree_partial_update"
_delete_id = "remotes_ostree_ostree_delete"

_name_singular = "remote"
_name_plural = "remotes"

@property
def _href(self):
return (
"ostree_remote_href"
if self.module.pulp_api.openapi_version == 2
else "ostree_ostree_remote_href"
)
142 changes: 142 additions & 0 deletions plugins/modules/ostree_distribution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# copyright (c) 2019, Matthias Dellweg
# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function

__metaclass__ = type


DOCUMENTATION = r"""
---
module: ostree_distribution
short_description: Manage ostree distributions of a pulp api server instance
description:
- "This performs CRUD operations on ostree distributions in a pulp api server instance."
options:
name:
description:
- Name of the distribution to query or manipulate
type: str
required: true
base_path:
description:
- Base path to the distribution
type: str
required: true
repository:
description:
- Name of the repository
type: str
required: false
version:
description:
- Repository version number
type: str
required: false
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
- pulp.squeezer.pulp.entity_state
author:
- Andrew Block (@sabre1041)
"""

EXAMPLES = r"""
- name: Read list of ostree distributions from pulp api server
pulp.squeezer.ostree_distribution:
pulp_url: https://pulp.example.org
username: admin
password: password
register: distribution_status
- name: Report pulp ostree distributions
debug:
var: distribution_status
- name: Create a ostree distribution
pulp.squeezer.ostree_distribution:
pulp_url: https://pulp.example.org
username: admin
password: password
name: new_ostree_distribution
base_path: new/ostree/dist
repository: ostree_repository
state: present
- name: Delete a ostree distribution
pulp.squeezer.ostree_distribution:
pulp_url: https://pulp.example.org
username: admin
password: password
name: new_ostree_distribution
state: absent
"""

RETURN = r"""
distributions:
description: List of ostree distributions
type: list
returned: when no name is given
distribution:
description: Ostree distribution details
type: dict
returned: when name is given
"""


from ansible_collections.pulp.squeezer.plugins.module_utils.pulp import (
PulpEntityAnsibleModule,
PulpOstreeDistribution,
PulpContentGuard,
)


def main():
with PulpEntityAnsibleModule(
argument_spec=dict(
name=dict(required=True),
base_path=dict(required=True),
repository=dict(),
version=dict(),
content_guard=dict(),
),
required_if=[
("state", "present", ["name", "base_path"]),
("state", "absent", ["name"]),
],
) as module:

content_guard_name = module.params["content_guard"]

natural_key = {
"name": module.params["name"],
}
desired_attributes = {
key: module.params[key]
for key in ["base_path", "repository"]
if module.params[key] is not None
}

if content_guard_name is not None:
if content_guard_name:
content_guard = PulpContentGuard(module, {"name": content_guard_name})
content_guard.find(failsafe=False)
desired_attributes["content_guard"] = content_guard.href
else:
desired_attributes["content_guard"] = None

if module.params["version"] is not None:
desired_attributes["version"] = module.params["version"] or None

PulpOstreeDistribution(module, natural_key, desired_attributes).process()


if __name__ == "__main__":
main()
121 changes: 121 additions & 0 deletions plugins/modules/ostree_remote.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# copyright (c) 2022, Andrew Block
# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function

__metaclass__ = type


DOCUMENTATION = r"""
---
module: ostree_remote
short_description: Manage ostree remotes of a pulp api server instance
description:
- "This performs CRUD operations on ostree remotes in a pulp api server instance."
options:
policy:
description:
- Whether downloads should be performed immediately, or lazy.
type: str
choices:
- immediate
- on_demand
- streamed
extends_documentation_fragment:
- pulp.squeezer.pulp
- pulp.squeezer.pulp.entity_state
- pulp.squeezer.pulp.remote
author:
- Andrew Block (@sabre1041)
"""

EXAMPLES = r"""
- name: Read list of ostree remotes from pulp api server
pulp.squeezer.ostree_remote:
pulp_url: https://pulp.example.org
username: admin
password: password
register: remote_status
- name: Report pulp ostree remotes
debug:
var: remote_status
- name: Create a ostree remote
pulp.squeezer.ostree_remote:
pulp_url: https://pulp.example.org
username: admin
password: password
name: new_ostree_remote
url: http://localhost/pub//pulp_manifest
state: present
- name: Delete a ostree remote
pulp.squeezer.ostree_remote:
pulp_url: https://pulp.example.org
username: admin
password: password
name: new_ostree_remote
state: absent
"""

RETURN = r"""
remotes:
description: List of ostree remotes
type: list
returned: when no name is given
remote:
description: Ostree remote details
type: dict
returned: when name is given
"""


from ansible_collections.pulp.squeezer.plugins.module_utils.pulp import (
PulpRemoteAnsibleModule,
PulpOstreeRemote,
)


def main():
with PulpRemoteAnsibleModule(
argument_spec=dict(
policy=dict(choices=["immediate", "on_demand", "streamed"]),
),
required_if=[("state", "present", ["name"]), ("state", "absent", ["name"])],
) as module:

natural_key = {"name": module.params["name"]}
desired_attributes = {
key: module.params[key]
for key in ["url", "download_concurrency", "policy", "tls_validation"]
if module.params[key] is not None
}

# Nullifiable values
if module.params["remote_username"] is not None:
desired_attributes["username"] = module.params["remote_username"] or None
if module.params["remote_password"] is not None:
desired_attributes["password"] = module.params["remote_password"] or None
desired_attributes.update(
{
key: module.params[key] or None
for key in [
"proxy_url",
"proxy_username",
"proxy_password",
"ca_cert",
"client_cert",
"client_key",
]
if module.params[key] is not None
}
)

PulpOstreeRemote(module, natural_key, desired_attributes).process()


if __name__ == "__main__":
main()
Loading

0 comments on commit 4d5da24

Please sign in to comment.