From 64a948602a69d60ecfe4415b8570aff6098bc956 Mon Sep 17 00:00:00 2001 From: Paul Lecuq Date: Tue, 15 Sep 2020 13:14:34 +0200 Subject: [PATCH] updated salt modules --- states/_modules/dkron.py | 9 +++++---- states/_modules/ovhapi.py | 4 +--- states/_modules/syncthing.py | 38 +++++++++++++++++++++++------------- 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/states/_modules/dkron.py b/states/_modules/dkron.py index 4999a78..986732d 100644 --- a/states/_modules/dkron.py +++ b/states/_modules/dkron.py @@ -1,9 +1,9 @@ #!/usr/bin/python3 import requests -import json -def get_jobs(url="http://localhost:8080", verify=False): +def get_jobs(url="http://localhost:8898", verify=False): + """get_jobs fetch jobs from dkron""" fullurl = f"{url}/v1/jobs" ret = dict() try: @@ -15,7 +15,8 @@ def get_jobs(url="http://localhost:8080", verify=False): return ret return None -def set_jobs(url="http://localhost:8080", verify=False, job={}): +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: @@ -25,4 +26,4 @@ def set_jobs(url="http://localhost:8080", verify=False, job={}): ret = req.json() if req.status_code == 201: return ret - return None \ No newline at end of file + return None diff --git a/states/_modules/ovhapi.py b/states/_modules/ovhapi.py index a929e94..f677bee 100644 --- a/states/_modules/ovhapi.py +++ b/states/_modules/ovhapi.py @@ -2,9 +2,7 @@ from __future__ import absolute_import, unicode_literals, print_function -import re import salt -import requests import ovh from salt.exceptions import CommandExecutionError, ArgumentValueError @@ -150,4 +148,4 @@ def domain_refresh_zone(zone=""): raise ArgumentValueError("Zone is not defined") client = _auth() req = client.post(f'/domain/zone/{zone}/refresh') - return req \ No newline at end of file + return req diff --git a/states/_modules/syncthing.py b/states/_modules/syncthing.py index cae0b23..ae79dfc 100644 --- a/states/_modules/syncthing.py +++ b/states/_modules/syncthing.py @@ -1,9 +1,7 @@ #!/usr/bin/python3 -import requests -import json -import salt.exceptions import xml.etree.ElementTree as ET +import requests def get_apikey(configfile="/root/.config/syncthing/config.xml"): try: @@ -11,17 +9,20 @@ def get_apikey(configfile="/root/.config/syncthing/config.xml"): root = tree.getroot() apikey = root.find("./gui/apikey").text return apikey - except (FileNotFoundError,ET.ParseError,AttributeError) as e: - raise "Exception {0} occured".format(e) + except (FileNotFoundError, ET.ParseError, AttributeError) as exc: + raise f"Exception {exc} occured" return "" def get_config(url, verify, apikey): fullurl = "{0}/rest/system/config".format(url) ret = dict() try: - req = requests.request("get", fullurl, verify=verify, headers={"X-API-Key": apikey}) + req = requests.request("get", + fullurl, + verify=verify, + headers={"X-API-Key": apikey}) except (requests.exceptions.RequestException) as exc: - raise "Exception {0} occured".format(exc) + raise f"Exception {exc} occured" ret = req.json() if req.status_code == 200: return ret @@ -30,9 +31,13 @@ def get_config(url, verify, apikey): def set_config(url, verify, apikey, config): fullurl = "{0}/rest/system/config".format(url) try: - req = requests.request("post", fullurl, verify=verify, headers={"X-API-Key": apikey}, json=config) + req = requests.request("post", + fullurl, + verify=verify, + headers={"X-API-Key": apikey}, + json=config) except (requests.exceptions.RequestException) as exc: - raise "Exception {0} occured".format(exc) + raise f"Exception {exc} occured" if req.status_code == 200: return True return None @@ -40,9 +45,12 @@ def set_config(url, verify, apikey, config): def insync(url, verify, apikey): fullurl = "{0}/rest/system/config/insync".format(url) try: - req = requests.request("get", fullurl, verify=verify, headers={"X-API-Key": apikey}) + req = requests.request("get", + fullurl, + verify=verify, + headers={"X-API-Key": apikey}) except (requests.exceptions.RequestException) as exc: - raise "Exception {0} occured".format(exc) + raise f"Exception {exc} occured" ret = req.json() if req.status_code == 200: return ret @@ -51,9 +59,11 @@ def insync(url, verify, apikey): def restart(url, verify, apikey): fullurl = "{0}/rest/system/restart".format(url) try: - req = requests.post(fullurl, verify=verify, headers={"X-API-Key": apikey}) + req = requests.post(fullurl, + verify=verify, + headers={"X-API-Key": apikey}) except (requests.exceptions.RequestException) as exc: - raise "Exception {0} occured".format(exc) + raise f"Exception {exc} occured" if req.status_code == 200: return {} - return None \ No newline at end of file + return None