Debian Codegraph @

ansible_collections/cisco/aci/plugins/modules/aci_snmp_client_group.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 from __future__ import absolute_import, division, print_function
7
8 __metaclass__ = type
9
10 ANSIBLE_METADATA = {"metadata_version": "1.1", "status": ["preview"], "supported_by": "certified"}
11
12 DOCUMENTATION = r"""
13 ---
14 module: aci_snmp_client_group
15 short_description: Manage SNMP client groups (snmp:ClientGrpP)
16 description:
17 - Manage SNMP client groups
18 options:
19 client_group:
20 description:
21 - Name of the SNMP client group
22 type: str
23 aliases: [ client_group_name, client_group_profile ]
24 description:
25 description:
26 - Description of the SNMP policy
27 type: str
28 mgmt_epg:
29 description:
30 - Associated management EPG
31 type: str
32 aliases: [ management_epg_name, management_epg ]
33 policy:
34 description:
35 - Name of an existing SNMP policy
36 type: str
37 aliases: [ snmp_policy, snmp_policy_name ]
38 state:
39 description:
40 - Use C(present) or C(absent) for adding or removing.
41 - Use C(query) for listing an object or multiple objects.
42 type: str
43 choices: [ absent, present, query ]
44 default: present
45 extends_documentation_fragment:
46 - cisco.aci.aci
47 - cisco.aci.annotation
48
49 seealso:
50 - name: APIC Management Information Model reference
51 description: More information about the internal APIC classes B(snmp:ClientGrpP).
52 link: https://developer.cisco.com/docs/apic-mim-ref/
53 author:
54 - Tim Cragg (@timcragg)
55 """
56
57 EXAMPLES = r"""
58 - name: Create an SNMP client group
59 cisco.aci.aci_snmp_client_group:
60 host: apic
61 username: admin
62 password: SomeSecretPassword
63 policy: my_snmp_policy
64 client_group: my_snmp_client_group
65 mgmt_epg: oob-default
66 state: present
67 delegate_to: localhost
68
69 - name: Remove an SNMP client group
70 cisco.aci.aci_snmp_client_group:
71 host: apic
72 username: admin
73 password: SomeSecretPassword
74 policy: my_snmp_policy
75 client_group: my_snmp_client_group
76 state: absent
77 delegate_to: localhost
78
79 - name: Query an SNMP client group
80 cisco.aci.aci_snmp_client_group:
81 host: apic
82 username: admin
83 password: SomeSecretPassword
84 policy: my_snmp_policy
85 client_group: my_snmp_client_group
86 state: query
87 delegate_to: localhost
88 register: query_result
89
90 - name: Query all SNMP client group
91 cisco.aci.aci_snmp_community_policy:
92 host: apic
93 username: admin
94 password: SomeSecretPassword
95 state: query
96 delegate_to: localhost
97 register: query_result
98 """
99
100 RETURN = r"""
101 current:
102 description: The existing configuration from the APIC after the module has finished
103 returned: success
104 type: list
105 sample:
106 [
107 {
108 "fvTenant": {
109 "attributes": {
110 "descr": "Production environment",
111 "dn": "uni/tn-production",
112 "name": "production",
113 "nameAlias": "",
114 "ownerKey": "",
115 "ownerTag": ""
116 }
117 }
118 }
119 ]
120 error:
121 description: The error information as returned from the APIC
122 returned: failure
123 type: dict
124 sample:
125 {
126 "code": "122",
127 "text": "unknown managed object class foo"
128 }
129 raw:
130 description: The raw output returned by the APIC REST API (xml or json)
131 returned: parse error
132 type: str
133 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
134 sent:
135 description: The actual/minimal configuration pushed to the APIC
136 returned: info
137 type: list
138 sample:
139 {
140 "fvTenant": {
141 "attributes": {
142 "descr": "Production environment"
143 }
144 }
145 }
146 previous:
147 description: The original configuration from the APIC before the module has started
148 returned: info
149 type: list
150 sample:
151 [
152 {
153 "fvTenant": {
154 "attributes": {
155 "descr": "Production",
156 "dn": "uni/tn-production",
157 "name": "production",
158 "nameAlias": "",
159 "ownerKey": "",
160 "ownerTag": ""
161 }
162 }
163 }
164 ]
165 proposed:
166 description: The assembled configuration from the user-provided parameters
167 returned: info
168 type: dict
169 sample:
170 {
171 "fvTenant": {
172 "attributes": {
173 "descr": "Production environment",
174 "name": "production"
175 }
176 }
177 }
178 filter_string:
179 description: The filter string used for the request
180 returned: failure or debug
181 type: str
182 sample: ?rsp-prop-include=config-only
183 method:
184 description: The HTTP method used for the request to the APIC
185 returned: failure or debug
186 type: str
187 sample: POST
188 response:
189 description: The HTTP response from the APIC
190 returned: failure or debug
191 type: str
192 sample: OK (30 bytes)
193 status:
194 description: The HTTP status from the APIC
195 returned: failure or debug
196 type: int
197 sample: 200
198 url:
199 description: The HTTP url used for the request to the APIC
200 returned: failure or debug
201 type: str
202 sample: https://10.11.12.13/api/mo/uni/tn-production.json
203 """
204
205
206 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec
207 from ansible.module_utils.basic import AnsibleModule
208
209
210 def main():
211 argument_spec = aci_argument_spec()
212 argument_spec.update(aci_annotation_spec())
213 argument_spec.update(
214 client_group=dict(type="str", aliases=["client_group_name", "client_group_profile"]),
215 mgmt_epg=dict(type="str", aliases=["management_epg_name", "management_epg"]),
216 policy=dict(type="str", aliases=["snmp_policy", "snmp_policy_name"]),
217 description=dict(type="str"),
218 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
219 )
220
221 module = AnsibleModule(
222 argument_spec=argument_spec,
223 supports_check_mode=True,
224 required_if=[
225 ["state", "absent", ["policy", "client_group"]],
226 ["state", "present", ["policy", "client_group"]],
227 ],
228 )
229
230 aci = ACIModule(module)
231
232 client_group = module.params.get("client_group")
233 policy = module.params.get("policy")
234 mgmt_epg = module.params.get("mgmt_epg")
235 description = module.params.get("description")
236 state = module.params.get("state")
237
238 aci.construct_url(
239 root_class=dict(
240 aci_class="snmpPol",
241 aci_rn="fabric/snmppol-{0}".format(policy),
242 module_object=policy,
243 target_filter={"name": policy},
244 ),
245 subclass_1=dict(
246 aci_class="snmpClientGrpP",
247 aci_rn="clgrp-{0}".format(client_group),
248 module_object=client_group,
249 target_filter={"name": client_group},
250 ),
251 child_classes=["snmpRsEpg"],
252 )
253
254 aci.get_existing()
255
256 if state == "present":
257 if mgmt_epg:
258 tdn = "uni/tn-mgmt/mgmtp-default/{0}".format(mgmt_epg)
259 else:
260 tdn = None
261 aci.payload(
262 aci_class="snmpClientGrpP",
263 class_config=dict(name=client_group, descr=description),
264 child_configs=[
265 dict(
266 snmpRsEpg=dict(
267 attributes=dict(tDn=tdn),
268 ),
269 ),
270 ],
271 )
272
273 aci.get_diff(aci_class="snmpClientGrpP")
274
275 aci.post_config()
276
277 elif state == "absent":
278 aci.delete_config()
279
280 aci.exit_json()
281
282
283 if __name__ == "__main__":
284 main()