Debian Codegraph @

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

raw symbols SCIP
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 # (c) 2017, Matthias M Dellweg <[email protected]> (ATIX AG)
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: location
25 version_added: 1.0.0
26 short_description: Manage Locations
27 description:
28 - Manage Locations
29 author:
30 - "Matthias M Dellweg (@mdellweg) ATIX AG"
31 options:
32 name:
33 description:
34 - Name of the Location
35 required: true
36 type: str
37 description:
38 description:
39 - Description of the Location
40 required: false
41 type: str
42 version_added: 4.2.0
43 parent:
44 description:
45 - Title of a parent Location for nesting
46 type: str
47 organizations:
48 description:
49 - List of organizations the location should be assigned to
50 type: list
51 elements: str
52 ignore_types:
53 description:
54 - List of resources types that will be automatically associated
55 type: list
56 elements: str
57 required: false
58 aliases:
59 - select_all_types
60 version_added: 3.8.0
61 extends_documentation_fragment:
62 - theforeman.foreman.foreman
63 - theforeman.foreman.foreman.entity_state
64 - theforeman.foreman.foreman.nested_parameters
65 '''
66
67 EXAMPLES = '''
68 # Create a simple location
69 - name: "Create CI Location"
70 theforeman.foreman.location:
71 username: "admin"
72 password: "changeme"
73 server_url: "https://foreman.example.com"
74 name: "My Cool New Location"
75 organizations:
76 - "Default Organization"
77 state: present
78
79 # Create a nested location
80 - name: "Create Nested CI Location"
81 theforeman.foreman.location:
82 username: "admin"
83 password: "changeme"
84 server_url: "https://foreman.example.com"
85 name: "My Nested location"
86 parent: "My Cool New Location"
87 state: present
88
89 # Create a new nested location with parent included in name
90 - name: "Create New Nested Location"
91 theforeman.foreman.location:
92 username: "admin"
93 password: "changeme"
94 server_url: "https://foreman.example.com"
95 name: "My Cool New Location/New nested location"
96 state: present
97
98 # Move a nested location to another parent
99 - name: "Create Nested CI Location"
100 theforeman.foreman.location:
101 username: "admin"
102 password: "changeme"
103 server_url: "https://foreman.example.com"
104 name: "My Cool New Location/New nested location"
105 parent: "My Cool New Location/My Nested location"
106 state: present
107 '''
108
109 RETURN = '''
110 entity:
111 description: Final state of the affected entities grouped by their type.
112 returned: success
113 type: dict
114 contains:
115 locations:
116 description: List of locations.
117 type: list
118 elements: dict
119 '''
120
121 from ansible_collections.theforeman.foreman.plugins.module_utils.foreman_helper import ForemanEntityAnsibleModule, NestedParametersMixin
122
123
124 class ForemanLocationModule(NestedParametersMixin, ForemanEntityAnsibleModule):
125 pass
126
127
128 def main():
129 module = ForemanLocationModule(
130 foreman_spec=dict(
131 name=dict(required=True),
132 description=dict(required=False),
133 parent=dict(type='entity'),
134 organizations=dict(type='entity_list'),
135 ignore_types=dict(type='list', elements='str', required=False, aliases=['select_all_types']),
136 select_all_types=dict(type='list', invisible=True, flat_name='ignore_types'),
137 ),
138 )
139
140 with module.api_connection():
141 entity = module.lookup_entity('entity')
142
143 # workround the fact that the API expects `ignore_types` when modifying the entity
144 # but uses `select_all_types` when showing one
145 if entity and 'select_all_types' in entity:
146 entity['ignore_types'] = entity.pop('select_all_types')
147
148 module.run()
149
150
151 if __name__ == '__main__':
152 main()