def __init__(self, config_path, config_private_path):
     with open(config_path, encoding = 'utf-8') as json_file:
         config = json.load(json_file)
     with open(config_private_path, encoding = 'utf-8') as json_file:
         config_private = json.load(json_file)
     self.config_path      = config_path
     self.week_index       = config.get("week_index")
     self.folder           = config.get("folder")
     self.filename         = config.get("filename")
     self.lesson_end_time  = config.get("lesson_end_time")
     self.greetings        = config.get("greetings")
     self.day_of_week      = config.get("day_of_week")
     self.lessons_schedule = config.get("lessons_schedule")
     self.bot_token        = config_private.get("bot_token")
     self.db_url           = config_private.get("db_url")
     self.timetable        = dict()
     self.bot              = aiogram.Bot(self.bot_token)
     self.dp               = aiogram.Dispatcher(self.bot)
     self.xls              = XlsHandler("../{}/{}".format(
                                     self.folder,
                                     self.filename
                                 ),
                                 self.day_of_week
                             )
     self.db               = dbHandler(self.db_url)
Esempio n. 2
0
def get_snapshot_restore_delete_status(restore_name,restore_type):
    try:
        conn = db_handler.dbHandler()
        cursor = conn.cursor()
        get_snapshot_restore_delete_status = ("select deleted from restores where display_name='"+restore_name+"' and restore_type='"+restore_type+"' order by deleted_at desc limit 1")
        cursor.execute(get_snapshot_restore_delete_status)
        rows = cursor.fetchall()
        for row in rows:
            return row[0]
    except Exception as e:
        print (str(e))
    finally:
        cursor.close()
        conn.close()
Esempio n. 3
0
def get_workload_status(workload_name):
    try:
        conn = db_handler.dbHandler()
        cursor = conn.cursor()
        get_workload_snapshot = ("select status from workloads where display_name='"+workload_name+"' order by created_at desc limit 1")
        cursor.execute(get_workload_snapshot)
        rows = cursor.fetchall()
        for row in rows:
            return row[0]
    except Exception as e:
        print (str(e))
    finally:
        cursor.close()
        conn.close()
Esempio n. 4
0
def get_workload_display_description(workload_id):
    try:
        conn = db_handler.dbHandler()
        cursor = conn.cursor()
        get_workload_display_description = ("select display_description from workloads where id='"+workload_id+"'")
        cursor.execute(get_workload_display_description)
        rows = cursor.fetchall()
        for row in rows:
            return row[0]
    except Exception as e:
        print (str(e))
    finally:
        cursor.close()
        conn.close()
Esempio n. 5
0
def get_inprogress_snapshot_id(workload_id):
    try:
        conn = db_handler.dbHandler()
        cursor = conn.cursor()
        get_workload_vmid = ("select id from snapshots where workload_id='"+workload_id+"' and status<>'available' order by updated_at desc limit 1")
        cursor.execute(get_workload_vmid)
        rows = cursor.fetchall()
        for row in rows:
            return row[0]
    except Exception as e:
        print (str(e))
    finally:
        cursor.close()
        conn.close()
Esempio n. 6
0
def get_workload_vmid(workload_id):
    try:
        conn = db_handler.dbHandler()
        cursor = conn.cursor()
        get_workload_vmid = ("select vm_id from workload_vms where workload_id='"+workload_id+"'")
        cursor.execute(get_workload_vmid)
        rows = cursor.fetchall()
        for row in rows:
            return row[0]
    except Exception as e:
        print (str(e))
    finally:
        cursor.close()
        conn.close()
Esempio n. 7
0
def get_workload_snapshot_delete_status(snapshot_name,snapshot_type, snapshot_id):
    try:
        conn = db_handler.dbHandler()
        cursor = conn.cursor()
        get_workload_snapshot_delete_status = ("select deleted from snapshots where display_name='"+snapshot_name+"' and snapshot_type='"+snapshot_type+"' and id='" + str(snapshot_id) + "' order by deleted_at desc limit 1")
        cursor.execute(get_workload_snapshot_delete_status)
        rows = cursor.fetchall()
        for row in rows:
            return row[0]
    except Exception as e:
        print (str(e))
    finally:
        cursor.close()
        conn.close()
Esempio n. 8
0
def get_snapshot_restore_id(snapshot_id):
    try:
        conn = db_handler.dbHandler()
        cursor = conn.cursor()
        get_snapshot_restore_id = ("select id from restores where snapshot_id='"+snapshot_id+"' order by deleted_at asc limit 1")
        cursor.execute(get_snapshot_restore_id)
        rows = cursor.fetchall()
        for row in rows:
            return row[0]
    except Exception as e:
        print (str(e))
    finally:
        cursor.close()
        conn.close()
Esempio n. 9
0
def get_available_vms_of_workload(workload_id):
    try:
        conn = db_handler.dbHandler()
        cursor = conn.cursor()
        get_count = ("select count(*) from workload_vms where workload_id='" + str(workload_id) + "' and status <> 'deleted';")
        cursor.execute(get_count)
        rows = cursor.fetchall()
        for row in rows:
            return row[0]
    except Exception as e:
        print (str(e))
    finally:
        cursor.close()
        conn.close()
Esempio n. 10
0
def get_available_restores():
    try:
        conn = db_handler.dbHandler()
        cursor = conn.cursor()
        get_available_restores = ("select count(*) from restores where status=\"available\"")
        cursor.execute(get_available_restores)
        rows = cursor.fetchall()
        for row in rows:
            return row[0]
    except Exception as e:
        print (str(e))
    finally:
        cursor.close()
        conn.close()
