コード例 #1
0
    def _add_router_interface_by_port(self, plugin, context, router_id,
                                      interface_info):
        try:
            session = context.session
            port = plugin._core_plugin._get_port(context,
                                                 interface_info['port_id'])
            network = plugin._core_plugin.get_network(context,
                                                      port['network_id'])

            binding = nwa_db.ensure_port_binding(session, port['id'])
            port_context = driver_context.PortContext(plugin._core_plugin,
                                                      context, port,
                                                      network, binding, None)

            nwa_info = nwa_l2_utils.portcontext_to_nwa_info(
                port_context, self.resource_groups)
            rt_tid = nwa_l3_db.get_tenant_id_by_router(
                session, router_id
            )
            nwa_rt_tid = nwa_com_utils.get_nwa_tenant_id(rt_tid)
            nwa_info['tenant_id'] = rt_tid
            nwa_info['nwa_tenant_id'] = nwa_rt_tid
            proxy = self._get_nwa_proxy(plugin, rt_tid)
            proxy.create_tenant_fw(
                port_context.network._plugin_context,
                rt_tid,
                nwa_rt_tid,
                nwa_info
            )

        except Exception as e:
            LOG.exception(_LE("create tenant firewall %s"), e)
コード例 #2
0
 def test_ensure_port_binding(self):
     port_id = 'uuid-port_id-1'
     self.session.query().filter_by().one.return_value = port_id
     rc = db_api.ensure_port_binding(self.session, port_id)
     self.assertEqual(rc, port_id)
コード例 #3
0
    def _get_device_details(self, rpc_context, **kwargs):
        """Agent requests device details."""
        agent_id = kwargs.get('agent_id')
        device = kwargs.get('device')
        host = kwargs.get('host')
        LOG.debug(
            "Device %(device)s details requested by agent "
            "%(agent_id)s with host %(host)s", {
                'device': device,
                'agent_id': agent_id,
                'host': host
            })

        plugin = manager.NeutronManager.get_plugin()
        port_id = plugin._device_to_port_id(device)
        port_context = plugin.get_bound_port_context(rpc_context, port_id,
                                                     host)
        if not port_context:
            LOG.warning(
                _LW("Device %(device)s requested by agent "
                    "%(agent_id)s not found in database"), {
                        'device': device,
                        'agent_id': agent_id
                    })
            return {'device': device}

        port = port_context.current

        session = db_api.get_session()
        with session.begin(subtransactions=True):
            segments = db_ml2.get_network_segments(session,
                                                   port['network_id'],
                                                   filter_dynamic=True)
            if not segments:
                LOG.warning(
                    _LW("Device %(device)s requested by agent "
                        "%(agent_id)s has network %(network_id)s not "
                        "no segment"), {
                            'device': device,
                            'agent_id': agent_id,
                            'network_id': port['network_id']
                        })
                return {'device': device}
            elif len(segments) != 1:
                LOG.warning(
                    _LW("Device %(device)s requested by agent "
                        "%(agent_id)s has network %(network_id)s not "
                        "no segment size miss mach"), {
                            'device': device,
                            'agent_id': agent_id,
                            'network_id': port['network_id']
                        })
                return {'device': device}
            elif segments[0]['segmentation_id'] == 0:
                LOG.warning(
                    _LW("Device %(device)s requested by agent "
                        "%(agent_id)s, segment %(segment_id)s has "
                        "network %(network_id)s not "
                        "no segment from NWA"), {
                            'device': device,
                            'agent_id': agent_id,
                            'segment_id': segments[0]['id'],
                            'network_id': port['network_id']
                        })
                return {'device': device}

            binding = necnwa_api.ensure_port_binding(session, port_id)

            if not binding.segment_id:
                LOG.warning(
                    _LW("Device %(device)s requested by agent "
                        "%(agent_id)s on network %(network_id)s not "
                        "bound, vif_type: %(vif_type)s"), {
                            'device': device,
                            'agent_id': agent_id,
                            'network_id': port['network_id'],
                            'vif_type': binding.vif_type
                        })
                return {'device': device}

        port = port_context.current

        new_status = (constants.PORT_STATUS_BUILD if port['admin_state_up']
                      else constants.PORT_STATUS_DOWN)

        if (port['status'] != new_status
                and port['status'] != constants.PORT_STATUS_ACTIVE):
            plugin.update_port_status(rpc_context, port_id, new_status, host)

        entry = {
            'device': device,
            'network_id': port['network_id'],
            'port_id': port_id,
            'mac_address': port['mac_address'],
            'admin_state_up': port['admin_state_up'],
            'network_type': segments[0]['network_type'],
            'segmentation_id': segments[0]['segmentation_id'],
            'physical_network': segments[0]['physical_network'],
            'fixed_ips': port['fixed_ips'],
            'device_owner': port['device_owner'],
            'profile': port[portbindings.PROFILE]
        }
        LOG.debug("Returning: %s", entry)
        return entry
