Debian Codegraph @

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

raw symbols SCIP
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 perPage=dict(type="int"),
30 total_pages=dict(type="int"),
31 direction=dict(type="str"),
32 startingAfter=dict(type="str"),
33 endingBefore=dict(type="str"),
34 configurationUpdatedAfter=dict(type="str"),
35 networkIds=dict(type="list"),
36 productTypes=dict(type="list"),
37 tags=dict(type="list"),
38 tagsFilterType=dict(type="str"),
39 name=dict(type="str"),
40 mac=dict(type="str"),
41 serial=dict(type="str"),
42 model=dict(type="str"),
43 macs=dict(type="list"),
44 serials=dict(type="list"),
45 sensorMetrics=dict(type="list"),
46 sensorAlertProfileIds=dict(type="list"),
47 models=dict(type="list"),
48 ))
49
50 required_if = []
51 required_one_of = []
52 mutually_exclusive = []
53 required_together = []
54
55
56 class ActionModule(ActionBase):
57 def __init__(self, *args, **kwargs):
58 if not ANSIBLE_UTILS_IS_INSTALLED:
59 raise AnsibleActionFail(
60 "ansible.utils is not installed. Execute 'ansible-galaxy collection install ansible.utils'")
61 super(ActionModule, self).__init__(*args, **kwargs)
62 self._supports_async = False
63 self._supports_check_mode = True
64 self._result = None
65
66 # Checks the supplied parameters against the argument spec for this module
67 def _check_argspec(self):
68 aav = AnsibleArgSpecValidator(
69 data=self._task.args,
70 schema=dict(argument_spec=argument_spec),
71 schema_format="argspec",
72 schema_conditionals=dict(
73 required_if=required_if,
74 required_one_of=required_one_of,
75 mutually_exclusive=mutually_exclusive,
76 required_together=required_together,
77 ),
78 name=self._task.action,
79 )
80 valid, errors, self._task.args = aav.validate()
81 if not valid:
82 raise AnsibleActionFail(errors)
83
84 def get_all(self, params):
85 new_object = {}
86 if params.get("organizationId") is not None:
87 new_object["organizationId"] = params.get(
88 "organizationId")
89 if params.get("perPage") is not None:
90 new_object["perPage"] = params.get(
91 "perPage")
92 new_object['total_pages'] = params.get(
93 "total_pages") or 1
94 new_object['direction'] = params.get(
95 "direction") or "next"
96 if params.get("startingAfter") is not None:
97 new_object["startingAfter"] = params.get(
98 "startingAfter")
99 if params.get("endingBefore") is not None:
100 new_object["endingBefore"] = params.get(
101 "endingBefore")
102 if params.get("configurationUpdatedAfter") is not None:
103 new_object["configurationUpdatedAfter"] = params.get(
104 "configurationUpdatedAfter")
105 if params.get("networkIds") is not None:
106 new_object["networkIds"] = params.get(
107 "networkIds")
108 if params.get("productTypes") is not None:
109 new_object["productTypes"] = params.get(
110 "productTypes")
111 if params.get("tags") is not None:
112 new_object["tags"] = params.get(
113 "tags")
114 if params.get("tagsFilterType") is not None:
115 new_object["tagsFilterType"] = params.get(
116 "tagsFilterType")
117 if params.get("name") is not None:
118 new_object["name"] = params.get(
119 "name")
120 if params.get("mac") is not None:
121 new_object["mac"] = params.get(
122 "mac")
123 if params.get("serial") is not None:
124 new_object["serial"] = params.get(
125 "serial")
126 if params.get("model") is not None:
127 new_object["model"] = params.get(
128 "model")
129 if params.get("macs") is not None:
130 new_object["macs"] = params.get(
131 "macs")
132 if params.get("serials") is not None:
133 new_object["serials"] = params.get(
134 "serials")
135 if params.get("sensorMetrics") is not None:
136 new_object["sensorMetrics"] = params.get(
137 "sensorMetrics")
138 if params.get("sensorAlertProfileIds") is not None:
139 new_object["sensorAlertProfileIds"] = params.get(
140 "sensorAlertProfileIds")
141 if params.get("models") is not None:
142 new_object["models"] = params.get(
143 "models")
144
145 return new_object
146
147 def run(self, tmp=None, task_vars=None):
148 self._task.diff = False
149 self._result = super(ActionModule, self).run(tmp, task_vars)
150 self._result["changed"] = False
151 self._check_argspec()
152
153 self._result.update(dict(meraki_response={}))
154
155 meraki = MERAKI(params=self._task.args)
156
157 response = meraki.exec_meraki(
158 family="organizations",
159 function='getOrganizationDevices',
160 params=self.get_all(self._task.args),
161 )
162 self._result.update(dict(meraki_response=response))
163 self._result.update(meraki.exit_json())
164 return self._result