Debian Codegraph @

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