Debian Codegraph @

ansible_collections/cisco/meraki/plugins/action/devices_live_tools_ping_device_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 serial=dict(type="str"),
29 id=dict(type="str"),
30 ))
31
32 required_if = []
33 required_one_of = []
34 mutually_exclusive = []
35 required_together = []
36
37
38 class ActionModule(ActionBase):
39 def __init__(self, *args, **kwargs):
40 if not ANSIBLE_UTILS_IS_INSTALLED:
41 raise AnsibleActionFail(
42 "ansible.utils is not installed. Execute 'ansible-galaxy collection install ansible.utils'")
43 super(ActionModule, self).__init__(*args, **kwargs)
44 self._supports_async = False
45 self._supports_check_mode = True
46 self._result = None
47
48 # Checks the supplied parameters against the argument spec for this module
49 def _check_argspec(self):
50 aav = AnsibleArgSpecValidator(
51 data=self._task.args,
52 schema=dict(argument_spec=argument_spec),
53 schema_format="argspec",
54 schema_conditionals=dict(
55 required_if=required_if,
56 required_one_of=required_one_of,
57 mutually_exclusive=mutually_exclusive,
58 required_together=required_together,
59 ),
60 name=self._task.action,
61 )
62 valid, errors, self._task.args = aav.validate()
63 if not valid:
64 raise AnsibleActionFail(errors)
65
66 def get_object(self, params):
67 new_object = {}
68 if params.get("serial") is not None:
69 new_object["serial"] = params.get(
70 "serial")
71 if params.get("id") is not None:
72 new_object["id"] = params.get(
73 "id")
74 return new_object
75
76 def run(self, tmp=None, task_vars=None):
77 self._task.diff = False
78 self._result = super(ActionModule, self).run(tmp, task_vars)
79 self._result["changed"] = False
80 self._check_argspec()
81
82 self._result.update(dict(meraki_response={}))
83
84 meraki = MERAKI(params=self._task.args)
85
86 id = self._task.args.get("id")
87 if id:
88 response = meraki.exec_meraki(
89 family="devices",
90 function='getDeviceLiveToolsPingDevice',
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
96 if not id:
97 # NOTE: Does not have a get all method or it is in another action
98 response = None
99 meraki.object_modify_result(
100 changed=False,
101 result="Module does not have get all, check arguments of module")
102 self._result.update(dict(meraki_response=response))
103 self._result.update(meraki.exit_json())
104 return self._result