Beispiel #1
0
def recreate_vdr_dhcp_edge(context, plugin, edge_manager, vdr_router_id):
    """Handle the edge recreation of a VDR router DHCP.
    """
    # delete the old bindings
    nsxv_db.delete_vdr_dhcp_binding(context.session, vdr_router_id)

    # Add each interface port of this router to a new edge:
    intf_ports = plugin._get_port_by_device_id(context, vdr_router_id,
                                               l3_db.DEVICE_OWNER_ROUTER_INTF)
    for port in intf_ports:
        fixed_ips = port.get("fixed_ips", [])
        if len(fixed_ips) > 0:
            fixed_ip = fixed_ips[0]
            subnet_id = fixed_ip['subnet_id']
            subnet = plugin.get_subnet(context, subnet_id)
        do_metadata = False
        for fixed_ip in fixed_ips:
            if fixed_ip['ip_address'] == subnet['gateway_ip']:
                do_metadata = True

        if do_metadata:
            edge_manager.configure_dhcp_for_vdr_network(
                context, subnet['network_id'], vdr_router_id)

    new_binding = nsxv_db.get_vdr_dhcp_binding_by_vdr(context.session,
                                                      vdr_router_id)
    if new_binding:
        LOG.info("VDR router %(vdr_id)s was moved to edge %(edge_id)s", {
            'vdr_id': vdr_router_id,
            'edge_id': new_binding['dhcp_edge_id']
        })
    else:
        LOG.error("VDR router %(vdr_id)s was not moved to a new edge",
                  {'vdr_id': vdr_router_id})
Beispiel #2
0
    def delete_router(self, context, router_id):
        self.edge_manager.delete_lrouter(context, router_id, dist=True)

        # This should address cases where the binding remains due to breakage
        if nsxv_db.get_vdr_dhcp_binding_by_vdr(context.session, router_id):
            LOG.warning("DHCP bind wasn't cleaned for router %s. "
                        "Cleaning up entry", router_id)
            nsxv_db.delete_vdr_dhcp_binding(context.session, router_id)
Beispiel #3
0
    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']
        vdr_dhcp_binding = nsxv_db.get_vdr_dhcp_binding_by_vdr(
            context.session, router_id)

        sids = self.plugin.get_subnets(context,
                                       filters={'network_id': [network_id],
                                                'enable_dhcp': [True]},
                                       fields=['id'])
        is_dhcp_network = len(sids) > 0
        with locking.LockManager.get_lock(self._get_edge_id(context,
                                                            router_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]
                md_gw_data = self._get_metadata_gw_data(context, router_id)
                self._update_routes(context, router_id, nexthop, md_gw_data)

            # If DHCP is disabled, this remove cannot trigger metadata change
            # as metadata is served via DHCP Edge
            elif (is_dhcp_network
                  and self.plugin.metadata_proxy_handler):
                md_gw_data = self._get_metadata_gw_data(context, router_id)
                if self._metadata_cfg_required_after_port_remove(
                    context, router_id, subnet):
                    self._metadata_route_update(context, router_id)

            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 and subnet['enable_dhcp']:
                self._attach_network_to_regular_dhcp(
                    context, router_id, network_id, subnet, vdr_dhcp_binding)

            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']

        with locking.LockManager.get_lock(self._get_edge_id(context,
                                                            router_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]
                md_gw_data = self._get_metadata_gw_data(context, router_id)
                self._update_routes(context, router_id, nexthop, md_gw_data)
                if (subnet['enable_dhcp']
                    and self.plugin.metadata_proxy_handler
                    and not md_gw_data):
                    # No more DHCP interfaces on VDR. Remove DHCP binding
                    nsxv_db.delete_vdr_dhcp_binding(context.session, router_id)

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

            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)

            # The network would be the last one attached to the VDR if
            # md_gw_data is None. For such condition, we just keep network
            # attached to the dhcp edge since the dhcp edge is a pure dhcp
            # support edge now
            if (self.plugin.metadata_proxy_handler and subnet['enable_dhcp']
                and md_gw_data):
                # Detach network from VDR-dedicated DHCP Edge
                vdr_dhcp_binding = nsxv_db.get_vdr_dhcp_binding_by_vdr(
                    context.session, router_id)

                # A case where we do not have a vdr_dhcp_binding indicates a DB
                # inconsistency. We check for this anyway, in case that
                # something is broken.
                if vdr_dhcp_binding:
                    self.edge_manager.reset_sysctl_rp_filter_for_vdr_dhcp(
                        context, vdr_dhcp_binding['dhcp_edge_id'], network_id)

                    self.edge_manager.remove_network_from_dhcp_edge(
                        context, network_id, vdr_dhcp_binding['dhcp_edge_id'])
                else:
                    LOG.error(_LE('VDR DHCP binding is missing for %s'),
                              router_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)

            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']

        with locking.LockManager.get_lock(self._get_edge_id(
                context, router_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]
                md_gw_data = self._get_metadata_gw_data(context, router_id)
                self._update_routes(context, router_id, nexthop, md_gw_data)
                if (subnet['enable_dhcp']
                        and self.plugin.metadata_proxy_handler
                        and not md_gw_data):
                    # No more DHCP interfaces on VDR. Remove DHCP binding
                    nsxv_db.delete_vdr_dhcp_binding(context.session, router_id)

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

            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)

            # The network would be the last one attached to the VDR if
            # md_gw_data is None. For such condition, we just keep network
            # attached to the dhcp edge since the dhcp edge is a pure dhcp
            # support edge now
            if (self.plugin.metadata_proxy_handler and subnet['enable_dhcp']
                    and md_gw_data):
                # Detach network from VDR-dedicated DHCP Edge
                vdr_dhcp_binding = nsxv_db.get_vdr_dhcp_binding_by_vdr(
                    context.session, router_id)

                # A case where we do not have a vdr_dhcp_binding indicates a DB
                # inconsistency. We check for this anyway, in case that
                # something is broken.
                if vdr_dhcp_binding:
                    self.edge_manager.reset_sysctl_rp_filter_for_vdr_dhcp(
                        context, vdr_dhcp_binding['dhcp_edge_id'], network_id)

                    self.edge_manager.remove_network_from_dhcp_edge(
                        context, network_id, vdr_dhcp_binding['dhcp_edge_id'])
                else:
                    LOG.error(_LE('VDR DHCP binding is missing for %s'),
                              router_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)

            return info