Exemplo n.º 1
0
 def remove_router_interface(self, context, router_id, interface_info):
     edge_id = edge_utils.get_router_edge_id(context, router_id)
     with locking.LockManager.get_lock(
             str(edge_id),
             lock_file_prefix=NSXV_ROUTER_RECONFIG,
             external=True):
         info = super(
             nsx_v.NsxVPluginV2, self.plugin).remove_router_interface(
                 context, router_id, interface_info)
         subnet = self.plugin.get_subnet(context, info['subnet_id'])
         network_id = subnet['network_id']
         router_ids = self.edge_manager.get_routers_on_same_edge(
             context, router_id)
         self._update_nat_rules_on_routers(context, router_id, router_ids)
         self._update_subnets_and_dnat_firewall_on_routers(
             context, router_id, router_ids, allow_external=True)
         ports = self.plugin._get_router_interface_ports_by_network(
             context, router_id, network_id)
         if not ports:
             edge_utils.delete_interface(self.nsx_v, context,
                                         router_id, network_id)
             # unbind all services if no interfaces attached to the router
             if not self.plugin._get_internal_network_ids_by_router(
                     context, router_id):
                 self._remove_router_services_on_edge(context, router_id)
                 self._unbind_router_on_edge(context, router_id)
         else:
             address_groups = self.plugin._get_address_groups(
                 context, router_id, network_id)
             edge_utils.update_internal_interface(
                 self.nsx_v, context, router_id, network_id, address_groups)
     return info
    def remove_router_interface(self, context, router_id, interface_info):
        info = super(nsx_v.NsxVPluginV2, self.plugin).remove_router_interface(
            context, router_id, interface_info)
        router_db = self.plugin._get_router(context, router_id)
        subnet = self.plugin.get_subnet(context, info['subnet_id'])
        network_id = subnet['network_id']
        if router_db.gw_port and router_db.enable_snat:
            plr_id = self.edge_manager.get_plr_by_tlr_id(
                context, router_id)
            self.plugin._update_nat_rules(context, router_db, plr_id)
            # Open firewall flows on plr
            self.plugin._update_subnets_and_dnat_firewall(
                context, router_db, router_id=plr_id)
            # Update static routes of plr
            nexthop = self.plugin._get_external_attachment_info(
                context, router_db)[2]
            self.update_routes(context, router_id, nexthop)

        ports = self.plugin._get_router_interface_ports_by_network(
            context, router_id, network_id)
        self.plugin._update_subnets_and_dnat_firewall(context, router_db)
        # No subnet on the network connects to the edge vnic
        if not ports:
            edge_utils.delete_interface(self.nsx_v, context,
                                        router_id, network_id,
                                        dist=True)
        else:
            address_groups = self.plugin._get_address_groups(
                context, router_id, network_id)
            edge_utils.update_vdr_internal_interface(
                self.nsx_v, context, router_id,
                network_id, address_groups)
        return info
    def remove_router_interface(self, context, router_id, interface_info):
        info = super(nsx_v.NsxVPluginV2, self.plugin).remove_router_interface(
            context, router_id, interface_info)
        router_db = self.plugin._get_router(context, router_id)
        subnet = self.plugin.get_subnet(context, info['subnet_id'])
        network_id = subnet['network_id']

        # If DHCP is disabled, this remove cannot trigger metadata change
        # as metadata is served via DHCP Edge
        if subnet['enable_dhcp'] and self.plugin.metadata_proxy_handler:
            md_cfg_required = self._metadata_cfg_required_after_port_remove(
                context, router_id, subnet)

            if md_cfg_required:
                self._metadata_route_remove(context, router_id)
        else:
            md_cfg_required = False

        if router_db.gw_port and router_db.enable_snat:
            plr_id = self.edge_manager.get_plr_by_tlr_id(
                context, router_id)
            self.plugin._update_nat_rules(context, router_db, plr_id)
            # Open firewall flows on plr
            self.plugin._update_subnets_and_dnat_firewall(
                context, router_db, router_id=plr_id)
            # Update static routes of plr
            nexthop = self.plugin._get_external_attachment_info(
                context, router_db)[2]
            self.update_routes(context, router_id, nexthop)

        self.plugin._update_subnets_and_dnat_firewall(context, router_db)
        # Safly remove interface, VDR can have interface to only one subnet in
        # a given network.
        edge_utils.delete_interface(
            self.nsx_v, context, router_id, network_id, dist=True)

        if self.plugin.metadata_proxy_handler:
            # Detach network from VDR-dedicated DHCP Edge
            vdr_dhcp_binding = nsxv_db.get_vdr_dhcp_binding_by_vdr(
                context.session, router_id)
            self.edge_manager.remove_network_from_dhcp_edge(
                context, network_id, vdr_dhcp_binding['dhcp_edge_id'])

            # Reattach to regular DHCP Edge
            self.edge_manager.create_dhcp_edge_service(
                context, network_id, subnet)

            address_groups = self.plugin._create_network_dhcp_address_group(
                context, network_id)
            self.edge_manager.update_dhcp_edge_service(
                context, network_id, address_groups=address_groups)

            if md_cfg_required:
                self._metadata_route_setup(context, router_id)
        return info
