Debian Codegraph @

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

raw symbols SCIP
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 # (c) 2016, Eric D Helms <[email protected]>
4 # (c) 2019, Matthias M Dellweg <[email protected]>
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19 from __future__ import absolute_import, division, print_function
20 __metaclass__ = type
21
22
23 DOCUMENTATION = '''
24 ---
25 module: repository_sync
26 version_added: 1.0.0
27 short_description: Sync a Repository or Product
28 description:
29 - Sync a repository or product
30 author:
31 - "Eric D Helms (@ehelms)"
32 - "Matthias M Dellweg (@mdellweg) ATIX AG"
33 options:
34 product:
35 description: Product to which the I(repository) lives in
36 required: true
37 type: str
38 repository:
39 description: |
40 Name of the repository to sync
41 If omitted, all repositories in I(product) are synched.
42 type: str
43 extends_documentation_fragment:
44 - theforeman.foreman.foreman
45 - theforeman.foreman.foreman.organization
46 ...
47 '''
48
49 EXAMPLES = '''
50 - name: "Sync repository"
51 theforeman.foreman.repository_sync:
52 username: "admin"
53 password: "changeme"
54 server_url: "https://foreman.example.com"
55 repository: "My repository"
56 product: "My Product"
57 organization: "Default Organization"
58 '''
59
60 RETURN = ''' # '''
61
62 from ansible_collections.theforeman.foreman.plugins.module_utils.foreman_helper import KatelloAnsibleModule
63
64
65 def main():
66 module = KatelloAnsibleModule(
67 foreman_spec=dict(
68 product=dict(type='entity', scope=['organization'], required=True),
69 repository=dict(type='entity', scope=['product']),
70 ),
71 )
72
73 module.task_timeout = 12 * 60 * 60
74
75 with module.api_connection():
76 product = module.lookup_entity('product')
77 repository = module.lookup_entity('repository')
78 if repository:
79 task = module.resource_action('repositories', 'sync', {'id': repository['id']})
80 else:
81 task = module.resource_action('products', 'sync', {'id': product['id']})
82
83 module.exit_json(task=task)
84
85
86 if __name__ == '__main__':
87 main()