paulbsd-salt/states/_modules/dkron.py

30 lines
861 B
Python
Raw Normal View History

2020-07-10 00:58:55 +02:00
#!/usr/bin/python3
import requests
2020-09-15 13:14:34 +02:00
def get_jobs(url="http://localhost:8898", verify=False):
"""get_jobs fetch jobs from dkron"""
2020-07-10 00:58:55 +02:00
fullurl = f"{url}/v1/jobs"
ret = dict()
try:
req = requests.request("get", fullurl, verify=verify)
except (requests.exceptions.RequestException) as exc:
raise f"Exception {exc} occured"
ret = req.json()
if req.status_code == 200:
return ret
return None
2020-09-15 13:14:34 +02:00
def set_jobs(url="http://localhost:8898", verify=False, job=None):
"""set_jobs set jobs on dkron"""
2020-07-10 00:58:55 +02:00
fullurl = f"{url}/v1/jobs"
ret = dict()
try:
req = requests.request("post", fullurl, verify=verify, json=job)
except (requests.exceptions.RequestException) as exc:
raise f"Exception {exc} occured"
ret = req.json()
if req.status_code == 201:
return ret
2020-09-15 13:14:34 +02:00
return None