Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rpm_package module #105

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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