Skip to content

Commit

Permalink
Add rpm_package module
Browse files Browse the repository at this point in the history
Based on PR #34 on the work by Jacob Floyd (@cognifloyd).

Co-authored-by: Jacob Floyd <[email protected]>
Signed-off-by: Daniel Ziegenberg <[email protected]>
  • Loading branch information
ziegenberg and cognifloyd committed Aug 1, 2022
1 parent f3bc3f5 commit 2a61527
Show file tree
Hide file tree
Showing 5 changed files with 29,269 additions and 0 deletions.
17 changes: 17 additions & 0 deletions plugins/module_utils/pulp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,23 @@ def _href(self):
)


class PulpRpmPackageContent(PulpFileContent): # reuse the create() method
_list_id = "content_rpm_packages_list"
_read_id = "content_rpm_packages_read"
_create_id = "content_rpm_packages_create"

_name_singular = "package"
_name_plural = "packages"

@property
def _href(self):
return (
"package_href" # TODO: is this right for openapi 2?
if self.module.pulp_api.openapi_version == 2
else "rpm_package_href"
)


# Container entities


Expand Down
103 changes: 103 additions & 0 deletions plugins/modules/rpm_package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# copyright (c) 2020, Jacob Floyd
# 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: rpm_package
short_description: Manage rpm package content of a pulp api server instance
description:
- "This performs Create/Read operations on rpm package content in a pulp api server instance."
- "The API does not have a delete or update operation on rpm packages (ie there is no state=absent for this module)."
options:
sha256:
description:
- sha256 digest of the rpm package content to query or manipulate
type: str
aliases:
- digest
relative_path:
description:
- Relative path of the rpm package content unit (ignored unless creating the package)
type: str
extends_documentation_fragment:
- pulp.squeezer.pulp
- pulp.squeezer.pulp.entity_state
author:
- Jacob Floyd (@cognifloyd)
- Daniel Ziegenberg (@ziegenberg)
"""

EXAMPLES = r"""
- name: Read list of rpm package content units from pulp api server
rpm_package:
api_url: localhost:24817
username: admin
password: password
register: content_status
- name: Report pulp rpm package content units
debug:
var: content_status
- name: Create a rpm package content unit
rpm_package:
api_url: localhost:24817
username: admin
password: password
sha256: 0000111122223333444455556666777788889999aaaabbbbccccddddeeeeffff
relative_path: "data/important_package.rpm"
state: present
"""

RETURN = r"""
packages:
description: List of rpm package content units
type: list
returned: when digest or relative_path is not given
package:
description: The rpm package content unit details
type: dict
returned: when digest and relative_path is given
"""


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


DESIRED_KEYS = {"relative_path"}


def main():
with PulpEntityAnsibleModule(
argument_spec=dict(
sha256=dict(aliases=["digest"]),
relative_path=dict(),
),
required_if=[
("state", "present", ["sha256"]),
],
) as module:

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

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


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

0 comments on commit 2a61527

Please sign in to comment.