def __load_feeds(self):
        """Load Feeds."""

        for feed in Session().query(TblFeed).all():

            RUNTIME.feeds[feed.feed_id] = Feed(feed.feed_id)
            RUNTIME.feeds[feed.feed_id].created = feed.created
            RUNTIME.feeds[feed.feed_id].updated = feed.updated

            if feed.pnfdev_addr:

                pnfdev = Session().query(TblPNFDev) \
                    .filter(TblPNFDev.addr == EtherAddress(feed.pnfdev_addr)) \
                    .first()

                if pnfdev:

                    pnfdevs = getattr(RUNTIME, pnfdev.tbl_type)

                    RUNTIME.feeds[feed.feed_id].pnfdev = \
                        pnfdevs[feed.pnfdev_addr]
                    pnfdev = pnfdevs[feed.pnfdev_addr]
                    pnfdev.feed = RUNTIME.feeds[feed.feed_id]

                else:

                    session = Session()
                    delete = Session().query(TblFeed) \
                        .filter(TblFeed.feed_id == feed.feed_id) \
                        .first()
                    delete.pnfdev = None
                    session.commit()

        query = Session().query(
            TblFeed, func.max(TblFeed.feed_id).label("max_id"))

        if query.one().max_id:
            self.feed_id = int(query.one().max_id)
Exemple #2
0
    def __load_feeds(self):
        """Load Feeds."""

        for feed in Session().query(TblFeed).all():

            RUNTIME.feeds[feed.feed_id] = Feed(feed.feed_id)
            RUNTIME.feeds[feed.feed_id].created = feed.created
            RUNTIME.feeds[feed.feed_id].updated = feed.updated

            if feed.addr:

                pnfdev = Session().query(TblPNFDev) \
                    .filter(TblPNFDev.addr == EtherAddress(feed.addr)) \
                    .first()

                if pnfdev:

                    pnfdevs = getattr(RUNTIME, pnfdev.tbl_type)

                    RUNTIME.feeds[feed.feed_id].pnfdev = \
                        pnfdevs[feed.addr]
                    pnfdev = pnfdevs[feed.addr]
                    pnfdev.feed = RUNTIME.feeds[feed.feed_id]

                else:

                    session = Session()
                    delete = Session().query(TblFeed) \
                        .filter(TblFeed.feed_id == feed.feed_id) \
                        .first()
                    delete.pnfdev = None
                    session.commit()

        query = Session().query(TblFeed,
                                func.max(TblFeed.feed_id).label("max_id"))

        if query.one().max_id:
            self.feed_id = int(query.one().max_id)
    def bind_feed(self, feed_id, pnfdev_addr=None):
        """Bind Feed to PNFDev."""

        if feed_id not in RUNTIME.feeds:
            raise KeyError(feed_id)

        feed = RUNTIME.feeds[feed_id]

        # if the feed is pointing to a dev, then reset the feed attribute of
        # that dev to None
        if feed.pnfdev:

            pnfdev = Session().query(TblPNFDev) \
                .filter(TblPNFDev.addr == EtherAddress(feed.pnfdev.addr)) \
                .first()

            if pnfdev:
                pnfdevs = getattr(RUNTIME, pnfdev.tbl_type)
                pnfdevs[feed.pnfdev.addr].feed = None

        # reset fedd pnfdev attribute to none
        feed.pnfdev = None

        # set the new pnfdev
        if pnfdev_addr:

            pnfdev = Session().query(TblPNFDev) \
                .filter(TblPNFDev.addr == EtherAddress(pnfdev_addr)) \
                .first()

            if not pnfdev:
                raise KeyError(pnfdev_addr)

            pnfdevs = getattr(RUNTIME, pnfdev.tbl_type)

            pnfdev = pnfdevs[pnfdev_addr]
            feed.pnfdev = pnfdev
            pnfdev.feed = feed
Exemple #4
0
    def bind_feed(self, feed_id, addr=None):
        """Bind Feed to PNFDev."""

        if feed_id not in RUNTIME.feeds:
            raise KeyError(feed_id)

        feed = RUNTIME.feeds[feed_id]

        # if the feed is pointing to a dev, then reset the feed attribute of
        # that dev to None
        if feed.pnfdev:

            pnfdev = Session().query(TblPNFDev) \
                .filter(TblPNFDev.addr == EtherAddress(feed.pnfdev.addr)) \
                .first()

            if pnfdev:
                pnfdevs = getattr(RUNTIME, pnfdev.tbl_type)
                pnfdevs[feed.pnfdev.addr].feed = None

        # reset fedd pnfdev attribute to none
        feed.pnfdev = None

        # set the new pnfdev
        if addr:

            pnfdev = Session().query(TblPNFDev) \
                .filter(TblPNFDev.addr == EtherAddress(addr)) \
                .first()

            if not pnfdev:
                raise KeyError(addr)

            pnfdevs = getattr(RUNTIME, pnfdev.tbl_type)

            pnfdev = pnfdevs[addr]
            feed.pnfdev = pnfdev
            pnfdev.feed = feed