ansible  2.9.27
About: Ansible is an IT Configuration Management, Deployment \
About: Ansible (2.x) is an IT Configuration Management, Deployment & Orchestration tool.
ansible download page.
  Fossies Dox: ansible-2.9.27.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

aci_epg_monitoring_policy.py
Go to the documentation of this file.
1#!/usr/bin/python
2# -*- coding: utf-8 -*-
3
4# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6from __future__ import absolute_import, division, print_function
7__metaclass__ = type
8
9ANSIBLE_METADATA = {'metadata_version': '1.1',
10 'status': ['preview'],
11 'supported_by': 'certified'}
12
13DOCUMENTATION = r'''
14---
15module: aci_epg_monitoring_policy
16short_description: Manage monitoring policies (mon:EPGPol)
17description:
18- Manage monitoring policies on Cisco ACI fabrics.
19version_added: '2.4'
20options:
21 monitoring_policy:
22 description:
23 - The name of the monitoring policy.
24 type: str
25 required: yes
26 aliases: [ name ]
27 description:
28 description:
29 - Description for the monitoring policy.
30 type: str
31 aliases: [ descr ]
32 tenant:
33 description:
34 - The name of the tenant.
35 type: str
36 required: yes
37 aliases: [ tenant_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
45extends_documentation_fragment: aci
46notes:
47- The C(tenant) used must exist before using this module in your playbook.
48 The M(aci_tenant) module can be used for this.
49seealso:
50- module: aci_tenant
51- name: APIC Management Information Model reference
52 description: More information about the internal APIC class B(mon:EPGPol).
53 link: https://developer.cisco.com/docs/apic-mim-ref/
54author:
55- Dag Wieers (@dagwieers)
56'''
57
58# FIXME: Add more, better examples
59EXAMPLES = r'''
60- aci_epg_monitoring_policy:
61 host: '{{ hostname }}'
62 username: '{{ username }}'
63 password: '{{ password }}'
64 monitoring_policy: '{{ monitoring_policy }}'
65 description: '{{ description }}'
66 tenant: '{{ tenant }}'
67 delegate_to: localhost
68'''
69
70RETURN = r'''
71current:
72 description: The existing configuration from the APIC after the module has finished
73 returned: success
74 type: list
75 sample:
76 [
77 {
78 "fvTenant": {
79 "attributes": {
80 "descr": "Production environment",
81 "dn": "uni/tn-production",
82 "name": "production",
83 "nameAlias": "",
84 "ownerKey": "",
85 "ownerTag": ""
86 }
87 }
88 }
89 ]
90error:
91 description: The error information as returned from the APIC
92 returned: failure
93 type: dict
94 sample:
95 {
96 "code": "122",
97 "text": "unknown managed object class foo"
98 }
99raw:
100 description: The raw output returned by the APIC REST API (xml or json)
101 returned: parse error
102 type: str
103 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
104sent:
105 description: The actual/minimal configuration pushed to the APIC
106 returned: info
107 type: list
108 sample:
109 {
110 "fvTenant": {
111 "attributes": {
112 "descr": "Production environment"
113 }
114 }
115 }
116previous:
117 description: The original configuration from the APIC before the module has started
118 returned: info
119 type: list
120 sample:
121 [
122 {
123 "fvTenant": {
124 "attributes": {
125 "descr": "Production",
126 "dn": "uni/tn-production",
127 "name": "production",
128 "nameAlias": "",
129 "ownerKey": "",
130 "ownerTag": ""
131 }
132 }
133 }
134 ]
135proposed:
136 description: The assembled configuration from the user-provided parameters
137 returned: info
138 type: dict
139 sample:
140 {
141 "fvTenant": {
142 "attributes": {
143 "descr": "Production environment",
144 "name": "production"
145 }
146 }
147 }
148filter_string:
149 description: The filter string used for the request
150 returned: failure or debug
151 type: str
152 sample: ?rsp-prop-include=config-only
153method:
154 description: The HTTP method used for the request to the APIC
155 returned: failure or debug
156 type: str
157 sample: POST
158response:
159 description: The HTTP response from the APIC
160 returned: failure or debug
161 type: str
162 sample: OK (30 bytes)
163status:
164 description: The HTTP status from the APIC
165 returned: failure or debug
166 type: int
167 sample: 200
168url:
169 description: The HTTP url used for the request to the APIC
170 returned: failure or debug
171 type: str
172 sample: https://10.11.12.13/api/mo/uni/tn-production.json
173'''
174
175from ansible.module_utils.basic import AnsibleModule
176from ansible.module_utils.network.aci.aci import ACIModule, aci_argument_spec
177
178
179def main():
180 argument_spec = aci_argument_spec()
181 argument_spec.update(
182 monitoring_policy=dict(type='str', aliases=['name']), # Not required for querying all objects
183 tenant=dict(type='str', aliases=['tenant_name']), # Not required for querying all objects
184 description=dict(type='str', aliases=['descr']),
185 state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
186 )
187
188 module = AnsibleModule(
189 argument_spec=argument_spec,
190 supports_check_mode=True,
191 required_if=[
192 ['state', 'absent', ['monitoring_policy', 'tenant']],
193 ['state', 'present', ['monitoring_policy', 'tenant']],
194 ],
195 )
196
197 monitoring_policy = module.params['monitoring_policy']
198 description = module.params['description']
199 state = module.params['state']
200 tenant = module.params['tenant']
201
202 aci = ACIModule(module)
203 aci.construct_url(
204 root_class=dict(
205 aci_class='fvTenant',
206 aci_rn='tn-{0}'.format(tenant),
207 module_object=tenant,
208 target_filter={'name': tenant},
209 ),
210 subclass_1=dict(
211 aci_class='monEPGPol',
212 aci_rn='monepg-{0}'.format(monitoring_policy),
213 module_object=monitoring_policy,
214 target_filter={'name': monitoring_policy},
215 ),
216 )
217
218 aci.get_existing()
219
220 if state == 'present':
221 aci.payload(
222 aci_class='monEPGPol',
223 class_config=dict(
224 name=monitoring_policy,
225 descr=description,
226 ),
227 )
228
229 aci.get_diff(aci_class='monEPGPol')
230
231 aci.post_config()
232
233 elif state == 'absent':
234 aci.delete_config()
235
236 aci.exit_json()
237
238
239if __name__ == "__main__":
240 main()