paulbsd-salt/states/_modules/dkron.py

29 lines
771 B
Python
Raw Normal View History

2020-07-10 00:58:55 +02:00
#!/usr/bin/python3
2021-10-02 12:39:16 +02:00
import json
from urllib.request import urlopen, Request
2020-07-10 00:58:55 +02:00
2021-07-11 17:37:42 +02:00
2023-03-31 17:38:52 +02:00
def get_job(url="http://localhost:8898"):
"""get_job fetchs jobs from dkron"""
2020-07-10 00:58:55 +02:00
fullurl = f"{url}/v1/jobs"
2021-10-02 12:39:16 +02:00
req = Request(method="GET", url=fullurl)
res = urlopen(req)
dkron_ret = json.loads(res.read())
if res.status == 200:
return dkron_ret
2020-07-10 00:58:55 +02:00
return None
2021-07-11 17:37:42 +02:00
2023-03-31 17:38:52 +02:00
def set_job(url="http://localhost:8898", job=None):
"""set_job sets job in dkron"""
2020-07-10 00:58:55 +02:00
fullurl = f"{url}/v1/jobs"
2021-10-02 12:39:16 +02:00
data = json.dumps(job).encode('utf-8')
req = Request(method="POST", url=fullurl, data=data)
req.add_header('Content-Type', 'application/json')
res = urlopen(req)
dkron_ret = json.loads(res.read())
if res.status == 201:
return dkron_ret
2020-09-15 13:14:34 +02:00
return None