コード例 #1
0
ファイル: nec_plugin.py プロジェクト: fyafighter/neutron
    def _process_portbindings_portinfo_update(self, context, port_data, port):
        """Update portinfo according to bindings:profile in update_port().

        :param context: neutron api request context
        :param port_data: port attributes passed in PUT request
        :param port: port attributes to be returned
        :returns: 'ADD', 'MOD', 'DEL' or None
        """
        if portbindings.PROFILE not in port_data:
            return
        profile = port_data.get(portbindings.PROFILE)
        # If binding:profile is None or an empty dict,
        # it means binding:.profile needs to be cleared.
        # TODO(amotoki): Allow Make None in binding:profile in
        # the API layer. See LP bug #1220011.
        profile_set = attrs.is_attr_set(profile) and profile
        cur_portinfo = ndb.get_portinfo(context.session, port['id'])
        if profile_set:
            portinfo = self._validate_portinfo(profile)
            portinfo_changed = 'ADD'
            if cur_portinfo:
                if (portinfo['datapath_id'] == cur_portinfo.datapath_id and
                    portinfo['port_no'] == cur_portinfo.port_no):
                    return
                ndb.del_portinfo(context.session, port['id'])
                portinfo_changed = 'MOD'
            portinfo['mac'] = port['mac_address']
            ndb.add_portinfo(context.session, port['id'], **portinfo)
        elif cur_portinfo:
            portinfo_changed = 'DEL'
            portinfo = None
            ndb.del_portinfo(context.session, port['id'])
        self._extend_port_dict_binding_portinfo(port, portinfo)
        return portinfo_changed
コード例 #2
0
    def _process_portbindings_portinfo_update(self, context, port_data, port):
        """Update portinfo according to bindings:profile in update_port().

        :param context: neutron api request context
        :param port_data: port attributes passed in PUT request
        :param port: port attributes to be returned
        :returns: 'ADD', 'MOD', 'DEL' or None
        """
        if portbindings.PROFILE not in port_data:
            return
        profile = port_data.get(portbindings.PROFILE)
        # If binding:profile is None or an empty dict,
        # it means binding:.profile needs to be cleared.
        # TODO(amotoki): Allow Make None in binding:profile in
        # the API layer. See LP bug #1220011.
        profile_set = attrs.is_attr_set(profile) and profile
        cur_portinfo = ndb.get_portinfo(context.session, port['id'])
        if profile_set:
            portinfo = self._validate_portinfo(profile)
            portinfo_changed = 'ADD'
            if cur_portinfo:
                if (portinfo['datapath_id'] == cur_portinfo.datapath_id
                        and portinfo['port_no'] == cur_portinfo.port_no):
                    return
                ndb.del_portinfo(context.session, port['id'])
                portinfo_changed = 'MOD'
            portinfo['mac'] = port['mac_address']
            ndb.add_portinfo(context.session, port['id'], **portinfo)
        elif cur_portinfo:
            portinfo_changed = 'DEL'
            portinfo = None
            ndb.del_portinfo(context.session, port['id'])
        self._extend_port_dict_binding_portinfo(port, portinfo)
        return portinfo_changed
コード例 #3
0
ファイル: nec_plugin.py プロジェクト: raceli/neutron
    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:
                if necutils.cmp_dpid(portinfo.datapath_id, datapath_id) and portinfo.port_no == p["port_no"]:
                    LOG.debug(_("update_ports(): ignore unchanged portinfo in " "port_added message (port_id=%s)."), id)
                    continue
                ndb.del_portinfo(session, id)
            port = self._get_port(rpc_context, id)
            if port:
                ndb.add_portinfo(session, id, datapath_id, p["port_no"], mac=p.get("mac", ""))
                # NOTE: Make sure that packet filters on this port exist while
                # the port is active to avoid unexpected packet transfer.
                if portinfo:
                    self.plugin.deactivate_port(rpc_context, port)
                    self.plugin.deactivate_packet_filters_by_port(rpc_context, id)
                self.plugin.activate_packet_filters_by_port(rpc_context, id)
                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 not necutils.cmp_dpid(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)
                self.plugin.deactivate_packet_filters_by_port(rpc_context, id)
コード例 #4
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:
                if (necutils.cmp_dpid(portinfo.datapath_id, datapath_id) and
                    portinfo.port_no == p['port_no']):
                    LOG.debug(_("update_ports(): ignore unchanged portinfo in "
                                "port_added message (port_id=%s)."), id)
                    continue
                ndb.del_portinfo(session, id)
            port = self._get_port(rpc_context, id)
            if port:
                ndb.add_portinfo(session, id, datapath_id, p['port_no'],
                                 mac=p.get('mac', ''))
                # NOTE: Make sure that packet filters on this port exist while
                # the port is active to avoid unexpected packet transfer.
                if portinfo:
                    self.plugin.deactivate_port(rpc_context, port,
                                                raise_exc=False)
                    self.plugin.deactivate_packet_filters_by_port(
                        rpc_context, id, raise_exc=False)
                self.plugin.activate_packet_filters_by_port(rpc_context, id)
                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 not necutils.cmp_dpid(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, raise_exc=False)
                self.plugin.deactivate_packet_filters_by_port(
                    rpc_context, id, raise_exc=False)
