Debian Codegraph @

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