Exemplo n.º 4
0
    def remove_router_interface(self, context, router_id, interface_info):

        # If a loadbalancer is attached to this Edge appliance, we cannot
        # detach the subnet from the exclusive router.
        subnet = interface_info.get('subnet_id')
        if not subnet and interface_info.get('port_id'):
            port = self.plugin.get_port(context, interface_info['port_id'])
            port_subnets = [
                fixed_ip['subnet_id'] for fixed_ip in port.get(
                    'fixed_ips', [])]
            subnet = port_subnets[0]

        if subnet and self.nsx_v.is_subnet_in_use(context, subnet):
            error = _('Cannot delete router interface while loadbalancers are '
                      'provisioned on attached subnet')
            raise nsxv_exc.NsxPluginException(err_msg=error)

        info = super(nsx_v.NsxVPluginV2, self.plugin).remove_router_interface(
            context, router_id, interface_info)
        router_db = self.plugin._get_router(context, router_id)
        subnet = self.plugin.get_subnet(context, info['subnet_id'])
        network_id = subnet['network_id']

        with locking.LockManager.get_lock(
                self._get_router_edge_id(context, router_id), external=True):
            if router_db.gw_port and router_db.enable_snat:
                # First update nat rules
                self.plugin._update_nat_rules(context, router_db)
            ports = self.plugin._get_router_interface_ports_by_network(
                context, router_id, network_id)
            self.plugin._update_subnets_and_dnat_firewall(context, router_db)
            # No subnet on the network connects to the edge vnic
            if not ports:
                edge_utils.delete_interface(self.nsx_v, context,
                                            router_id, network_id,
                                            dist=False)
            else:
                address_groups = self.plugin._get_address_groups(
                    context, router_id, network_id)
                edge_utils.update_internal_interface(self.nsx_v, context,
                                                     router_id, network_id,
                                                     address_groups)
        return info
Exemplo n.º 5
0
 def _remove_router_services_on_edge(self, context, router_id,
                                     intf_net_id=None):
     router_ids = self.edge_manager.get_routers_on_same_edge(
         context, router_id)
     router_ids.remove(router_id)
     # Refresh firewall, nats, ext_vnic as well as static routes
     self._update_routes_on_routers(context, router_id, router_ids)
     self._update_subnets_and_dnat_firewall_on_routers(
         context, router_id, router_ids, allow_external=True)
     self._update_nat_rules_on_routers(context, router_id, router_ids)
     self._update_external_interface_on_routers(
         context, router_id, router_ids)
     intf_net_ids = self._get_internal_network_ids_by_router(
         context, router_id)
     if intf_net_id:
         intf_net_ids.remove(intf_net_id)
     for net_id in intf_net_ids:
         edge_utils.delete_interface(self.nsx_v, context, router_id, net_id,
                                     is_wait=False)
 def remove_router_interface(self, context, router_id, interface_info):
     info = super(nsx_v.NsxVPluginV2, self.plugin).remove_router_interface(
         context, router_id, interface_info)
     router_db = self.plugin._get_router(context, router_id)
     subnet = self.plugin.get_subnet(context, info['subnet_id'])
     network_id = subnet['network_id']
     if router_db.gw_port and router_db.enable_snat:
         # First update nat rules
         self.plugin._update_nat_rules(context, router_db)
     ports = self.plugin._get_router_interface_ports_by_network(
         context, router_id, network_id)
     self.plugin._update_subnets_and_dnat_firewall(context, router_db)
     # No subnet on the network connects to the edge vnic
     if not ports:
         edge_utils.delete_interface(self.nsx_v, context,
                                     router_id, network_id,
                                     dist=False)
     else:
         address_groups = self.plugin._get_address_groups(
             context, router_id, network_id)
         edge_utils.update_internal_interface(self.nsx_v, context,
                                              router_id, network_id,
                                              address_groups)
     return info