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_fabric_scheduler.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 = '''
16---
17module: aci_fabric_scheduler
18
19short_description: This modules creates ACI schedulers.
20
21version_added: "2.8"
22
23description:
24 - With the module you can create schedule policies that can be a shell, onetime execution or recurring
25
26options:
27 name:
28 description:
29 - The name of the Scheduler.
30 required: yes
31 aliases: [ name, scheduler_name ]
32 description:
33 description:
34 - Description for the Scheduler.
35 aliases: [ descr ]
36 recurring:
37 description:
38 - If you want to make the Scheduler a recurring it would be a "True" and for a
39 oneTime execution it would be "False". For a shell just exclude this option from
40 the task
41 type: bool
42 default: 'no'
43 windowname:
44 description:
45 - This is the name for your what recurring or oneTime execution
46 concurCap:
47 description:
48 - This is the amount of devices that can be executed on at a time
49 type: int
50 maxTime:
51 description:
52 - This is the amount MAX amount of time a process can be executed
53 date:
54 description:
55 - This is the date and time that the scheduler will execute
56 hour:
57 description:
58 - This set the hour of execution
59 minute:
60 description:
61 - This sets the minute of execution, used in conjunction with hour
62 day:
63 description:
64 - This sets the day when execution will take place
65 default: "every-day"
66 choices: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday','Sunday', 'even-day', 'odd-day', 'every-day']
67 state:
68 description:
69 - Use C(present) or C(absent) for adding or removing.
70 - Use C(query) for listing an object or multiple objects.
71 default: present
72 choices: [ absent, present, query ]
73
74extends_documentation_fragment: aci
75
76author:
77 - Steven Gerhart (@sgerhart)
78'''
79
80EXAMPLES = '''
81 - name: Simple Scheduler (Empty)
82 aci_fabric_scheduler:
83 host: "{{ inventory_hostname }}"
84 username: "{{ user }}"
85 password: "{{ pass }}"
86 validate_certs: no
87 name: simpleScheduler
88 state: present
89 - name: Remove Simple Scheduler
90 aci_fabric_scheduler:
91 host: "{{ inventory_hostname }}"
92 username: "{{ user }}"
93 password: "{{ pass }}"
94 validate_certs: no
95 name: simpleScheduler
96 state: absent
97 - name: One Time Scheduler
98 aci_fabric_scheduler:
99 host: "{{ inventory_hostname }}"
100 username: "{{ user }}"
101 password: "{{ pass }}"
102 validate_certs: no
103 name: OneTime
104 windowname: OneTime
105 recurring: False
106 concurCap: 20
107 date: "2018-11-20T24:00:00"
108 state: present
109 - name: Recurring Scheduler
110 aci_fabric_scheduler:
111 host: "{{ inventory_hostname }}"
112 username: "{{ user }}"
113 password: "{{ pass }}"
114 validate_certs: no
115 name: Recurring
116 windowname: Recurring
117 recurring: True
118 concurCap: 20
119 hour: 13
120 minute: 30
121 day: Tuesday
122 state: present
123'''
124
125RETURN = '''
126current:
127 description: The existing configuration from the APIC after the module has finished
128 returned: success
129 type: list
130 sample:
131 [
132 {
133 "fvTenant": {
134 "attributes": {
135 "descr": "Production environment",
136 "dn": "uni/tn-production",
137 "name": "production",
138 "nameAlias": "",
139 "ownerKey": "",
140 "ownerTag": ""
141 }
142 }
143 }
144 ]
145error:
146 description: The error information as returned from the APIC
147 returned: failure
148 type: dict
149 sample:
150 {
151 "code": "122",
152 "text": "unknown managed object class foo"
153 }
154raw:
155 description: The raw output returned by the APIC REST API (xml or json)
156 returned: parse error
157 type: str
158 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
159sent:
160 description: The actual/minimal configuration pushed to the APIC
161 returned: info
162 type: list
163 sample:
164 {
165 "fvTenant": {
166 "attributes": {
167 "descr": "Production environment"
168 }
169 }
170 }
171previous:
172 description: The original configuration from the APIC before the module has started
173 returned: info
174 type: list
175 sample:
176 [
177 {
178 "fvTenant": {
179 "attributes": {
180 "descr": "Production",
181 "dn": "uni/tn-production",
182 "name": "production",
183 "nameAlias": "",
184 "ownerKey": "",
185 "ownerTag": ""
186 }
187 }
188 }
189 ]
190proposed:
191 description: The assembled configuration from the user-provided parameters
192 returned: info
193 type: dict
194 sample:
195 {
196 "fvTenant": {
197 "attributes": {
198 "descr": "Production environment",
199 "name": "production"
200 }
201 }
202 }
203filter_string:
204 description: The filter string used for the request
205 returned: failure or debug
206 type: str
207 sample: ?rsp-prop-include=config-only
208method:
209 description: The HTTP method used for the request to the APIC
210 returned: failure or debug
211 type: str
212 sample: POST
213response:
214 description: The HTTP response from the APIC
215 returned: failure or debug
216 type: str
217 sample: OK (30 bytes)
218status:
219 description: The HTTP status from the APIC
220 returned: failure or debug
221 type: int
222 sample: 200
223url:
224 description: The HTTP url used for the request to the APIC
225 returned: failure or debug
226 type: str
227 sample: https://10.11.12.13/api/mo/uni/tn-production.json
228'''
229
230import json
231from ansible.module_utils.network.aci.aci import ACIModule, aci_argument_spec
232from ansible.module_utils.basic import AnsibleModule
233
234
235def main():
236 argument_spec = aci_argument_spec()
237 argument_spec.update(
238 name=dict(type='str', aliases=['name', 'scheduler_name']), # Not required for querying all objects
239 description=dict(type='str', aliases=['descr']),
240 windowname=dict(type='str', aliases=['windowname']),
241 recurring=dict(type='bool'),
242 concurCap=dict(type='int'), # Number of devices it will run against concurrently
243 maxTime=dict(type='str'), # The amount of minutes a process will be able to run (unlimited or dd:hh:mm:ss)
244 date=dict(type='str', aliases=['date']), # The date the process will run YYYY-MM-DDTHH:MM:SS
245 state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
246 hour=dict(type='int'),
247 minute=dict(type='int'),
248 day=dict(type='str', default='every-day', choices=['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday',
249 'Saturday', 'Sunday', 'every-day', 'even-day', 'odd-day']),
250 )
251
252 module = AnsibleModule(
253 argument_spec=argument_spec,
254 supports_check_mode=True,
255 required_if=[
256 ['state', 'absent', ['name']],
257 ['state', 'present', ['name']],
258 ],
259 )
260
261 state = module.params['state']
262 name = module.params['name']
263 windowname = module.params['windowname']
264 recurring = module.params['recurring']
265 date = module.params['date']
266 hour = module.params['hour']
267 minute = module.params['minute']
268 maxTime = module.params['maxTime']
269 concurCap = module.params['concurCap']
270 day = module.params['day']
271 description = module.params['description']
272
273 if recurring:
274 child_configs = [dict(trigRecurrWindowP=dict(attributes=dict(name=windowname, hour=hour, minute=minute,
275 procCa=maxTime, concurCap=concurCap, day=day,)))]
276 elif recurring is False:
277 child_configs = [dict(trigAbsWindowP=dict(attributes=dict(name=windowname, procCap=maxTime,
278 concurCap=concurCap, date=date,)))]
279 else:
280 child_configs = []
281
282 aci = ACIModule(module)
283 aci.construct_url(
284 root_class=dict(
285 aci_class='trigSchedP',
286 aci_rn='fabric/schedp-{0}'.format(name),
287 target_filter={'name': name},
288 module_object=name,
289 ),
290
291 )
292
293 aci.get_existing()
294
295 if state == 'present':
296 aci.payload(
297 aci_class='trigSchedP',
298 class_config=dict(
299 name=name,
300 descr=description,
301 ),
302 child_configs=child_configs,
303
304 )
305
306 aci.get_diff(aci_class='trigSchedP')
307
308 aci.post_config()
309
310 elif state == 'absent':
311 aci.delete_config()
312
313 aci.exit_json()
314
315
316if __name__ == "__main__":
317 main()