Debian Codegraph @

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