WIP: add: base files #1

Draft
fil wants to merge 3 commits from developing into main
2 changed files with 9 additions and 14 deletions
Showing only changes of commit c3641a76f4 - Show all commits

View file

@ -7,20 +7,17 @@ import os
class Database():
def __init__(self):
self.config = Config()
self.conn = self.conenct()
self.cur = self.conn.cursor(
cursor_factory=psycopg2.extras.RealDictCursor)
self.connect()
def conenct(self):
return psycopg2.connect(
def connect(self):
self.conn = psycopg2.connect(
host=self.config["DB_HOST"],
database=self.config["DB_DATABASE"],
user=self.config["DB_USER"],
password=self.config["DB_PASSWORD"]
)
def check_connection(self):
return self.conn.closed
self.cur = self.conn.cursor(
cursor_factory=psycopg2.extras.RealDictCursor)
def get_vm(self, id):
self.cur.execute("SELECT * FROM vm WHERE id = %s;", (str(id),))

View file

@ -165,9 +165,8 @@ class Uptime():
self.__disconnect()
def start(self):
if (self.db.check_connection()):
logger.info("Connecting to Database")
self.db.connect()
logger.info("Connecting to Database")
self.db.connect()
self.update_time = str(datetime.now(pytz.UTC).timestamp())
logger.info(f"Update time is {datetime.now(pytz.UTC)} \
({self.update_time})")
@ -197,9 +196,8 @@ class Uptime():
logger.info("Purge completed")
def calculate_sla(self):
if (self.db.check_connection()):
logger.info("Connecting to Database")
self.db.connect()
logger.info("Connecting to Database")
self.db.connect()
hits, failures, total = 0, 0, 0
logger.info("Calculating SLA (hits/failures)")
for vm in self.db.get_all_vm():