コード例 #4
0
 def test_ensure_port_binding(self):
     port_id = 'uuid-port_id-1'
     self.session.query().filter_by().one.return_value = port_id
     rc = db_api.ensure_port_binding(self.session, port_id)
     self.assertEqual(rc, port_id)
コード例 #5
0
    def _get_device_details(self, rpc_context, **kwargs):
        """Agent requests device details."""
        agent_id = kwargs.get('agent_id')
        device = kwargs.get('device')
        host = kwargs.get('host')
        LOG.debug("Device %(device)s details requested by agent "
                  "%(agent_id)s with host %(host)s",
                  {'device': device, 'agent_id': agent_id, 'host': host})

        plugin = manager.NeutronManager.get_plugin()
        port_id = plugin._device_to_port_id(device)
        port_context = plugin.get_bound_port_context(rpc_context,
                                                     port_id,
                                                     host)
        if not port_context:
            LOG.warning(_LW("Device %(device)s requested by agent "
                            "%(agent_id)s not found in database"),
                        {'device': device, 'agent_id': agent_id})
            return {'device': device}

        port = port_context.current

        session = db_api.get_session()
        with session.begin(subtransactions=True):
            segments = db_ml2.get_network_segments(session, port['network_id'],
                                                   filter_dynamic=True)
            if not segments:
                LOG.warning(_LW("Device %(device)s requested by agent "
                                "%(agent_id)s has network %(network_id)s not "
                                "no segment"),
                            {'device': device, 'agent_id': agent_id,
                             'network_id': port['network_id']})
                return {'device': device}
            elif len(segments) != 1:
                LOG.warning(_LW("Device %(device)s requested by agent "
                                "%(agent_id)s has network %(network_id)s not "
                                "no segment size miss mach"),
                            {'device': device, 'agent_id': agent_id,
                             'network_id': port['network_id']})
                return {'device': device}
            elif segments[0]['segmentation_id'] == 0:
                LOG.warning(_LW("Device %(device)s requested by agent "
                                "%(agent_id)s, segment %(segment_id)s has "
                                "network %(network_id)s not "
                                "no segment from NWA"),
                            {'device': device, 'agent_id': agent_id,
                             'segment_id': segments[0]['id'],
                             'network_id': port['network_id']})
                return {'device': device}

            binding = necnwa_api.ensure_port_binding(session, port_id)

            if not binding.segment_id:
                LOG.warning(_LW("Device %(device)s requested by agent "
                                "%(agent_id)s on network %(network_id)s not "
                                "bound, vif_type: %(vif_type)s"),
                            {'device': device,
                             'agent_id': agent_id,
                             'network_id': port['network_id'],
                             'vif_type': binding.vif_type})
                return {'device': device}

        port = port_context.current

        new_status = (constants.PORT_STATUS_BUILD if port['admin_state_up']
                      else constants.PORT_STATUS_DOWN)

        if (
                port['status'] != new_status and
                port['status'] != constants.PORT_STATUS_ACTIVE
        ):
            plugin.update_port_status(rpc_context,
                                      port_id,
                                      new_status,
                                      host)

        entry = {'device': device,
                 'network_id': port['network_id'],
                 'port_id': port_id,
                 'mac_address': port['mac_address'],
                 'admin_state_up': port['admin_state_up'],
                 'network_type': segments[0]['network_type'],
                 'segmentation_id': segments[0]['segmentation_id'],
                 'physical_network': segments[0]['physical_network'],
                 'fixed_ips': port['fixed_ips'],
                 'device_owner': port['device_owner'],
                 'profile': port[portbindings.PROFILE]}
        LOG.debug("Returning: %s", entry)
        return entry