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
|
|
|
|
2021-10-02 12:39:16 +02:00
|
|
|
def get_jobs(url="http://localhost:8898"):
|
2020-09-15 13:14:34 +02:00
|
|
|
"""get_jobs fetch 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
|
|
|
|
2021-10-02 12:39:16 +02:00
|
|
|
def set_jobs(url="http://localhost:8898", job=None):
|
2020-09-15 13:14:34 +02:00
|
|
|
"""set_jobs set jobs on 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
|