コード例 #5
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)
コード例 #6
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)
コード例 #7
0
 def testh_exists_ofc_port(self):
     """test exists_ofc_port."""
     t, n, p, f, none = self.get_random_params()
     self.ofc.create_ofc_tenant(self.ctx, t)
     self.ofc.create_ofc_network(self.ctx, t, n)
     ndb.add_portinfo(self.ctx.session, p, "0xabc", 2, 65535,
                      "00:12:22:33:44:55")
     self.assertFalse(self.ofc.exists_ofc_port(self.ctx, p))
     port = {'tenant_id': t, 'network_id': n}
     self.ofc.create_ofc_port(self.ctx, p, port)
     self.assertTrue(self.ofc.exists_ofc_port(self.ctx, p))
コード例 #8
0
 def testh_exists_ofc_port(self):
     """test exists_ofc_port."""
     t, n, p, f, none = self.get_random_params()
     self.ofc.create_ofc_tenant(self.ctx, t)
     self.ofc.create_ofc_network(self.ctx, t, n)
     ndb.add_portinfo(self.ctx.session, p, "0xabc", 2, 65535,
                      "00:12:22:33:44:55")
     self.assertFalse(self.ofc.exists_ofc_port(self.ctx, p))
     port = {'tenant_id': t, 'network_id': n}
     self.ofc.create_ofc_port(self.ctx, p, port)
     self.assertTrue(self.ofc.exists_ofc_port(self.ctx, p))
コード例 #9
0
 def testi_delete_ofc_port(self):
     """test delete ofc_port."""
     t, n, p, f, none = self.get_random_params()
     self.ofc.create_ofc_tenant(self.ctx, t)
     self.ofc.create_ofc_network(self.ctx, t, n)
     ndb.add_portinfo(self.ctx.session, p, "0xabc", 3, 65535,
                      "00:13:22:33:44:55")
     port = {'tenant_id': t, 'network_id': n}
     self.ofc.create_ofc_port(self.ctx, p, port)
     self.assertTrue(ndb.get_ofc_item(self.ctx.session, 'ofc_port', p))
     self.ofc.delete_ofc_port(self.ctx, p, port)
     self.assertFalse(ndb.get_ofc_item(self.ctx.session, 'ofc_port', p))
コード例 #10
0
 def testi_delete_ofc_port(self):
     """test delete ofc_port."""
     t, n, p, f, none = self.get_random_params()
     self.ofc.create_ofc_tenant(self.ctx, t)
     self.ofc.create_ofc_network(self.ctx, t, n)
     ndb.add_portinfo(self.ctx.session, p, "0xabc", 3, 65535,
                      "00:13:22:33:44:55")
     port = {'tenant_id': t, 'network_id': n}
     self.ofc.create_ofc_port(self.ctx, p, port)
     self.assertTrue(ndb.get_ofc_item(self.ctx.session, 'ofc_port', p))
     self.ofc.delete_ofc_port(self.ctx, p, port)
     self.assertFalse(ndb.get_ofc_item(self.ctx.session, 'ofc_port', p))
コード例 #11
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)
コード例 #12
0
 def testg_create_ofc_port(self):
     """test create ofc_port."""
     t, n, p, f, none = self.get_random_params()
     self.ofc.create_ofc_tenant(self.ctx, t)
     self.ofc.create_ofc_network(self.ctx, t, n)
     ndb.add_portinfo(self.ctx.session, p, "0xabc", 1, 65535,
                      "00:11:22:33:44:55")
     self.assertFalse(ndb.get_ofc_item(self.ctx.session, 'ofc_port', p))
     port = {'tenant_id': t, 'network_id': n}
     self.ofc.create_ofc_port(self.ctx, p, port)
     self.assertTrue(ndb.get_ofc_item(self.ctx.session, 'ofc_port', p))
     port = ndb.get_ofc_item(self.ctx.session, 'ofc_port', p)
     self.assertEqual(port.ofc_id, "ofc-" + p[:-4])
