Debian Codegraph @

ansible_collections/cisco/meraki/plugins/action/networks_wireless_zigbee.py

raw
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 # Copyright (c) 2021, Cisco Systems
5 # GNU General Public License v3.0+ (see LICENSE or
6 # https://www.gnu.org/licenses/gpl-3.0.txt)
7
8 from __future__ import (absolute_import, division, print_function)
9 __metaclass__ = type
10 from ansible.plugins.action import ActionBase
11 try:
12 from ansible_collections.ansible.utils.plugins.module_utils.common.argspec_validate import (
13 AnsibleArgSpecValidator, )
14 except ImportError:
15 ANSIBLE_UTILS_IS_INSTALLED = False
16 else:
17 ANSIBLE_UTILS_IS_INSTALLED = True
18 from ansible.errors import AnsibleActionFail
19 from ansible_collections.cisco.meraki.plugins.plugin_utils.meraki import (
20 MERAKI,
21 meraki_argument_spec,
22 )
23
24 # Get common arguements specification
25 argument_spec = meraki_argument_spec()
26 # Add arguments specific for this module
27 argument_spec.update(dict(
28 enabled=dict(type="bool"),
29 iotController=dict(type="dict"),
30 lockManagement=dict(type="dict"),
31 defaults=dict(type="dict"),
32 networkId=dict(type="str"),
33 ))
34
35 required_if = []
36 required_one_of = []
37 mutually_exclusive = []
38 required_together = []
39
40
41 class ActionModule(ActionBase):
42 def __init__(self, *args, **kwargs):
43 if not ANSIBLE_UTILS_IS_INSTALLED:
44 raise AnsibleActionFail(
45 "ansible.utils is not installed. Execute 'ansible-galaxy collection install ansible.utils'")
46 super(ActionModule, self).__init__(*args, **kwargs)
47 self._supports_async = False
48 self._supports_check_mode = False
49 self._result = None
50
51 # Checks the supplied parameters against the argument spec for this module
52 def _check_argspec(self):
53 aav = AnsibleArgSpecValidator(
54 data=self._task.args,
55 schema=dict(argument_spec=argument_spec),
56 schema_format="argspec",
57 schema_conditionals=dict(
58 required_if=required_if,
59 required_one_of=required_one_of,
60 mutually_exclusive=mutually_exclusive,
61 required_together=required_together,
62 ),
63 name=self._task.action,
64 )
65 valid, errors, self._task.args = aav.validate()
66 if not valid:
67 raise AnsibleActionFail(errors)
68
69 def get_object(self, params):
70 new_object = dict(
71 enabled=params.get("enabled"),
72 iotController=params.get("iotController"),
73 lockManagement=params.get("lockManagement"),
74 defaults=params.get("defaults"),
75 network_id=params.get("networkId"),
76 )
77 return new_object
78
79 def run(self, tmp=None, task_vars=None):
80 self._task.diff = False
81 self._result = super(ActionModule, self).run(tmp, task_vars)
82 self._result["changed"] = False
83 self._check_argspec()
84
85 meraki = MERAKI(params=self._task.args)
86
87 response = meraki.exec_meraki(
88 family="wireless",
89 function='updateNetworkWirelessZigbee',
90 op_modifies=True,
91 params=self.get_object(self._task.args),
92 )
93 self._result.update(dict(meraki_response=response))
94 self._result.update(meraki.exit_json())
95 return self._result