|
| 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() |
0 commit comments