mirror of
https://github.com/ThomasGsp/HyperProxmox.git
synced 2025-03-09 15:40:18 +00:00
Add error managment
This commit is contained in:
parent
d9de9384a2
commit
898f5af57e
3 changed files with 136 additions and 85 deletions
|
@ -307,8 +307,8 @@ class Core:
|
|||
"type": "PROXMOX - VALUES",
|
||||
"value": "{0} is not a valid VMID: {1}".format(vmid, ierror)
|
||||
}
|
||||
|
||||
return result
|
||||
# Voir comment return ça proprement
|
||||
return
|
||||
|
||||
"""
|
||||
#######################
|
||||
|
@ -330,9 +330,17 @@ class Core:
|
|||
data["password"] = base64.b64encode(pcrypt(data["password"], self.generalconf["keys"]["key_pvt"])["data"]).decode('utf-8')
|
||||
new_cluster = self.mongo.insert_new_cluster(data)
|
||||
else:
|
||||
new_cluster = {"value": "{0}".format("Duplicate entry, please delete the current cluster or update it")}
|
||||
new_cluster = {
|
||||
"value": "{0}".format("Duplicate entry, please delete the current cluster or update it")
|
||||
"result": "ERROR",
|
||||
"type": "PROXMOX - VALUES"
|
||||
}
|
||||
else:
|
||||
new_cluster = {"value": "{1} {0}".format(testdata, "Invalid or miss paramettrer")}
|
||||
new_cluster = {
|
||||
"value": "{1} {0}".format(testdata, "Invalid or miss paramettrer")
|
||||
"result": "ERROR",
|
||||
"type": "PROXMOX - VALUES"
|
||||
}
|
||||
|
||||
|
||||
return new_cluster
|
||||
|
|
|
@ -40,23 +40,27 @@ class Proxmox:
|
|||
self.ticket = self.socket.post(request, params=params, verify=False, timeout=5)
|
||||
|
||||
if self.ticket.status_code == 200:
|
||||
result = {"result": "OK",
|
||||
"value": self.ticket.json()
|
||||
}
|
||||
result = {
|
||||
"result": "OK",
|
||||
"value": self.ticket.json()
|
||||
}
|
||||
self.PVEAuthCookie = {'PVEAuthCookie': self.ticket.json()['data']['ticket']}
|
||||
self.csrf = {'CSRFPreventionToken': self.ticket.json()['data']['CSRFPreventionToken']}
|
||||
else:
|
||||
result = {"result": "ERROR",
|
||||
"target": "{0}".format(request),
|
||||
"type": "PROXMOX - STATUS CODE",
|
||||
"value": "Error nodes informations. Bad HTTP Status code : "
|
||||
"{0} -- {1}".format(self.ticket.status_code, self.ticket.text)
|
||||
}
|
||||
result = {
|
||||
"result": "ERROR",
|
||||
"target": "{0}".format(request),
|
||||
"type": "PROXMOX - STATUS CODE",
|
||||
"value": "Error nodes informations. Bad HTTP Status code : "
|
||||
"{0} -- {1}".format(self.ticket.status_code, self.ticket.text)
|
||||
}
|
||||
except (TypeError, ValueError, requests.exceptions.RequestException) as e:
|
||||
result = {"result": "ERROR",
|
||||
"target": "{0}".format(url),
|
||||
"type": "PYTHON",
|
||||
"value": "Cannot get ticket session {0} ({1})".format(url, e)}
|
||||
result = {
|
||||
"result": "ERROR",
|
||||
"target": "{0}".format(url),
|
||||
"type": "PYTHON",
|
||||
"value": "Cannot get ticket session {0} ({1})".format(url, e)
|
||||
}
|
||||
|
||||
return result
|
||||
|
||||
|
@ -104,10 +108,18 @@ class Proxmox:
|
|||
request = "https://{0}/api2/json/nodes/{1}/status".format(url, nodename)
|
||||
try:
|
||||
self.status = self.socket.get(request, cookies=self.PVEAuthCookie, verify=False, timeout=5).json()
|
||||
result = {"result": "OK"}
|
||||
result = {
|
||||
"result": "OK",
|
||||
"value": self.status
|
||||
|
||||
}
|
||||
except (TypeError, ValueError, requests.exceptions.RequestException) as e:
|
||||
result = {"result": "ERROR", "target": "[{3}]",
|
||||
"value": "Cannot get node information for {0} ({1})".format(url, e, nodename)}
|
||||
result = {
|
||||
"result": "ERROR",
|
||||
"target": "{0}".format(nodename),
|
||||
"type": "PYTHON - ERROR",
|
||||
"value": "Cannot get node information for {0} ({1})".format(url, e)
|
||||
}
|
||||
|
||||
return result
|
||||
|
||||
|
@ -120,10 +132,17 @@ class Proxmox:
|
|||
request = "https://{0}/api2/json/nodes/{1}/storage".format(url, nodename)
|
||||
try:
|
||||
self.storage = self.socket.get(request, cookies=self.PVEAuthCookie, verify=False, timeout=5).json()
|
||||
result = {"result": "OK"}
|
||||
result = {
|
||||
"result": "OK",
|
||||
"value": self.storage
|
||||
}
|
||||
except (TypeError, ValueError, requests.exceptions.RequestException) as e:
|
||||
result = {"result": "ERROR", "target": "[{3}]",
|
||||
"value": "Cannot get storage information for {0} ({1})".format(url, e, nodename)}
|
||||
result = {
|
||||
"result": "ERROR",
|
||||
"type": "PYTHON - ERROR",
|
||||
"target": "{0}".format(nodename),
|
||||
"value": "Cannot get storage information for {0} ({1})".format(url, e)
|
||||
}
|
||||
|
||||
return result
|
||||
|
||||
|
@ -137,10 +156,17 @@ class Proxmox:
|
|||
request = "https://{0}/api2/json/nodes/{1}/storage/{2}/content".format(url, nodename, sto_id)
|
||||
try:
|
||||
self.disks = self.socket.get(request, cookies=self.PVEAuthCookie, verify=False, timeout=5).json()
|
||||
result = {"result": "OK"}
|
||||
result = {
|
||||
"result": "OK",
|
||||
"value": self.disks
|
||||
}
|
||||
except (TypeError, ValueError, requests.exceptions.RequestException) as e:
|
||||
result = {"result": "ERROR", "target": "[{3}]",
|
||||
"value": "Cannot get disks information for {0} ({1})".format(url, e, nodename)}
|
||||
result = {
|
||||
"result": "ERROR",
|
||||
"type": "PYTHON - ERROR",
|
||||
"target": "{0}".format(nodename),
|
||||
"value": "Cannot get disks information for {0} ({1})".format(url, e)
|
||||
}
|
||||
|
||||
return result
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue