Debian Codegraph @

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