recreate cache if cannot read

This commit is contained in:
Miłosz Stocki 2019-12-12 14:22:16 +01:00
parent ec5ce90d9a
commit 27b2efbc95
Signed by: osiu97
GPG Key ID: E3D1D83FA04F51D6
2 changed files with 10 additions and 5 deletions

View File

@ -5,7 +5,7 @@ from VM import VM
from Storage import Storage
USERNAME = "zabbix@pve"
PASSWORD = "KbCurGdt82NTgBye"
PASSWORD = "zabbix"
HOST = "localhost:8006"
conn = PVEApi(HOST, USERNAME, PASSWORD)

View File

@ -53,10 +53,15 @@ class PVEApi(object):
Proxmox says ticket is valid for 2 hours. For safety we use 1 hour
:return: Boolean value of True if ticket is considered expired. False if opposite.
"""
with open(CACHEFILE, 'r') as f:
data = json.load(f)
timestamp = data['timestamp']
return True if time.time() - timestamp > 3600 else False
try:
with open(CACHEFILE, 'r') as f:
data = json.load(f)
timestamp = data['timestamp']
return True if time.time() - timestamp > 3600 else False
except:
self.csrftoken = get_auth(self.host, username, password)[0]
self.ticket = get_auth(self.host, username, password)[1]
self.write_ticketcache()
def write_ticketcache(self):