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_maintenance_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 = {
10 'metadata_version': '1.1',
11 'status': ['preview'],
12 'supported_by': 'community'
13}
14
15DOCUMENTATION = r'''
16---
17module: aci_maintenance_policy
18short_description: Manage firmware maintenance policies
19version_added: '2.8'
20description:
21- Manage maintenance policies that defines behavior during an ACI upgrade.
22options:
23 name:
24 description:
25 - The name for the maintenance policy.
26 required: true
27 aliases: [ maintenance_policy ]
28 runmode:
29 description:
30 - Whether the system pauses on error or just continues through it.
31 choices: ['pauseOnlyOnFailures', 'pauseNever']
32 default: pauseOnlyOnFailures
33 graceful:
34 description:
35 - Whether the system will bring down the nodes gracefully during an upgrade, which reduces traffic lost.
36 - The APIC defaults to C(no) when unset during creation.
37 type: bool
38 scheduler:
39 description:
40 - The name of scheduler that is applied to the policy.
41 type: str
42 required: true
43 adminst:
44 description:
45 - Will trigger an immediate upgrade for nodes if adminst is set to triggered.
46 choices: [ triggered, untriggered ]
47 default: untriggered
48 ignoreCompat:
49 description:
50 - To check whether compatibility checks should be ignored
51 - The APIC defaults to C(no) when unset during creation.
52 type: bool
53 state:
54 description:
55 - Use C(present) or C(absent) for adding or removing.
56 - Use C(query) for listing an object or multiple objects.
57 choices: [ absent, present, query ]
58 default: present
59extends_documentation_fragment:
60- aci
61notes:
62- A scheduler is required for this module, which could have been created using the M(aci_fabric_scheduler) module or via the UI.
63author:
64- Steven Gerhart (@sgerhart)
65'''
66
67EXAMPLES = r'''
68- name: Ensure maintenance policy is present
69 aci_maintenance_policy:
70 host: '{{ inventory_hostname }}'
71 username: '{{ user }}'
72 password: '{{ pass }}'
73 validate_certs: no
74 name: maintenancePol1
75 scheduler: simpleScheduler
76 runmode: False
77 state: present
78'''
79
80RETURN = r'''
81current:
82 description: The existing configuration from the APIC after the module has finished
83 returned: success
84 type: list
85 sample:
86 [
87 {
88 "fvTenant": {
89 "attributes": {
90 "descr": "Production environment",
91 "dn": "uni/tn-production",
92 "name": "production",
93 "nameAlias": "",
94 "ownerKey": "",
95 "ownerTag": ""
96 }
97 }
98 }
99 ]
100error:
101 description: The error information as returned from the APIC
102 returned: failure
103 type: dict
104 sample:
105 {
106 "code": "122",
107 "text": "unknown managed object class foo"
108 }
109raw:
110 description: The raw output returned by the APIC REST API (xml or json)
111 returned: parse error
112 type: str
113 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
114sent:
115 description: The actual/minimal configuration pushed to the APIC
116 returned: info
117 type: list
118 sample:
119 {
120 "fvTenant": {
121 "attributes": {
122 "descr": "Production environment"
123 }
124 }
125 }
126previous:
127 description: The original configuration from the APIC before the module has started
128 returned: info
129 type: list
130 sample:
131 [
132 {
133 "fvTenant": {
134 "attributes": {
135 "descr": "Production",
136 "dn": "uni/tn-production",
137 "name": "production",
138 "nameAlias": "",
139 "ownerKey": "",
140 "ownerTag": ""
141 }
142 }
143 }
144 ]
145proposed:
146 description: The assembled configuration from the user-provided parameters
147 returned: info
148 type: dict
149 sample:
150 {
151 "fvTenant": {
152 "attributes": {
153 "descr": "Production environment",
154 "name": "production"
155 }
156 }
157 }
158filter_string:
159 description: The filter string used for the request
160 returned: failure or debug
161 type: str
162 sample: ?rsp-prop-include=config-only
163method:
164 description: The HTTP method used for the request to the APIC
165 returned: failure or debug
166 type: str
167 sample: POST
168response:
169 description: The HTTP response from the APIC
170 returned: failure or debug
171 type: str
172 sample: OK (30 bytes)
173status:
174 description: The HTTP status from the APIC
175 returned: failure or debug
176 type: int
177 sample: 200
178url:
179 description: The HTTP url used for the request to the APIC
180 returned: failure or debug
181 type: str
182 sample: https://10.11.12.13/api/mo/uni/tn-production.json
183'''
184
185
186from ansible.module_utils.network.aci.aci import ACIModule, aci_argument_spec
187from ansible.module_utils.basic import AnsibleModule
188
189
190def main():
191 argument_spec = aci_argument_spec()
192 argument_spec.update(
193 name=dict(type='str', aliases=['maintenance_policy']), # Not required for querying all objects
194 runmode=dict(type='str', default='pauseOnlyOnFailures', choices=['pauseOnlyOnFailures', 'pauseNever']),
195 graceful=dict(type='bool'),
196 scheduler=dict(type='str'),
197 ignoreCompat=dict(type='bool'),
198 adminst=dict(type='str', default='untriggered', choices=['triggered', 'untriggered']),
199 state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
200 )
201
202 module = AnsibleModule(
203 argument_spec=argument_spec,
204 supports_check_mode=True,
205 required_if=[
206 ['state', 'absent', ['name']],
207 ['state', 'present', ['name', 'scheduler']],
208 ],
209 )
210
211 aci = ACIModule(module)
212
213 state = module.params['state']
214 name = module.params['name']
215 runmode = module.params['runmode']
216 scheduler = module.params['scheduler']
217 adminst = module.params['adminst']
218 graceful = aci.boolean(module.params['graceful'])
219 ignoreCompat = aci.boolean(module.params['ignoreCompat'])
220
221 aci.construct_url(
222 root_class=dict(
223 aci_class='maintMaintP',
224 aci_rn='fabric/maintpol-{0}'.format(name),
225 target_filter={'name': name},
226 module_object=name,
227 ),
228 child_classes=['maintRsPolScheduler']
229
230 )
231
232 aci.get_existing()
233
234 if state == 'present':
235 aci.payload(
236 aci_class='maintMaintP',
237 class_config=dict(
238 name=name,
239 runMode=runmode,
240 graceful=graceful,
241 adminSt=adminst,
242 ignoreCompat=ignoreCompat,
243 ),
244 child_configs=[
245 dict(
246 maintRsPolScheduler=dict(
247 attributes=dict(
248 tnTrigSchedPName=scheduler,
249 ),
250 ),
251 ),
252 ],
253
254 )
255
256 aci.get_diff(aci_class='maintMaintP')
257
258 aci.post_config()
259
260 elif state == 'absent':
261 aci.delete_config()
262
263 aci.exit_json()
264
265
266if __name__ == "__main__":
267 main()