Example #1
0
    def update_ports(self, rpc_context, **kwargs):
        """Update ports' information and activate/deavtivate them.

        Expected input format is:
            {'topic': 'q-agent-notifier',
             'agent_id': 'nec-q-agent.' + <hostname>,
             'datapath_id': <datapath_id of br-int on remote host>,
             'port_added': [<new PortInfo>,...],
             'port_removed': [<removed Port ID>,...]}
        """
        LOG.debug(_("NECPluginV2RPCCallbacks.update_ports() called, "
                    "kwargs=%s ."), kwargs)
        topic = kwargs['topic']
        datapath_id = kwargs['datapath_id']
        session = rpc_context.session
        for p in kwargs.get('port_added', []):
            id = p['id']
            port = self.plugin.get_port(rpc_context, id)
            if port and ndb.get_portinfo(session, id):
                ndb.del_portinfo(session, id)
                self.plugin.deactivate_port(rpc_context, port)
            ndb.add_portinfo(session, id, datapath_id, p['port_no'],
                             mac=p.get('mac', ''))
            self.plugin.activate_port_if_ready(rpc_context, port)
        for id in kwargs.get('port_removed', []):
            port = self.plugin.get_port(rpc_context, id)
            if port and ndb.get_portinfo(session, id):
                ndb.del_portinfo(session, id)
                self.plugin.deactivate_port(rpc_context, port)
Example #2
0
    def update_ports(self, rpc_context, **kwargs):
        """Update ports' information and activate/deavtivate them.

        Expected input format is:
            {'topic': 'q-agent-notifier',
             'agent_id': 'nec-q-agent.' + <hostname>,
             'datapath_id': <datapath_id of br-int on remote host>,
             'port_added': [<new PortInfo>,...],
             'port_removed': [<removed Port ID>,...]}
        """
        LOG.debug("NECPluginV2RPCCallbacks.update_ports() called, "
                  "kwargs=%s ." % kwargs)
        topic = kwargs['topic']
        datapath_id = kwargs['datapath_id']
        for p in kwargs.get('port_added', []):
            id = p['id']
            port = self.plugin.get_port(self.admin_context, id)
            if port and ndb.get_portinfo(id):
                ndb.del_portinfo(id)
                self.plugin.deactivate_port(self.admin_context, port)
            ndb.add_portinfo(id, datapath_id, p['port_no'],
                             mac=p.get('mac', ''))
            self.plugin.activate_port_if_ready(self.admin_context, port)
        for id in kwargs.get('port_removed', []):
            port = self.plugin.get_port(self.admin_context, id)
            if port and ndb.get_portinfo(id):
                ndb.del_portinfo(id)
                self.plugin.deactivate_port(self.admin_context, port)
Example #3
0
 def testf_del_portinfo(self):
     """test delete portinfo"""
     i, d, p, v, m, n = self.get_portinfo_random_params()
     ndb.add_portinfo(self.session, i, d, p, v, m)
     portinfo = ndb.get_portinfo(self.session, i)
     self.assertEqual(portinfo.id, i)
     ndb.del_portinfo(self.session, i)
     portinfo_none = ndb.get_portinfo(self.session, i)
     self.assertEqual(None, portinfo_none)
Example #4
0
 def testf_del_portinfo(self):
     """test delete portinfo"""
     i, d, p, v, m, n = self.get_portinfo_random_params()
     ndb.add_portinfo(i, d, p, v, m)
     portinfo = ndb.get_portinfo(i)
     self.assertEqual(portinfo.id, i)
     ndb.del_portinfo(i)
     portinfo_none = ndb.get_portinfo(i)
     self.assertEqual(None, portinfo_none)
Example #5
0
    def update_ports(self, rpc_context, **kwargs):
        """Update ports' information and activate/deavtivate them.

        Expected input format is:
            {'topic': 'q-agent-notifier',
             'agent_id': 'nec-q-agent.' + <hostname>,
             'datapath_id': <datapath_id of br-int on remote host>,
             'port_added': [<new PortInfo>,...],
             'port_removed': [<removed Port ID>,...]}
        """
        LOG.debug(
            _("NECPluginV2RPCCallbacks.update_ports() called, "
              "kwargs=%s ."), kwargs)
        datapath_id = kwargs['datapath_id']
        session = rpc_context.session
        for p in kwargs.get('port_added', []):
            id = p['id']
            portinfo = ndb.get_portinfo(session, id)
            if portinfo:
                ndb.del_portinfo(session, id)
            ndb.add_portinfo(session,
                             id,
                             datapath_id,
                             p['port_no'],
                             mac=p.get('mac', ''))
            port = self._get_port(rpc_context, id)
            if port:
                if portinfo:
                    self.plugin.deactivate_port(rpc_context, port)
                self.plugin.activate_port_if_ready(rpc_context, port)
        for id in kwargs.get('port_removed', []):
            portinfo = ndb.get_portinfo(session, id)
            if not portinfo:
                LOG.debug(
                    _("update_ports(): ignore port_removed message "
                      "due to portinfo for port_id=%s was not "
                      "registered"), id)
                continue
            if portinfo.datapath_id != datapath_id:
                LOG.debug(
                    _("update_ports(): ignore port_removed message "
                      "received from different host "
                      "(registered_datapath_id=%(registered)s, "
                      "received_datapath_id=%(received)s)."), {
                          'registered': portinfo.datapath_id,
                          'received': datapath_id
                      })
                continue
            ndb.del_portinfo(session, id)
            port = self._get_port(rpc_context, id)
            if port:
                self.plugin.deactivate_port(rpc_context, port)
Example #6
0
    def update_ports(self, rpc_context, **kwargs):
        """Update ports' information and activate/deavtivate them.

        Expected input format is:
            {'topic': 'q-agent-notifier',
             'agent_id': 'nec-q-agent.' + <hostname>,
             'datapath_id': <datapath_id of br-int on remote host>,
             'port_added': [<new PortInfo>,...],
             'port_removed': [<removed Port ID>,...]}
        """
        LOG.debug(_("NECPluginV2RPCCallbacks.update_ports() called, " "kwargs=%s ."), kwargs)
        datapath_id = kwargs["datapath_id"]
        session = rpc_context.session
        for p in kwargs.get("port_added", []):
            id = p["id"]
            portinfo = ndb.get_portinfo(session, id)
            if portinfo:
                ndb.del_portinfo(session, id)
            ndb.add_portinfo(session, id, datapath_id, p["port_no"], mac=p.get("mac", ""))
            port = self._get_port(rpc_context, id)
            if port:
                if portinfo:
                    self.plugin.deactivate_port(rpc_context, port)
                self.plugin.activate_port_if_ready(rpc_context, port)
        for id in kwargs.get("port_removed", []):
            portinfo = ndb.get_portinfo(session, id)
            if not portinfo:
                LOG.debug(
                    _(
                        "update_ports(): ignore port_removed message "
                        "due to portinfo for port_id=%s was not "
                        "registered"
                    ),
                    id,
                )
                continue
            if portinfo.datapath_id != datapath_id:
                LOG.debug(
                    _(
                        "update_ports(): ignore port_removed message "
                        "received from different host "
                        "(registered_datapath_id=%(registered)s, "
                        "received_datapath_id=%(received)s)."
                    ),
                    {"registered": portinfo.datapath_id, "received": datapath_id},
                )
                continue
            ndb.del_portinfo(session, id)
            port = self._get_port(rpc_context, id)
            if port:
                self.plugin.deactivate_port(rpc_context, port)