Debian Codegraph @

ansible_collections/cisco/meraki/plugins/action/networks_clients_provision.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 clients=dict(type="list"),
29 devicePolicy=dict(type="str"),
30 groupPolicyId=dict(type="str"),
31 policiesBySecurityAppliance=dict(type="dict"),
32 policiesBySsid=dict(type="dict"),
33 networkId=dict(type="str"),
34 ))
35
36 required_if = []
37 required_one_of = []
38 mutually_exclusive = []
39 required_together = []
40
41
42 class ActionModule(ActionBase):
43 def __init__(self, *args, **kwargs):
44 if not ANSIBLE_UTILS_IS_INSTALLED:
45 raise AnsibleActionFail(
46 "ansible.utils is not installed. Execute 'ansible-galaxy collection install ansible.utils'")
47 super(ActionModule, self).__init__(*args, **kwargs)
48 self._supports_async = False
49 self._supports_check_mode = False
50 self._result = None
51
52 # Checks the supplied parameters against the argument spec for this module
53 def _check_argspec(self):
54 aav = AnsibleArgSpecValidator(
55 data=self._task.args,
56 schema=dict(argument_spec=argument_spec),
57 schema_format="argspec",
58 schema_conditionals=dict(
59 required_if=required_if,
60 required_one_of=required_one_of,
61 mutually_exclusive=mutually_exclusive,
62 required_together=required_together,
63 ),
64 name=self._task.action,
65 )
66 valid, errors, self._task.args = aav.validate()
67 if not valid:
68 raise AnsibleActionFail(errors)
69
70 def get_object(self, params):
71 new_object = dict(
72 clients=params.get("clients"),
73 devicePolicy=params.get("devicePolicy"),
74 groupPolicyId=params.get("groupPolicyId"),
75 policiesBySecurityAppliance=params.get("policiesBySecurityAppliance"),
76 policiesBySsid=params.get("policiesBySsid"),
77 networkId=params.get("networkId"),
78 )
79 return new_object
80
81 def run(self, tmp=None, task_vars=None):
82 self._task.diff = False
83 self._result = super(ActionModule, self).run(tmp, task_vars)
84 self._result["changed"] = False
85 self._check_argspec()
86
87 meraki = MERAKI(params=self._task.args)
88
89 response = meraki.exec_meraki(
90 family="networks",
91 function='provisionNetworkClients',
92 op_modifies=True,
93 params=self.get_object(self._task.args),
94 )
95 self._result.update(dict(meraki_response=response))
96 self._result.update(meraki.exit_json())
97 return self._result