예제 #1
0
def get_application_from_ID(appid: int):
    query = "SELECT * FROM application WHERE id = %s"
    info = (appid, )
    application = Application()

    try:
        conn = get_connection()

        if conn:
            cursor = conn.cursor()
            cursor.execute(query, info)
            item = cursor.fetchone()

            if item:
                application.appid = item[0]
                application.name = item[1]
                application.type = item[2]
                application.image = item[3]
                application.min_memory = item[4]
                application.num_cores = item[5]
                application.comments = item[6]
                # print('Application: ', vars(application))

            cursor.close()
            conn.close()

    except mysql.connector.Error as err:
        logging.error('Getting Application %s Info on Database Error: %s',
                      appid, err)

    finally:
        return application
예제 #2
0
def list_applications():
    query = "SELECT * FROM application"
    app_list = []

    try:
        conn = get_connection()

        if conn:
            cursor = conn.cursor()
            cursor.execute(query)

            for item in cursor:
                app = Application()
                app.appid = item[0]
                app.name = item[1]
                app.type = item[2]
                app.image = item[3]
                app.min_memory = item[4]
                app.num_cores = item[5]
                app.comments = item[6]
                # print('Application: ', vars(app))
                app_list.append(app)

            cursor.close()
            conn.close()

    except mysql.connector.Error as err:
        logging.error('Getting Application List on Database Error: %s', err)

    finally:
        if not app_list:
            logging.info('Not Find any Application on Database')
        return app_list