Ejemplo n.º 1
0
 def getSwitchById(switch_id):
     try:
         lock.acquire(True)
         queryCursor.execute(
             "SELECT device_id, switch_name, dir_path FROM switches WHERE device_id=?",
             (switch_id, ))
         row = queryCursor.fetchone()
         if row is None:
             return False
         else:
             return SwitchObject(row[0], row[1], row[2])
     finally:
         lock.release()
Ejemplo n.º 2
0
 def addSwitch(dict, switch_id, switch_name, dir_path):
     try:
         lock.acquire(True)
         try:
             queryCursor.execute(
                 "INSERT INTO switches (device_id, switch_name, dir_path) VALUES (?, ?, ?)",
                 (switch_id, switch_name, dir_path))
             dbVar.commit()
             dict[(switch_id)] = SwitchObject(switch_id, switch_name,
                                              dir_path)
             return True
         except:
             return False
     finally:
         lock.release()
Ejemplo n.º 3
0
 def getSwitchByName(switch_name):
     try:
         lock.acquire(True)
         queryCursor.execute(
             "SELECT device_id, switch_name, switch_type, pvs_dir_path, bmv2_address FROM switches WHERE switch_name=?",
             (switch_name, ))
         row = queryCursor.fetchone()
         if row is None:
             return False
         else:
             return SwitchObject(row[0],
                                 row[1],
                                 row[2],
                                 pvs_dir_path=row[3],
                                 bmv2_address=row[4])
     finally:
         lock.release()
Ejemplo n.º 4
0
    def loadDbMemory(switch_dict, table_dict, table_action_dict):
        try:
            lock.acquire(True)
            # Load switches dictionary.
            queryCursor.execute("SELECT * FROM switches")
            switches = queryCursor.fetchall()
            for switch in switches:
                switch_dict[(switch[0])] = SwitchObject(switch[0],
                                                        switch[1],
                                                        switch[2],
                                                        pvs_dir_path=switch[3],
                                                        bmv2_address=switch[4])

            # Load tables dictionary.
            queryCursor.execute("SELECT * FROM switch_tables")
            tables = queryCursor.fetchall()
            for table in tables:
                table_dict[(table[0], table[1])] = SwitchTableObject(
                    table[0], table[1], table[2], table[3], table[4])
                queryCursor.execute(
                    "SELECT field_name, field_size FROM table_match_fields WHERE device_id=? AND table_id=?",
                    (table[0], table[1]))
                fields = queryCursor.fetchall()
                for field in fields:
                    table_dict[(table[0], table[1])].match_fields.append(field)

            # Load actions dictionary.
            queryCursor.execute("SELECT * FROM table_actions")
            actions = queryCursor.fetchall()
            for action in actions:
                table_action_dict[(action[0], action[1],
                                   action[2])] = SwitchTableActionObject(
                                       action[0], action[1], action[2],
                                       action[3])
                queryCursor.execute(
                    "SELECT field_name, field_size FROM table_action_fields WHERE device_id=? AND table_id=? AND action_id=?",
                    (action[0], action[1], action[2]))
                fields = queryCursor.fetchall()
                for field in fields:
                    table_action_dict[(action[0], action[1],
                                       action[2])].action_fields.append(field)

            print "Successfully loaded switches and tables database into memory"
            return True
        finally:
            lock.release()