Automated Scheduling Feature (API)
ClearGLASS allows you to store and run scheduled tasks (cronjobs) that can run your scripts and schedule actions on your servers.
There are three types of tasks: interval (running periodically), crontab (with a format that resembles the unix crontab file) and one_off (runs only once).
A scheduled task can also have an activation time, an expiration time and can be disabled and kept for future use. ClearGLASS provides a REST API for task management. All scheduled task results can be accessed through the ClearGLASS logs.
Adding a task
Adding a task requires a POST call to /api/v1/schedules. For example, the following task will try to start the machine every 2 minutes:
user@user:/tmp$ curl -H "Authorization: 51fb1fc5554d0861d80843dd2612234365feb8211e9d191a70fde56a340bf742" -X POST -d '{'name':'test','action':'start', 'machines_per_cloud':[["b48a696e84554275a52fbe6278f6df56","i-781daaf3"]],'enabled':true,'expires':'2016-11-10 20:20:00','cronjob_type':'interval','cronjob_entry':JSON.stringify({"every" : 2,"period" : "minutes"})}' https://ClearGLASS/api/v1/schedules
while this example, will run a script every 2 hours:
user@user:/tmp$ curl -H "Authorization: 51fb1fc5554d0861d80843dd2612234365feb8211e9d191a70fde56a340bf742" -X POST -d '{'name':'test','script_id':'875cabc81fa1438b98ef25f099bbdf09', 'machines_per_cloud':[["b48a696e84554275a52fbe6278f6df56","i-781daaf3"]],'enabled':true,'expires':'2016-11-10 20:20:00','cronjob_type':'interval','cronjob_entry':JSON.stringify({"every" : 2,"period" : "hours"})}' https://ClearGLASS/api/v1/schedules
Task options
Things you can/should provide while creating a new task:
- name (name of the cronjob), required
- desciption (to remember what it is), optional
- run_immediately (true/false) default false
- script_id (ex.'99f87bf3928743ab8f7f2b27e651643b'), required if you want to run a specific script
- action (reboot, destroy, start, shutdown), required if you want the task to perform an action
- enabled (true, false) default true
- expires in the form of (ex. '2016-3-24 17:20:00'), time is in UTC, optional
- cronjob_type (one_off, interval, crontab), required
- cronjob_entry (required), in the form of:
- interval: (ex. 'cronjob_entry':JSON.stringify({“every” : 1, “period” : “minutes”}) )
Available periods: days, hours, minutes, seconds, microseconds
- crontab: (ex. 'cronjob_entry':JSON.stringify({'minute':'*/50'}) )
example of crontabs
{"minute" : "30", "hour" : "2", "day_of_week" : "*", "day_of_month" : "*", "month_of_year" : "*"} other crontab examples: http://docs.celeryproject.org/en/latest/userguide/periodic-tasks.html#crontab-schedules * one_off: (ex. 'cronjob_entry':'2016-2-28 16:20:00' )
Getting all your tasks
To get a list of all your tasks, you need to send a GET call to / api /v1/schedules. E.g.:
user@user:/tmp$ curl -X GET -H "Authorization: 51fb1fc5554d0861d80843dd2612234365feb8211e9d191a70fde56a340bf742" https://ClearGLASS/api/v1/schedules
Getting a specific task
To get a specific task, you need to send a GET call to / api /v1/schedules/taskId. E.g.:
user@user:/tmp$ curl -X GET -H "Authorization: 51fb1fc5554d0861d80843dd2612234365feb8211e9d191a70fde56a340bf742" https://ClearGLASS/api/v1/schedules/3bb46efc882c4b44b21826e5e98f7c28
Editing a task
To edit the configuration of a task, you need to send a PUT call to / api /v1/schedules/taskId. E.g.:
user@user:/tmp$ curl -H "Authorization: 51fb1fc5554d0861d80843dd2612234365feb8211e9d191a70fde56a340bf742" -X POST -d '{'name':'test','script_id':'875cabc81fa1438b98ef25f099bbdf09', 'machines_per_cloud':[["b48a696e84554275a52fbe6278f6df56","i-781daaf3"]],'enabled':true,'expires':'2016-11-10 20:20:00','cronjob_type':'interval','cronjob_entry':JSON.stringify({"every" : 5,"period" : "hours"})}' https://clear.glass/api/v1/schedules/3bb46efc882c4b44b21826e5e98f7c28
Deleting a task
To delete one of your tasks, you need to send a DELETE call to / api /v1/schedules/taskId. E.g.:
user@user:/tmp$ curl -X DELETE -H "Authorization: 51fb1fc5554d0861d80843dd2612234365feb8211e9d191a70fde56a340bf742" https://clear.glass/api/v1/schedules/3bb46efc882c4b44b21826e5e98f7c28