コード例 #13
0
    def teste_get_portinfo(self):
        """test get 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)
        self.assertEqual(portinfo.datapath_id, d)
        self.assertEqual(portinfo.port_no, p)
        self.assertEqual(portinfo.vlan_id, v)
        self.assertEqual(portinfo.mac, m)

        portinfo_none = ndb.get_portinfo(self.session, n)
        self.assertEqual(None, portinfo_none)
コード例 #14
0
 def testg_create_ofc_port(self):
     """test create ofc_port."""
     t, n, p, f, none = self.get_random_params()
     self.ofc.create_ofc_tenant(self.ctx, t)
     self.ofc.create_ofc_network(self.ctx, t, n)
     ndb.add_portinfo(self.ctx.session, p, "0xabc", 1, 65535,
                      "00:11:22:33:44:55")
     self.assertFalse(ndb.get_ofc_item(self.ctx.session, 'ofc_port', p))
     port = {'tenant_id': t, 'network_id': n}
     self.ofc.create_ofc_port(self.ctx, p, port)
     self.assertTrue(ndb.get_ofc_item(self.ctx.session, 'ofc_port', p))
     port = ndb.get_ofc_item(self.ctx.session, 'ofc_port', p)
     self.assertEqual(port.ofc_id, "ofc-" + p[:-4])
コード例 #15
0
    def teste_get_portinfo(self):
        """test get 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)
        self.assertEqual(portinfo.datapath_id, d)
        self.assertEqual(portinfo.port_no, p)
        self.assertEqual(portinfo.vlan_id, v)
        self.assertEqual(portinfo.mac, m)

        portinfo_none = ndb.get_portinfo(self.session, n)
        self.assertEqual(None, portinfo_none)
コード例 #16
0
    def testd_add_portinfo(self):
        """test add portinfo."""
        i, d, p, v, m, n = self.get_portinfo_random_params()
        portinfo = ndb.add_portinfo(self.session, i, d, p, v, m)
        self.assertEqual(portinfo.id, i)
        self.assertEqual(portinfo.datapath_id, d)
        self.assertEqual(portinfo.port_no, p)
        self.assertEqual(portinfo.vlan_id, v)
        self.assertEqual(portinfo.mac, m)

        exception_raised = False
        try:
            ndb.add_portinfo(self.session, i, d, p, v, m)
        except nexc.NECDBException:
            exception_raised = True
        self.assertTrue(exception_raised)
コード例 #17
0
    def testd_add_portinfo(self):
        """test add portinfo."""
        i, d, p, v, m, n = self.get_portinfo_random_params()
        portinfo = ndb.add_portinfo(self.session, i, d, p, v, m)
        self.assertEqual(portinfo.id, i)
        self.assertEqual(portinfo.datapath_id, d)
        self.assertEqual(portinfo.port_no, p)
        self.assertEqual(portinfo.vlan_id, v)
        self.assertEqual(portinfo.mac, m)

        exception_raised = False
        try:
            ndb.add_portinfo(self.session, i, d, p, v, m)
        except nexc.NECDBException:
            exception_raised = True
        self.assertTrue(exception_raised)
コード例 #18
0
ファイル: nec_plugin.py プロジェクト: matrohon/quantum
    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)
コード例 #19
0
ファイル: nec_plugin.py プロジェクト: ChengZuo/neutron
    def _process_portbindings_portinfo_create(self, context, port_data, port):
        """Add portinfo according to bindings:profile in create_port().

        :param context: neutron api request context
        :param port_data: port attributes passed in PUT request
        :param port: port attributes to be returned
        """
        profile = port_data.get(portbindings.PROFILE)
        # If portbindings.PROFILE is None, unspecified or an empty dict
        # it is regarded that portbinding.PROFILE is not set.
        profile_set = attrs.is_attr_set(profile) and profile
        if profile_set:
            portinfo = self._validate_portinfo(profile)
            portinfo['mac'] = port['mac_address']
            ndb.add_portinfo(context.session, port['id'], **portinfo)
        else:
            portinfo = None
        self._extend_port_dict_binding_portinfo(port, portinfo)
コード例 #20
0
ファイル: nec_plugin.py プロジェクト: userlocalhost/neutron
    def _process_portbindings_portinfo_create(self, context, port_data, port):
        """Add portinfo according to bindings:profile in create_port().

        :param context: neutron api request context
        :param port_data: port attributes passed in PUT request
        :param port: port attributes to be returned
        """
        profile = port_data.get(portbindings.PROFILE)
        # If portbindings.PROFILE is None, unspecified or an empty dict
        # it is regarded that portbinding.PROFILE is not set.
        profile_set = attrs.is_attr_set(profile) and profile
        if profile_set:
            portinfo = self._validate_portinfo(profile)
            portinfo['mac'] = port['mac_address']
            ndb.add_portinfo(context.session, port['id'], **portinfo)
        else:
            portinfo = None
        self._extend_port_dict_binding_portinfo(port, portinfo)
コード例 #21
0
ファイル: test_db.py プロジェクト: CiscoSystems/neutron
 def _add_portinfo(self, session, params):
     return ndb.add_portinfo(session, params['port_id'],
                             params['datapath_id'], params['port_no'],
                             params['vlan_id'], params['mac'])
コード例 #22
0
ファイル: test_db.py プロジェクト: nabilmaad/neutron
 def _add_portinfo(self, session, params):
     return ndb.add_portinfo(session, params['port_id'],
                             params['datapath_id'], params['port_no'],
                             params['vlan_id'], params['mac'])
コード例 #23
0
ファイル: test_db.py プロジェクト: B-Rich/neutron
 def _add_portinfo(self, session, params):
     return ndb.add_portinfo(
         session, params["port_id"], params["datapath_id"], params["port_no"], params["vlan_id"], params["mac"]
     )