Debian Codegraph @

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