2020-07-10 00:58:55 +02:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
import requests
|
|
|
|
|
2021-07-11 17:37:42 +02:00
|
|
|
|
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:
|
2021-07-11 17:37:42 +02:00
|
|
|
req = requests.request("GET", fullurl, verify=verify)
|
2020-07-10 00:58:55 +02:00
|
|
|
except (requests.exceptions.RequestException) as exc:
|
|
|
|
raise f"Exception {exc} occured"
|
|
|
|
ret = req.json()
|
|
|
|
if req.status_code == 200:
|
|
|
|
return ret
|
|
|
|
return None
|
|
|
|
|
2021-07-11 17:37:42 +02:00
|
|
|
|
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:
|
2021-07-11 17:37:42 +02:00
|
|
|
req = requests.request("POST", fullurl, verify=verify, json=job)
|
2020-07-10 00:58:55 +02:00
|
|
|
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
|