paulbsd-salt/states/_modules/dkron.py
2021-07-11 17:37:42 +02:00

32 lines
863 B
Python

#!/usr/bin/python3
import requests
def get_jobs(url="http://localhost:8898", verify=False):
"""get_jobs fetch jobs from dkron"""
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
def set_jobs(url="http://localhost:8898", verify=False, job=None):
"""set_jobs set jobs on dkron"""
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
return None