Exemplo n.º 1
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)
Exemplo n.º 2
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)
Exemplo n.º 3
0
def erase_assignment(workload, DB: MySQL, EEM: EEM):
    DB.start_transaction()

    workload_id = next(iter(workload.values()))
    # Retrieve server EEM net card and GID
    workload_server_net_card, gid = get_server_card(workload_id, DB)
    if not workload_server_net_card:
        return finish_assignment(
            False,
            "Workload does not exist or is not assigned to any server",
            DB)

    downs_port = get_card(workload_server_net_card, DB, EEM)["downstream_port"]
    if downs_port == "All down":
        message = (
            "Cannot erase assignment as the network card %s "
            "does not have any hardware card attached"
            % workload_server_net_card)
        return finish_assignment(
            False,
            message,
            DB)

    downs_port = downs_port["downstream_port_id"]
    assigned_cards = get_assignment_hardware(workload_id, DB)
    if not assigned_cards:
        message = (
            "Cannot erase assignment as the workload does not "
            "have any hardware card assigned"
        )
        return finish_assignment(
            False,
            message,
            DB)

    erase_message = ""
    for assigned_hardware in assigned_cards:
        assigned_hardware = next(iter(assigned_hardware))
        values = [assigned_hardware, workload_server_net_card, workload_id]

        if is_feasible_to_unasign_hardware(
                assigned_hardware,
                workload_server_net_card,
                DB):

            EEM.disconect_hardware_from_server(assigned_hardware)

            erase_message += "VLAN erased between %s and %s" % (
                assigned_hardware,
                workload_server_net_card)

        else:
            erase_message += (
                "VLAN between %s and %s could't be erased as "
                "there are other assignments in progress, "
                "DB assignment erased"
            ) % (assigned_hardware, workload_server_net_card)

        # Always eliminate assignment in DB even if the VLAN can't be erased
        status1, message1 = DB.delete_query(
            __table,
            assignment_keys,
            values)

        status2, message2 = DB.delete_query_simple(
            __table_assigned_capacities,
            "workload",
            workload_id)

        if not status1:
            status = False
            message = message1
        elif not status2:
            status = False
            message = message2
        else:
            status = True

        if not status:
            return finish_assignment(
                False,
                message,
                DB)

    return finish_assignment(
        True,
        erase_message,
        DB)