Beispiel #1
0
def update_cards(cards, DB):
    DB_cards = []
    statement = (
        "SELECT id "
        "FROM hardware_cards"
    )
    statement2 = (
        "SELECT id "
        "FROM net_card"
    )
    for DB_card in DB.select_query(statement):
        while (isinstance(DB_card, Iterable) and not isinstance(DB_card, str)):
            DB_card = next(iter(DB_card))
        DB_cards.append(DB_card)
    for DB_card in DB.select_query(statement2):
        while (isinstance(DB_card, Iterable) and not isinstance(DB_card, str)):
            DB_card = next(iter(DB_card))
        DB_cards.append(DB_card)
    for card in cards:
        status = True
        card = eemParser.parse(card)
        if card["id"] not in DB_cards:
            if card["status"] == "eeio":
                status, message = update_hardware_card(card, DB)
            else:
                status, message = update_net_card(card, DB)

            if not status:
                return messenger.general_error(message)

    return messenger.message200('OK')
Beispiel #2
0
def erase_card(id, DB: MySQL, EEM: EEM):
    DB.start_transaction()

    if get_card(id, DB, EEM)["status"] == "eeio":
        DB.start_transaction()

        status, message = DB.delete_query_simple(__table_hardware, "id", id)

    else:
        status, message = DB.delete_query_simple(__table_net, "id", id)

    # First status code checks:
    # 1: Syntaxis
    # 2: Completeness
    if status:
        status, result = DB.commit_transaction()
        # Second status checks:
        # 1: Data integrity
        if status:
            return messenger.message200("OK")

        # Implicit rollback
        else:
            return messenger.message404(message)
    else:
        status, error = DB.rollback(messsage)
        return messenger.message404(error)
Beispiel #3
0
def modify_hardware_tag(card, DB: MySQL, EEM: EEM):
    DB.start_transaction()

    status, message = modify_card(card, __table_hardware, hardware_card_keys,
                                  DB, EEM)

    status, message = modify_capacities(card, __table_hardware_capacity,
                                        hardware_capacity_keys, DB, EEM)

    # First status code checks:
    # 1: Syntaxis
    # 2: Completeness
    if status:
        status, message = DB.commit_transaction()
        # Second status checks:
        # 1: Data integrity
        if status:
            return messenger.message200("OK")

        # Implicit rollback
        else:
            return messenger.message404(message)
    else:
        status, error = DB.rollback(message)
        return messenger.message404(error)
Beispiel #4
0
def finish_assignment(success, message, DB):
    if success:
        status, commit_message = DB.commit_transaction()
        if status:
            return messenger.message200(message)

        # Implicit rollback
        else:
            return messenger.message409(commit_message)
    else:
        status, error = DB.rollback(message)
        return messenger.message409(error)
Beispiel #5
0
def erase_workload(id, DB: MySQL):
    DB.start_transaction()

    # A single delete is enough as child tables delete on cascade
    status, message = DB.delete_query_simple(__table_workloads, "id", id)

    # First status code checks:
    # 1: Syntaxis
    # 2: Completeness
    if status:
        status, message = DB.commit_transaction()
        # Second status checks:
        # 1: Data integrity
        if status:
            return messenger.message200("OK")

        # Implicit rollback
        else:
            return messenger.message404(message)
    else:
        status, error = DB.rollback(messsage)
        return messenger.message404(error)