Debian Codegraph @

ansible_collections/cisco/meraki/plugins/action/networks_wireless_latency_stats_info.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 arguments specification
25 argument_spec = meraki_argument_spec()
26 # Add arguments specific for this module
27 argument_spec.update(dict(
28 networkId=dict(type="str"),
29 t0=dict(type="str"),
30 t1=dict(type="str"),
31 timespan=dict(type="float"),
32 band=dict(type="str"),
33 ssid=dict(type="int"),
34 apTag=dict(type="str"),
35 vlan=dict(type="int"),
36 fields=dict(type="str"),
37 ))
38
39 required_if = []
40 required_one_of = []
41 mutually_exclusive = []
42 required_together = []
43
44
45 class ActionModule(ActionBase):
46 def __init__(self, *args, **kwargs):
47 if not ANSIBLE_UTILS_IS_INSTALLED:
48 raise AnsibleActionFail(
49 "ansible.utils is not installed. Execute 'ansible-galaxy collection install ansible.utils'")
50 super(ActionModule, self).__init__(*args, **kwargs)
51 self._supports_async = False
52 self._supports_check_mode = True
53 self._result = None
54
55 # Checks the supplied parameters against the argument spec for this module
56 def _check_argspec(self):
57 aav = AnsibleArgSpecValidator(
58 data=self._task.args,
59 schema=dict(argument_spec=argument_spec),
60 schema_format="argspec",
61 schema_conditionals=dict(
62 required_if=required_if,
63 required_one_of=required_one_of,
64 mutually_exclusive=mutually_exclusive,
65 required_together=required_together,
66 ),
67 name=self._task.action,
68 )
69 valid, errors, self._task.args = aav.validate()
70 if not valid:
71 raise AnsibleActionFail(errors)
72
73 def get_all(self, params):
74 new_object = {}
75 if params.get("networkId") is not None:
76 new_object["networkId"] = params.get(
77 "networkId")
78 if params.get("t0") is not None:
79 new_object["t0"] = params.get(
80 "t0")
81 if params.get("t1") is not None:
82 new_object["t1"] = params.get(
83 "t1")
84 if params.get("timespan") is not None:
85 new_object["timespan"] = params.get(
86 "timespan")
87 if params.get("band") is not None:
88 new_object["band"] = params.get(
89 "band")
90 if params.get("ssid") is not None:
91 new_object["ssid"] = params.get(
92 "ssid")
93 if params.get("apTag") is not None:
94 new_object["apTag"] = params.get(
95 "apTag")
96 if params.get("vlan") is not None:
97 new_object["vlan"] = params.get(
98 "vlan")
99 if params.get("fields") is not None:
100 new_object["fields"] = params.get(
101 "fields")
102
103 return new_object
104
105 def run(self, tmp=None, task_vars=None):
106 self._task.diff = False
107 self._result = super(ActionModule, self).run(tmp, task_vars)
108 self._result["changed"] = False
109 self._check_argspec()
110
111 self._result.update(dict(meraki_response={}))
112
113 meraki = MERAKI(params=self._task.args)
114
115 response = meraki.exec_meraki(
116 family="wireless",
117 function='getNetworkWirelessLatencyStats',
118 params=self.get_all(self._task.args),
119 )
120 self._result.update(dict(meraki_response=response))
121 self._result.update(meraki.exit_json())
122 return self._result