def _delete_nat(self, context, fip):
        if not fip['router_id'] or not fip['fixed_ip_address']:
            LOG.debug('already deleted %s', fip)
            return
        tenant_id = nwa_l3_db.get_tenant_id_by_router(
            context.session, fip['router_id']
        )
        nwa_tenant_id = nwa_com_utils.get_nwa_tenant_id(tenant_id)

        fl_data = {
            'floating_ip_address': fip['floating_ip_address'],
            'fixed_ip_address': fip['fixed_ip_address'],
            'id': fip['id'],
            'device_id': fip['router_id'],
            'floating_network_id': fip['floating_network_id'],
            'tenant_id': fip['tenant_id']
        }
        LOG.info(_LI('delete_nat fl_data=%s'), fl_data)

        proxy = self._get_nwa_proxy(self, tenant_id)
        proxy.delete_nat(
            context, tenant_id=tenant_id,
            nwa_tenant_id=nwa_tenant_id,
            floating=fl_data
        )
    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)
Exemple #3
0
 def _make_l3api_kwargs(self, context):
     rt_tid = nwa_l3_db.get_tenant_id_by_router(
         context.network._plugin_context.session,
         context._port['device_id'])
     nwa_rt_tid = nwa_com_utils.get_nwa_tenant_id(rt_tid)
     nwa_info = nwa_l2_utils.portcontext_to_nwa_info(
         context, self.resource_groups)
     nwa_info['tenant_id'] = rt_tid  # overwrite by router's
     nwa_info['nwa_tenant_id'] = nwa_rt_tid  # tenant_id and nwa_tenant_id
     return {
         'tenant_id': rt_tid,
         'nwa_tenant_id': nwa_rt_tid,
         'nwa_info': nwa_info
     }
 def _make_l3api_kwargs(self, context):
     rt_tid = nwa_l3_db.get_tenant_id_by_router(
         context.network._plugin_context.session,
         context._port['device_id']
     )
     nwa_rt_tid = nwa_com_utils.get_nwa_tenant_id(rt_tid)
     nwa_info = nwa_l2_utils.portcontext_to_nwa_info(
         context, self.resource_groups)
     nwa_info['tenant_id'] = rt_tid           # overwrite by router's
     nwa_info['nwa_tenant_id'] = nwa_rt_tid   # tenant_id and nwa_tenant_id
     return {
         'tenant_id': rt_tid,
         'nwa_tenant_id': nwa_rt_tid,
         'nwa_info': nwa_info
     }
    def update_floatingip(self, context, fpid, floatingip):
        port_id_specified = 'port_id' in floatingip['floatingip']
        if not port_id_specified:
            LOG.error(_LE("port_id key is not found in %s"), floatingip)
            raise exc.PortNotFound(port_id=None)

        port_id = floatingip['floatingip'].get('port_id')
        try:
            if port_id_specified and not port_id:
                floating = context.session.query(l3_db.FloatingIP).filter_by(
                    id=fpid).one()
                self._delete_nat(context, floating)
        except sa.orm.exc.NoResultFound:
            raise exc.PortNotFound(port_id=port_id)

        ret = super(NECNWAL3Plugin, self).update_floatingip(
            context, fpid, floatingip)

        try:
            if port_id_specified and port_id:
                floating = context.session.query(l3_db.FloatingIP).filter_by(
                    id=fpid).one()
                tenant_id = nwa_l3_db.get_tenant_id_by_router(
                    context.session,
                    floating['router_id']
                )
                nwa_tenant_id = nwa_com_utils.get_nwa_tenant_id(tenant_id)

                fl_data = {
                    'floating_ip_address': floating['floating_ip_address'],
                    'fixed_ip_address': floating['fixed_ip_address'],
                    'id': fpid, 'device_id': floating['router_id'],
                    'floating_network_id': floating['floating_network_id'],
                    'tenant_id': floating['tenant_id'],
                    'floating_port_id': floating['floating_port_id']
                }
                LOG.info(_LI('setting_nat fl_data is %s'), fl_data)
                proxy = self._get_nwa_proxy(self, tenant_id)
                proxy.setting_nat(
                    context, tenant_id=tenant_id,
                    nwa_tenant_id=nwa_tenant_id,
                    floating=fl_data
                )

        except sa.orm.exc.NoResultFound:
            raise exc.PortNotFound(port_id=port_id)

        return ret