Debian Codegraph @

ansible_collections/theforeman/foreman/plugins/modules/repository_info.py

raw symbols SCIP
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 # (c) 2020 Evgeni Golov
4 #
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 from __future__ import absolute_import, division, print_function
19 __metaclass__ = type
20
21
22 DOCUMENTATION = '''
23 ---
24 module: repository_info
25 version_added: 2.0.0
26 short_description: Fetch information about Repositories
27 description:
28 - Fetch information about Repositories
29 author: "Evgeni Golov (@evgeni)"
30 options:
31 product:
32 description:
33 - Product to which the repository lives in
34 required: true
35 type: str
36 extends_documentation_fragment:
37 - theforeman.foreman.foreman
38 - theforeman.foreman.foreman.katelloinfomodule
39 - theforeman.foreman.foreman.infomodule
40 '''
41
42 EXAMPLES = '''
43 - name: "Find repository by name"
44 theforeman.foreman.repository_info:
45 username: "admin"
46 password: "changeme"
47 server_url: "https://foreman.example.com"
48 name: "My repository"
49 product: "My Product"
50 organization: "Default Organization"
51
52 - name: "Find repository using a search"
53 theforeman.foreman.repository_info:
54 username: "admin"
55 password: "changeme"
56 server_url: "https://foreman.example.com"
57 product: "My Product"
58 organization: "Default Organization"
59 search: 'name = "My repository"'
60 '''
61
62 RETURN = '''
63 repository:
64 description: Details about the found repository
65 returned: success and I(name) was passed
66 type: dict
67 repositories:
68 description: List of all found repositories and their details
69 returned: success and I(search) was passed
70 type: list
71 elements: dict
72 '''
73
74
75 from ansible_collections.theforeman.foreman.plugins.module_utils.foreman_helper import KatelloInfoAnsibleModule
76
77
78 class KatelloRepositoryInfo(KatelloInfoAnsibleModule):
79 pass
80
81
82 def main():
83 module = KatelloRepositoryInfo(
84 foreman_spec=dict(
85 product=dict(type='entity', scope=['organization'], required=True),
86 ),
87 entity_opts={'scope': ['product']},
88 )
89
90 # KatelloInfoAnsibleModule automatically adds organization to the entity scope
91 # but repositories are scoped by product (and these are org scoped)
92 module.foreman_spec['entity']['scope'].remove('organization')
93
94 with module.api_connection():
95 module.run()
96
97
98 if __name__ == '__main__':
99 main()