def get_enb(self): session = DBLoader().create_session() try: enb_ = session.query(UEDAO.CLASS.enbIPS1U).distinct().all() enb = [] for ip in enb_: enb.append(ip[0]) return enb except Exception: session.rollback() raise finally: session.close()
def get_all_locations(self): session = DBLoader().create_session() try: locations_ = session.query( VirtualMachineDAO.CLASS.location).distinct().all() locations = [] for l in locations_: locations.append(l[0]) return locations except Exception: session.rollback() raise finally: session.close()
def __load_topology__(): """ Loads the topology into the dictionary. It uses the class mapping with the key to use and the DAO to obtain the snapshot. The topology must be saved in an ordered dict to send the messages as they were introduced in the system. :return: Ordered Dict with the topology. """ topology = OrderedDict() for key, obj in Topology.LOADER.items(): try: session = DBLoader().create_session() topology[key] = obj(session).snapshot() except Exception: session.rollback() raise finally: session.close() return topology
def query_by_multiple_filters(self, table, *filter_by, clean=True, **kwargs): session = DBLoader().create_session() try: objs = session.query(table).filter_by(**kwargs).all() response = [] for row in objs: r = dict(zip(table.columns.keys(), row)) if clean: self.__clean_filter__(r, table, *filter_by) response.append(r) return response except Exception: session.rollback() raise finally: session.close()