Debian Codegraph @

ansible_collections/cisco/meraki/plugins/modules/meraki_mr_settings.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2018, Kevin Breit (@kbreit) <[email protected]>
5 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 from __future__ import absolute_import, division, print_function
8 __metaclass__ = type
9
10 ANSIBLE_METADATA = {
11 'metadata_version': '1.1',
12 "status": ['deprecated'],
13 'supported_by': 'community'
14 }
15
16 DOCUMENTATION = r'''
17 ---
18 module: meraki_mr_settings
19 short_description: Manage general settings for Meraki wireless networks
20 description:
21 - Allows for configuration of general settings in Meraki MR wireless networks.
22 deprecated:
23 removed_in: '3.0.0'
24 why: Updated modules released with increased functionality
25 alternative: cisco.meraki.networks_wireless_settings
26 options:
27 state:
28 description:
29 - Query or edit wireless settings.
30 type: str
31 choices: [ present, query]
32 default: present
33 net_name:
34 description:
35 - Name of network.
36 type: str
37 net_id:
38 description:
39 - ID of network.
40 type: str
41 upgrade_strategy:
42 description:
43 - The upgrade strategy to apply to the network.
44 - Requires firmware version MR 26.8 or higher.
45 choices: [ minimize_upgrade_time, minimize_client_downtime ]
46 type: str
47 ipv6_bridge_enabled:
48 description:
49 - Toggle for enabling or disabling IPv6 bridging in a network.
50 - If enabled, SSIDs must also be configured to use bridge mode.
51 type: bool
52 led_lights_on:
53 description:
54 - Toggle for enabling or disabling LED lights on all APs in the network.
55 type: bool
56 location_analytics_enabled:
57 description:
58 - Toggle for enabling or disabling location analytics for your network.
59 type: bool
60 meshing_enabled:
61 description: Toggle for enabling or disabling meshing in a network.
62 type: bool
63 author:
64 - Kevin Breit (@kbreit)
65 extends_documentation_fragment: cisco.meraki.meraki
66 '''
67
68 EXAMPLES = r'''
69 - name: Query all settings
70 meraki_mr_settings:
71 auth_key: abc123
72 org_name: YourOrg
73 net_name: YourNet
74 state: query
75 delegate_to: localhost
76 - name: Configure settings
77 meraki_mr_settings:
78 auth_key: abc123
79 org_name: YourOrg
80 net_name: YourNet
81 state: present
82 upgrade_strategy: minimize_upgrade_time
83 ipv6_bridge_enabled: false
84 led_lights_on: true
85 location_analytics_enabled: true
86 meshing_enabled: true
87 delegate_to: localhost
88 '''
89
90 RETURN = r'''
91 data:
92 description: List of wireless settings.
93 returned: success
94 type: complex
95 contains:
96 upgrade_strategy:
97 description:
98 - The upgrade strategy to apply to the network.
99 - Requires firmware version MR 26.8 or higher.
100 type: str
101 returned: success
102 sample: minimize_upgrade_time
103 ipv6_bridge_enabled:
104 description:
105 - Toggle for enabling or disabling IPv6 bridging in a network.
106 - If enabled, SSIDs must also be configured to use bridge mode.
107 type: bool
108 returned: success
109 sample: true
110 led_lights_on:
111 description:
112 - Toggle for enabling or disabling LED lights on all APs in the network.
113 type: bool
114 returned: success
115 sample: true
116 location_analytics_enabled:
117 description:
118 - Toggle for enabling or disabling location analytics for your network.
119 type: bool
120 returned: success
121 sample: true
122 meshing_enabled:
123 description: Toggle for enabling or disabling meshing in a network.
124 type: bool
125 returned: success
126 sample: true
127 '''
128
129 from ansible.module_utils.basic import AnsibleModule, json
130 from ansible_collections.cisco.meraki.plugins.module_utils.network.meraki.meraki import MerakiModule, meraki_argument_spec
131 from re import sub
132
133
134 def convert_to_camel_case(string):
135 string = sub(r"(_|-)+", " ", string).title().replace(" ", "")
136 return string[0].lower() + string[1:]
137
138
139 def construct_payload(meraki):
140 payload = {}
141 if meraki.params['upgrade_strategy'] is not None:
142 payload['upgradeStrategy'] = convert_to_camel_case(meraki.params['upgrade_strategy'])
143 if meraki.params['ipv6_bridge_enabled'] is not None:
144 payload['ipv6BridgeEnabled'] = meraki.params['ipv6_bridge_enabled']
145 if meraki.params['led_lights_on'] is not None:
146 payload['ledLightsOn'] = meraki.params['led_lights_on']
147 if meraki.params['location_analytics_enabled'] is not None:
148 payload['locationAnalyticsEnabled'] = meraki.params['location_analytics_enabled']
149 if meraki.params['meshing_enabled'] is not None:
150 payload['meshingEnabled'] = meraki.params['meshing_enabled']
151 return payload
152
153
154 def main():
155 # define the available arguments/parameters that a user can pass to
156 # the module
157 argument_spec = meraki_argument_spec()
158 argument_spec.update(state=dict(type='str', choices=['present', 'query'], default='present'),
159 org_name=dict(type='str', aliases=['organization']),
160 org_id=dict(type='str'),
161 net_name=dict(type='str'),
162 net_id=dict(type='str'),
163 upgrade_strategy=dict(type='str', choices=['minimize_upgrade_time',
164 'minimize_client_downtime']),
165 ipv6_bridge_enabled=dict(type='bool'),
166 led_lights_on=dict(type='bool'),
167 location_analytics_enabled=dict(type='bool'),
168 meshing_enabled=dict(type='bool'),
169 )
170
171 # the AnsibleModule object will be our abstraction working with Ansible
172 # this includes instantiation, a couple of common attr would be the
173 # args/params passed to the execution, as well as if the module
174 # supports check mode
175 module = AnsibleModule(argument_spec=argument_spec,
176 supports_check_mode=True,
177 )
178 meraki = MerakiModule(module, function='mr_settings')
179
180 meraki.params['follow_redirects'] = 'all'
181
182 query_urls = {'mr_settings': '/networks/{net_id}/wireless/settings'}
183 update_urls = {'mr_settings': '/networks/{net_id}/wireless/settings'}
184
185 meraki.url_catalog['get_one'].update(query_urls)
186 meraki.url_catalog['update'] = update_urls
187
188 org_id = meraki.params['org_id']
189 net_id = meraki.params['net_id']
190 if org_id is None:
191 org_id = meraki.get_org_id(meraki.params['org_name'])
192 if net_id is None:
193 nets = meraki.get_nets(org_id=org_id)
194 net_id = meraki.get_net_id(org_id, meraki.params['net_name'], data=nets)
195
196 if meraki.params['state'] == 'query':
197 path = meraki.construct_path('get_one', net_id=net_id)
198 response = meraki.request(path, method='GET')
199 meraki.result['data'] = response
200 meraki.exit_json(**meraki.result)
201 elif meraki.params['state'] == 'present':
202 path = meraki.construct_path('get_one', net_id=net_id)
203 original = meraki.request(path, method='GET')
204 payload = construct_payload(meraki)
205 if meraki.is_update_required(original, payload) is True:
206 if meraki.check_mode is True:
207 meraki.result['data'] = payload
208 meraki.result['changed'] = True
209 meraki.exit_json(**meraki.result)
210 path = meraki.construct_path('update', net_id=net_id)
211 response = meraki.request(path, method='PUT', payload=json.dumps(payload))
212 meraki.result['data'] = response
213 meraki.result['changed'] = True
214 meraki.exit_json(**meraki.result)
215 else:
216 meraki.result['data'] = original
217 meraki.exit_json(**meraki.result)
218
219 # in the event of a successful module execution, you will want to
220 # simple AnsibleModule.exit_json(), passing the key/value results
221 meraki.exit_json(**meraki.result)
222
223
224 if __name__ == '__main__':
225 main()