updated salt modules
This commit is contained in:
parent
4f7e38fb34
commit
64a948602a
@ -1,9 +1,9 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
import requests
|
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"
|
fullurl = f"{url}/v1/jobs"
|
||||||
ret = dict()
|
ret = dict()
|
||||||
try:
|
try:
|
||||||
@ -15,7 +15,8 @@ def get_jobs(url="http://localhost:8080", verify=False):
|
|||||||
return ret
|
return ret
|
||||||
return None
|
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"
|
fullurl = f"{url}/v1/jobs"
|
||||||
ret = dict()
|
ret = dict()
|
||||||
try:
|
try:
|
||||||
@ -25,4 +26,4 @@ def set_jobs(url="http://localhost:8080", verify=False, job={}):
|
|||||||
ret = req.json()
|
ret = req.json()
|
||||||
if req.status_code == 201:
|
if req.status_code == 201:
|
||||||
return ret
|
return ret
|
||||||
return None
|
return None
|
||||||
|
@ -2,9 +2,7 @@
|
|||||||
|
|
||||||
from __future__ import absolute_import, unicode_literals, print_function
|
from __future__ import absolute_import, unicode_literals, print_function
|
||||||
|
|
||||||
import re
|
|
||||||
import salt
|
import salt
|
||||||
import requests
|
|
||||||
import ovh
|
import ovh
|
||||||
|
|
||||||
from salt.exceptions import CommandExecutionError, ArgumentValueError
|
from salt.exceptions import CommandExecutionError, ArgumentValueError
|
||||||
@ -150,4 +148,4 @@ def domain_refresh_zone(zone=""):
|
|||||||
raise ArgumentValueError("Zone is not defined")
|
raise ArgumentValueError("Zone is not defined")
|
||||||
client = _auth()
|
client = _auth()
|
||||||
req = client.post(f'/domain/zone/{zone}/refresh')
|
req = client.post(f'/domain/zone/{zone}/refresh')
|
||||||
return req
|
return req
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
import requests
|
|
||||||
import json
|
|
||||||
import salt.exceptions
|
|
||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
|
import requests
|
||||||
|
|
||||||
def get_apikey(configfile="/root/.config/syncthing/config.xml"):
|
def get_apikey(configfile="/root/.config/syncthing/config.xml"):
|
||||||
try:
|
try:
|
||||||
@ -11,17 +9,20 @@ def get_apikey(configfile="/root/.config/syncthing/config.xml"):
|
|||||||
root = tree.getroot()
|
root = tree.getroot()
|
||||||
apikey = root.find("./gui/apikey").text
|
apikey = root.find("./gui/apikey").text
|
||||||
return apikey
|
return apikey
|
||||||
except (FileNotFoundError,ET.ParseError,AttributeError) as e:
|
except (FileNotFoundError, ET.ParseError, AttributeError) as exc:
|
||||||
raise "Exception {0} occured".format(e)
|
raise f"Exception {exc} occured"
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
def get_config(url, verify, apikey):
|
def get_config(url, verify, apikey):
|
||||||
fullurl = "{0}/rest/system/config".format(url)
|
fullurl = "{0}/rest/system/config".format(url)
|
||||||
ret = dict()
|
ret = dict()
|
||||||
try:
|
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:
|
except (requests.exceptions.RequestException) as exc:
|
||||||
raise "Exception {0} occured".format(exc)
|
raise f"Exception {exc} occured"
|
||||||
ret = req.json()
|
ret = req.json()
|
||||||
if req.status_code == 200:
|
if req.status_code == 200:
|
||||||
return ret
|
return ret
|
||||||
@ -30,9 +31,13 @@ def get_config(url, verify, apikey):
|
|||||||
def set_config(url, verify, apikey, config):
|
def set_config(url, verify, apikey, config):
|
||||||
fullurl = "{0}/rest/system/config".format(url)
|
fullurl = "{0}/rest/system/config".format(url)
|
||||||
try:
|
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:
|
except (requests.exceptions.RequestException) as exc:
|
||||||
raise "Exception {0} occured".format(exc)
|
raise f"Exception {exc} occured"
|
||||||
if req.status_code == 200:
|
if req.status_code == 200:
|
||||||
return True
|
return True
|
||||||
return None
|
return None
|
||||||
@ -40,9 +45,12 @@ def set_config(url, verify, apikey, config):
|
|||||||
def insync(url, verify, apikey):
|
def insync(url, verify, apikey):
|
||||||
fullurl = "{0}/rest/system/config/insync".format(url)
|
fullurl = "{0}/rest/system/config/insync".format(url)
|
||||||
try:
|
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:
|
except (requests.exceptions.RequestException) as exc:
|
||||||
raise "Exception {0} occured".format(exc)
|
raise f"Exception {exc} occured"
|
||||||
ret = req.json()
|
ret = req.json()
|
||||||
if req.status_code == 200:
|
if req.status_code == 200:
|
||||||
return ret
|
return ret
|
||||||
@ -51,9 +59,11 @@ def insync(url, verify, apikey):
|
|||||||
def restart(url, verify, apikey):
|
def restart(url, verify, apikey):
|
||||||
fullurl = "{0}/rest/system/restart".format(url)
|
fullurl = "{0}/rest/system/restart".format(url)
|
||||||
try:
|
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:
|
except (requests.exceptions.RequestException) as exc:
|
||||||
raise "Exception {0} occured".format(exc)
|
raise f"Exception {exc} occured"
|
||||||
if req.status_code == 200:
|
if req.status_code == 200:
|
||||||
return {}
|
return {}
|
||||||
return None
|
return None
|
||||||
|
Loading…
Reference in New Issue
Block a user