コード例 #1
0
class UEDAO(ABSDao):
    """
    UE DAO abstraction to create LTE messages.
    """
    TABLE = TABLE = DBLoader().get_table(ABSDao.DATABASE_NAME.get('ue'))
    CLASS = DBLoader().get_base_class(ABSDao.DATABASE_NAME.get('ue'))

    EVENT_TYPE = 'ue_event'
    INNER_OBJ = 'ue'
    DB_MAP = dict(imsi='IMSI',
                  mcc='MCC',
                  mnc='MNC',
                  ueid='UEId',
                  mme_teid_s11='mmeTeidS11',
                  sgw_teid_s11='sgwTeidS11',
                  eps_bearer_id='epsBearerId',
                  mme_ip='MMEIp',
                  sgw_teid_s1='sgwTeidS1',
                  enb_teid_s1u='enbTeidS1u',
                  sgw_ip_s1u='sgwIPS1U',
                  enb_ip_s1u='enbIPS1U',
                  ue_ip='UEIP')

    @classmethod
    def __create_message__(cls, row):
        """
        Override create message method, since no state is saved on the DB, it must be looked under each attribute set.
        :param row: The DB row to transform in real time message.
        :return: Real time message in dict format
        """
        message = super(UEDAO, cls).__create_message__(
            row)  # Uses the super method to create message bases
        message['type'] = 'UPDATE' if 'ue_ip' in list(
            message.get(UEDAO.INNER_OBJ).keys()) else 'CREATE'
        return message
コード例 #2
0
ファイル: virtual.py プロジェクト: Selfnet-5G/NBI
class VMNetworkDAO(ABSDao):
    """
    VM Network DAO abstraction to create each VM network.
    """
    TABLE = DBLoader().get_table(ABSDao.DATABASE_NAME.get('vm_network'))
    CLASS = DBLoader().get_base_class(ABSDao.DATABASE_NAME.get('vm_network'))

    DB_MAP = dict(mac='mac',
                  iface='iface',
                  dhcp='dhcp',
                  gateway='gateway',
                  dns='dns',
                  ip='vmIp',
                  network_id='networkId',
                  port_id='portId',
                  ovs_id='ovsId',
                  segmentation_id='segmentationId',
                  network_reported_time='reportedTime',
                  network_resource_id='resourceId')

    @staticmethod
    def __create_message__(row):
        """
        Override create message method, since no state, inner object or event type are needed FOR NOW.
        :param row:
        :return:
        """
        network = dict()
        for key, value in VMNetworkDAO.DB_MAP.items():
            network[key] = row.pop(value, None)
        return VMNetworkDAO.__clean_dict__(network)

    def __init__(self, session, vm):
        """
        Overrides ABS init because each Network needs to be related to a VM.
        :param session: The DB connection to use in the queries.
        :param vm: The VM the networks will relate to
        """
        super().__init__(session)
        self.vm = vm

    def snapshot(self):
        """
        Override the parent method since it needs to support the instance id of . However paren'ts method is used
        to create the bases of the snapshot.
        :return: dict with queried type messages
        """
        rows = self.query_by_filer(
            VirtualMachineDAO.DB_MAP.get(
                VirtualMachineDAO.DB_MAP.get(VirtualMachineDAO.FOREIGN_KEY)),
            self.vm)
        self.rows = list()
        for row in rows:
            self.rows.append(dict(zip(VMNetworkDAO.TABLE.columns.keys(), row)))
        return [VMNetworkDAO.__create_message__(row) for row in self.rows]
コード例 #3
0
ファイル: physical.py プロジェクト: Selfnet-5G/NBI
class PhysicalDAO(ABSDao):
    """
    Physical DAO abstraction to create physical machine messages.
    """
    TABLE = DBLoader().get_table(ABSDao.DATABASE_NAME.get('physical_machine'))
    CLASS = DBLoader().get_base_class(
        ABSDao.DATABASE_NAME.get('physical_machine'))

    EVENT_TYPE = 'compute_event'
    INNER_OBJ = 'compute_node'
    DB_MAP = dict(hostname='hostname',
                  location='location',
                  ip='ip',
                  network_id='networkId')
コード例 #4
0
ファイル: topology.py プロジェクト: Selfnet-5G/NBI
 def get_topology():
     """
     Creates the current topology.
     If topology dict is empty it queries the DB otherwise it will be returned as is.
     Because object references are used, a copy of the topology is sent in case the object is being read by a
     client and invalidated during the operation,
     allowing the client to keep the messages and receive the new ones only.
     :return: A dict with the current topology.
     """
     DBLoader().get_table('pm')
     return Topology.__load_topology__()
コード例 #5
0
ファイル: virtual.py プロジェクト: Selfnet-5G/NBI
class VirtualMachineDAO(ABSDao):
    """
    Virtual DAO abstraction to create physical machine messages.
    This class also creates the messages based on each network.
    """
    TABLE = DBLoader().get_table(ABSDao.DATABASE_NAME.get('virtual_machine'))
    CLASS = DBLoader().get_base_class(
        ABSDao.DATABASE_NAME.get('virtual_machine'))

    EVENT_TYPE = 'instance_event'
    FOREIGN_KEY = 'uuid'
    INNER_OBJ = 'vm'
    DB_MAP = dict(
        location='location',
        name='name',
        tenant_id='tenantId',
        user_id='userId',
        hostname='hostName',
        host_ip='hostIp',
        instance_id='instanceId',
        uuid='uuid',
        image_id='imageId',
        reported_time='reportedTime',
        resource_id='resourceId',
    )

    def snapshot(self):
        """
        Override the parent method since it needs to support the inclusion of networks. However paren'ts method is used
        to create the bases of the snapshot.
        :return: dict with queried type messages
        """
        snapshot = super(VirtualMachineDAO, self).snapshot()
        for entry in snapshot:
            vm = entry.get(VirtualMachineDAO.INNER_OBJ)
            vm['network'] = VMNetworkDAO(
                self.session,
                vm.get(VirtualMachineDAO.FOREIGN_KEY)).snapshot()
        return snapshot
コード例 #6
0
ファイル: topology.py プロジェクト: Selfnet-5G/NBI
 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()
コード例 #7
0
ファイル: topology.py プロジェクト: Selfnet-5G/NBI
 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()
コード例 #8
0
ファイル: topology.py プロジェクト: Selfnet-5G/NBI
 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()
コード例 #9
0
ファイル: topology.py プロジェクト: Selfnet-5G/NBI
 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