Debian Codegraph @

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