Esempio n. 11
0
def get_workload_count(workload_name):
    try:
        conn = db_handler.dbHandler()
        cursor = conn.cursor()
        get_workload_count = ("select count(*) from workloads where display_name='"+workload_name+"' and status=\"available\"")
        cursor.execute(get_workload_count)
        rows = cursor.fetchall()
        for row in rows:
            return row[0]
    except Exception as e:
        print (str(e))
    finally:
        cursor.close()
        conn.close()
Esempio n. 12
0
def get_available_snapshots():
    try:
        conn = db_handler.dbHandler()
        cursor = conn.cursor()
        get_available_snapshots = ("select count(*) from snapshots where deleted=0 and status = 'available' order by created_at desc limit 1")
        cursor.execute(get_available_snapshots)
        rows = cursor.fetchall()
        for row in rows:
            return row[0]
    except Exception as e:
        print (str(e))
    finally:
        cursor.close()
        conn.close()
Esempio n. 13
0
def get_config_workload_id():
    try:
        conn = db_handler.dbHandler()
        cursor = conn.cursor()
        get_config_backup_id = ("select id from config_workloads;")
        cursor.execute(get_config_backup_id)
        rows = cursor.fetchall()
        for row in rows:
            return row[0]
    except Exception as e:
        print (str(e))
    finally:
        cursor.close()
        conn.close()
Esempio n. 14
0
def get_available_snapshots_for_workload(snapshot_name, workload_id):
    try:
        conn = db_handler.dbHandler()
        cursor = conn.cursor()
        get_available_snapshots = ("select count(*) from snapshots where display_name='"+snapshot_name+"' and workload_id='" + str(workload_id) + "' and deleted=0 order by created_at desc limit 1")
        cursor.execute(get_available_snapshots)
        rows = cursor.fetchall()
        for row in rows:
            return row[0]
    except Exception as e:
        print (str(e))
    finally:
        cursor.close()
        conn.close()
Esempio n. 15
0
def get_deleted_workload(workload_id):
    try:
        conn = db_handler.dbHandler()
        cursor = conn.cursor()
        get_deleted_workload = ("select status from workloads where id='"+str(workload_id)+"' order by updated_at desc limit 1")
        cursor.execute(get_deleted_workload)
        rows = cursor.fetchall()
        for row in rows:
            return row[0]
    except Exception as e:
        print (str(e))
    finally:
        cursor.close()
        conn.close()
Esempio n. 16
0
def get_workload_type_data(workload_type_id):
    try:
        conn = db_handler.dbHandler()
        cursor = conn.cursor()
        get_workload_types = ("select * from workload_types where deleted <> 1 and ID='" + str(workload_type_id) + "'")
        cursor.execute(get_workload_types)
        rows = cursor.fetchall()
        for row in rows:
            return row
    except Exception as e:
        LOG.error(str(e))
    finally:
        cursor.close()
        conn.close()
Esempio n. 17
0
def get_available_workload_types():
    try:
        conn = db_handler.dbHandler()
        cursor = conn.cursor()
        get_workload_types = ("select count(*) from workload_types where deleted <> 1")
        cursor.execute(get_workload_types)
        rows = cursor.fetchall()
        for row in rows:
            return row[0]
    except Exception as e:
        LOG.error(str(e))
    finally:
        cursor.close()
        conn.close()
Esempio n. 18
0
def get_workload_schedule(workload_id):
    try:
        conn = db_handler.dbHandler()
        cursor = conn.cursor()
        get_workload_schedule = ("select jobschedule from workloads where id='"+workload_id+"' order by created_at desc limit 1")
        cursor.execute(get_workload_schedule)
        rows = cursor.fetchall()
        for row in rows:
            return row[0]
    except Exception as e:
        LOG.error(str(e))
    finally:
        cursor.close()
        conn.close()
Esempio n. 19
0
def get_vmids():
    try:
        vmlist = []
        conn = db_handler.dbHandler()
        cursor = conn.cursor()
        get_vmids = ("select vm_id from workload_vms where status=\"available\"")
        cursor.execute(get_vmids)
        rows = cursor.fetchall()
        for row in rows:
            vmlist.append(str(row[0]))
        return vmlist
    except Exception as e:
        print (str(e))
    finally:
        cursor.close()
        conn.close()
Esempio n. 20
0
app = Flask(__name__)
#app.permanent_session_lifetime = False
app.secret_key = "3a4ds3fdfad3s2fas5d"
mail_settings = {
    "MAIL_SERVER": 'smtp.gmail.com',
    "MAIL_PORT": 465,
    "MAIL_USE_TLS": False,
    "MAIL_USE_SSL": True,
    "MAIL_USERNAME": '******',
    "MAIL_PASSWORD": '******'
}
app.config.update(mail_settings)
mail = Mail(app)
serializer = URLSafeTimedSerializer("3a4ds3fdfad3s2fas5d")
handler = dbHandler()


@app.route('/')
def test():
    return render_template('manage_plans.html', plans=handler.get_all_plans())


@app.route('/login_admin', methods=['POST', 'GET'])
def admin_login():
    if request.method == 'POST':
        user_name = request.form.get('user_name')
        password = request.form.get('pswd')
        auth = handler.authenticate_admin(user_name, password)
        if auth:
            session['admin'] = True