updated state modules

This commit is contained in:
Paul 2023-03-31 17:38:52 +02:00
parent 4ed76b8dbb
commit 5d8819eca7
3 changed files with 11 additions and 8 deletions

View File

@ -4,8 +4,8 @@ import json
from urllib.request import urlopen, Request from urllib.request import urlopen, Request
def get_jobs(url="http://localhost:8898"): def get_job(url="http://localhost:8898"):
"""get_jobs fetch jobs from dkron""" """get_job fetchs jobs from dkron"""
fullurl = f"{url}/v1/jobs" fullurl = f"{url}/v1/jobs"
req = Request(method="GET", url=fullurl) req = Request(method="GET", url=fullurl)
res = urlopen(req) res = urlopen(req)
@ -15,8 +15,8 @@ def get_jobs(url="http://localhost:8898"):
return None return None
def set_jobs(url="http://localhost:8898", job=None): def set_job(url="http://localhost:8898", job=None):
"""set_jobs set jobs on dkron""" """set_job sets job in dkron"""
fullurl = f"{url}/v1/jobs" fullurl = f"{url}/v1/jobs"
data = json.dumps(job).encode('utf-8') data = json.dumps(job).encode('utf-8')
req = Request(method="POST", url=fullurl, data=data) req = Request(method="POST", url=fullurl, data=data)

View File

@ -3,6 +3,7 @@
import ssl import ssl
import json import json
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
import http.client
from urllib.request import urlopen, Request from urllib.request import urlopen, Request
from urllib.parse import urljoin from urllib.parse import urljoin
from urllib.error import HTTPError from urllib.error import HTTPError

View File

@ -4,15 +4,17 @@ import salt.utils.dictupdate
import salt.utils.dictdiffer import salt.utils.dictdiffer
def jobs(name, url="http://localhost:8080", verify=False, jobs={}): def jobs(name, url="http://localhost:8080", verify=False, jobs={}, default_job={}):
ret = {'name': name, ret = {'name': name,
'changes': {}, 'changes': {},
'result': True, 'result': True,
'comment': 'Config is up to date'} 'comment': 'Config is up to date'}
for name, job in jobs.items(): for name, j in jobs.items():
job['name'] = name j['name'] = name
res = __salt__['dkron.set_jobs'](url, job) job = default_job.copy()
job.update(j)
res = __salt__['dkron.set_job'](url, job)
if res is not None: if res is not None:
ret['changes'][job['name']] = res ret['changes'][job['name']] = res
else: else: