From 5d8819eca77dbffa91f1583d9e4fd3e4ce602dc4 Mon Sep 17 00:00:00 2001 From: Paul Lecuq Date: Fri, 31 Mar 2023 17:38:52 +0200 Subject: [PATCH] updated state modules --- states/_modules/dkron.py | 8 ++++---- states/_modules/syncthing.py | 1 + states/_states/dkron.py | 10 ++++++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/states/_modules/dkron.py b/states/_modules/dkron.py index 443a695..2c44174 100644 --- a/states/_modules/dkron.py +++ b/states/_modules/dkron.py @@ -4,8 +4,8 @@ import json from urllib.request import urlopen, Request -def get_jobs(url="http://localhost:8898"): - """get_jobs fetch jobs from dkron""" +def get_job(url="http://localhost:8898"): + """get_job fetchs jobs from dkron""" fullurl = f"{url}/v1/jobs" req = Request(method="GET", url=fullurl) res = urlopen(req) @@ -15,8 +15,8 @@ def get_jobs(url="http://localhost:8898"): return None -def set_jobs(url="http://localhost:8898", job=None): - """set_jobs set jobs on dkron""" +def set_job(url="http://localhost:8898", job=None): + """set_job sets job in dkron""" fullurl = f"{url}/v1/jobs" data = json.dumps(job).encode('utf-8') req = Request(method="POST", url=fullurl, data=data) diff --git a/states/_modules/syncthing.py b/states/_modules/syncthing.py index a36f306..d26cd93 100644 --- a/states/_modules/syncthing.py +++ b/states/_modules/syncthing.py @@ -3,6 +3,7 @@ import ssl import json import xml.etree.ElementTree as ET +import http.client from urllib.request import urlopen, Request from urllib.parse import urljoin from urllib.error import HTTPError diff --git a/states/_states/dkron.py b/states/_states/dkron.py index 5078358..df35de4 100644 --- a/states/_states/dkron.py +++ b/states/_states/dkron.py @@ -4,15 +4,17 @@ import salt.utils.dictupdate 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, 'changes': {}, 'result': True, 'comment': 'Config is up to date'} - for name, job in jobs.items(): - job['name'] = name - res = __salt__['dkron.set_jobs'](url, job) + for name, j in jobs.items(): + j['name'] = name + job = default_job.copy() + job.update(j) + res = __salt__['dkron.set_job'](url, job) if res is not None: ret['changes'][job['name']] = res else: