Debian Codegraph @

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

raw symbols SCIP
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 # (c) 2016, Eric D Helms <[email protected]>
4 # (c) 2017, Matthias M Dellweg <[email protected]> (ATIX AG)
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: organization
26 version_added: 1.0.0
27 short_description: Manage Organizations
28 description:
29 - Manage Organizations
30 author:
31 - "Eric D Helms (@ehelms)"
32 - "Matthias M Dellweg (@mdellweg) ATIX AG"
33 options:
34 name:
35 description:
36 - Name of the Organization
37 required: true
38 type: str
39 description:
40 description:
41 - Description of the Organization
42 required: false
43 type: str
44 label:
45 description:
46 - Label of the Organization
47 type: str
48 ignore_types:
49 description:
50 - List of resources types that will be automatically associated
51 type: list
52 elements: str
53 required: false
54 aliases:
55 - select_all_types
56 version_added: 3.8.0
57 extends_documentation_fragment:
58 - theforeman.foreman.foreman
59 - theforeman.foreman.foreman.entity_state
60 - theforeman.foreman.foreman.nested_parameters
61 '''
62
63 EXAMPLES = '''
64 - name: "Create CI Organization"
65 theforeman.foreman.organization:
66 username: "admin"
67 password: "changeme"
68 server_url: "https://foreman.example.com"
69 name: "My Cool New Organization"
70 state: present
71 '''
72
73 RETURN = '''
74 entity:
75 description: Final state of the affected entities grouped by their type.
76 returned: success
77 type: dict
78 contains:
79 organizations:
80 description: List of organizations.
81 type: list
82 elements: dict
83 '''
84
85
86 from ansible_collections.theforeman.foreman.plugins.module_utils.foreman_helper import ForemanEntityAnsibleModule, NestedParametersMixin
87
88
89 class ForemanOrganizationModule(NestedParametersMixin, ForemanEntityAnsibleModule):
90 pass
91
92
93 def main():
94 module = ForemanOrganizationModule(
95 foreman_spec=dict(
96 name=dict(required=True),
97 description=dict(),
98 label=dict(),
99 ignore_types=dict(type='list', elements='str', required=False, aliases=['select_all_types']),
100 select_all_types=dict(type='list', invisible=True, flat_name='ignore_types'),
101 ),
102 )
103
104 with module.api_connection():
105 entity = module.lookup_entity('entity')
106
107 # workround the fact that the API expects `ignore_types` when modifying the entity
108 # but uses `select_all_types` when showing one
109 if entity and 'select_all_types' in entity:
110 entity['ignore_types'] = entity.pop('select_all_types')
111
112 module.run()
113
114
115 if __name__ == '__main__':
116 main()