Exemple #1
0
    def process_floating_ip_addresses(self, interface_name):
        """Configure IP addresses on router's external gateway interface.

        Ensures addresses for existing floating IPs and cleans up
        those that should not longer be configured.
        """

        fip_statuses = {}
        if interface_name is None:
            LOG.debug('No Interface for floating IPs router: %s',
                      self.router['id'])
            return fip_statuses

        device = ip_lib.IPDevice(interface_name, namespace=self.ns_name)
        existing_cidrs = self.get_router_cidrs(device)
        new_cidrs = set()

        floating_ips = self.get_floating_ips()
        # Loop once to ensure that floating ips are configured.
        for fip in floating_ips:
            fip_ip = fip['floating_ip_address']
            ip_cidr = common_utils.ip_to_cidr(fip_ip)
            new_cidrs.add(ip_cidr)
            fip_statuses[fip['id']] = l3_constants.FLOATINGIP_STATUS_ACTIVE
            if ip_cidr not in existing_cidrs:
                fip_statuses[fip['id']] = self.add_floating_ip(
                    fip, interface_name, device)

        fips_to_remove = (ip_cidr for ip_cidr in existing_cidrs - new_cidrs
                          if common_utils.is_cidr_host(ip_cidr))
        for ip_cidr in fips_to_remove:
            self.remove_floating_ip(device, ip_cidr)

        return fip_statuses
Exemple #2
0
    def scan_fip_ports(self, ri):
        # don't scan if not dvr or count is not None
        if ri.dist_fip_count is not None:
            return

        # scan system for any existing fip ports
        ri.dist_fip_count = 0
        rtr_2_fip_interface = self.get_rtr_ext_device_name(ri.router_id)
        device = ip_lib.IPDevice(rtr_2_fip_interface, namespace=ri.ns_name)
        if device.exists():
            ri.dist_fip_count = len(ri.get_router_cidrs(device))
            # On upgrade, there could be stale IP addresses configured, check
            # and remove them once.
            # TODO(haleyb): this can go away after a cycle or two
            if not self._stale_fips_checked:
                stale_cidrs = (
                    ip for ip in router_info.RouterInfo.get_router_cidrs(
                        ri, device)
                    if common_utils.is_cidr_host(ip))
                for ip_cidr in stale_cidrs:
                    LOG.debug("Removing stale floating ip %s from interface "
                              "%s in namespace %s",
                              ip_cidr, rtr_2_fip_interface, ri.ns_name)
                    device.delete_addr_and_conntrack_state(ip_cidr)
                self._stale_fips_checked = True
Exemple #3
0
    def process_floating_ip_addresses(self, interface_name):
        """Configure IP addresses on router's external gateway interface.

        Ensures addresses for existing floating IPs and cleans up
        those that should not longer be configured.
        """

        fip_statuses = {}
        if interface_name is None:
            LOG.debug('No Interface for floating IPs router: %s',
                      self.router['id'])
            return fip_statuses

        device = ip_lib.IPDevice(interface_name, namespace=self.ns_name)
        existing_cidrs = self.get_router_cidrs(device)
        new_cidrs = set()
        gw_cidrs = self._get_gw_ips_cidr()

        floating_ips = self.get_floating_ips()
        # Loop once to ensure that floating ips are configured.
        for fip in floating_ips:
            fip_ip = fip['floating_ip_address']
            ip_cidr = common_utils.ip_to_cidr(fip_ip)
            new_cidrs.add(ip_cidr)
            fip_statuses[fip['id']] = lib_constants.FLOATINGIP_STATUS_ACTIVE
            if ip_cidr not in existing_cidrs:
                fip_statuses[fip['id']] = self.add_floating_ip(
                    fip, interface_name, device)
                LOG.debug('Floating ip %(id)s added, status %(status)s', {
                    'id': fip['id'],
                    'status': fip_statuses.get(fip['id'])
                })
            elif (fip_ip in self.fip_map
                  and self.fip_map[fip_ip] != fip['fixed_ip_address']):
                LOG.debug(
                    "Floating IP was moved from fixed IP "
                    "%(old)s to %(new)s", {
                        'old': self.fip_map[fip_ip],
                        'new': fip['fixed_ip_address']
                    })
                fip_statuses[fip['id']] = self.move_floating_ip(fip)
            elif fip_statuses[fip['id']] == fip['status']:
                # mark the status as not changed. we can't remove it because
                # that's how the caller determines that it was removed
                fip_statuses[fip['id']] = FLOATINGIP_STATUS_NOCHANGE
        fips_to_remove = (ip_cidr
                          for ip_cidr in existing_cidrs - new_cidrs - gw_cidrs
                          if common_utils.is_cidr_host(ip_cidr))
        for ip_cidr in fips_to_remove:
            LOG.debug(
                "Removing floating ip %s from interface %s in "
                "namespace %s", ip_cidr, interface_name, self.ns_name)
            self.remove_floating_ip(device, ip_cidr)

        return fip_statuses
Exemple #4
0
    def scan_fip_ports(self, ri):
        # don't scan if not dvr or count is not None
        if ri.dist_fip_count is not None:
            return

        # scan system for any existing fip ports
        ri.dist_fip_count = 0
        rtr_2_fip_interface = self.get_rtr_ext_device_name(ri.router_id)
        if ip_lib.device_exists(rtr_2_fip_interface, namespace=ri.ns_name):
            device = ip_lib.IPDevice(rtr_2_fip_interface, namespace=ri.ns_name)
            existing_cidrs = [addr["cidr"] for addr in device.addr.list()]
            fip_cidrs = [c for c in existing_cidrs if common_utils.is_cidr_host(c)]
            ri.dist_fip_count = len(fip_cidrs)
Exemple #5
0
    def process_floating_ip_addresses(self, interface_name):
        """Configure IP addresses on router's external gateway interface.

        Ensures addresses for existing floating IPs and cleans up
        those that should not longer be configured.
        """

        fip_statuses = {}
        if interface_name is None:
            LOG.debug('No Interface for floating IPs router: %s',
                      self.router['id'])
            return fip_statuses

        device = ip_lib.IPDevice(interface_name, namespace=self.ns_name)
        existing_cidrs = self.get_router_cidrs(device)
        new_cidrs = set()
        gw_cidrs = self._get_gw_ips_cidr()

        floating_ips = self.get_floating_ips()
        # Loop once to ensure that floating ips are configured.
        for fip in floating_ips:
            fip_ip = fip['floating_ip_address']
            ip_cidr = common_utils.ip_to_cidr(fip_ip)
            new_cidrs.add(ip_cidr)
            fip_statuses[fip['id']] = lib_constants.FLOATINGIP_STATUS_ACTIVE
            if ip_cidr not in existing_cidrs:
                fip_statuses[fip['id']] = self.add_floating_ip(
                    fip, interface_name, device)
                LOG.debug('Floating ip %(id)s added, status %(status)s',
                          {'id': fip['id'],
                           'status': fip_statuses.get(fip['id'])})
            elif (fip_ip in self.fip_map and
                  self.fip_map[fip_ip] != fip['fixed_ip_address']):
                LOG.debug("Floating IP was moved from fixed IP "
                          "%(old)s to %(new)s",
                          {'old': self.fip_map[fip_ip],
                           'new': fip['fixed_ip_address']})
                fip_statuses[fip['id']] = self.move_floating_ip(fip)
            elif fip_statuses[fip['id']] == fip['status']:
                # mark the status as not changed. we can't remove it because
                # that's how the caller determines that it was removed
                fip_statuses[fip['id']] = FLOATINGIP_STATUS_NOCHANGE
        fips_to_remove = (
            ip_cidr for ip_cidr in existing_cidrs - new_cidrs - gw_cidrs
            if common_utils.is_cidr_host(ip_cidr))
        for ip_cidr in fips_to_remove:
            LOG.debug("Removing floating ip %s from interface %s in "
                      "namespace %s", ip_cidr, interface_name, self.ns_name)
            self.remove_floating_ip(device, ip_cidr)

        return fip_statuses
Exemple #6
0
    def scan_fip_ports(self, ri):
        # don't scan if not dvr or count is not None
        if ri.dist_fip_count is not None:
            return

        # scan system for any existing fip ports
        ri.dist_fip_count = 0
        rtr_2_fip_interface = self.get_rtr_ext_device_name(ri.router_id)
        if ip_lib.device_exists(rtr_2_fip_interface, namespace=ri.ns_name):
            device = ip_lib.IPDevice(rtr_2_fip_interface, namespace=ri.ns_name)
            existing_cidrs = [addr['cidr'] for addr in device.addr.list()]
            fip_cidrs = [c for c in existing_cidrs if
                         common_utils.is_cidr_host(c)]
            ri.dist_fip_count = len(fip_cidrs)
Exemple #7
0
    def _set_subnet_arp_info(self, subnet):
        """Set ARP info retrieved from Plugin for existing ports."""
        # TODO(Carl) Can we eliminate the need to make this RPC while
        # processing a router.
        subnet_ports = self.agent.get_ports_by_subnet(subnet['id'])
        ignored_device_owners = (
            lib_constants.ROUTER_INTERFACE_OWNERS +
            tuple(common_utils.get_dvr_allowed_address_pair_device_owners()))
        device, device_exists = self.get_arp_related_dev(subnet['id'])

        subnet_ip_version = netaddr.IPNetwork(subnet['cidr']).version
        for p in subnet_ports:
            if p['device_owner'] not in ignored_device_owners:
                for fixed_ip in p['fixed_ips']:
                    if fixed_ip['subnet_id'] == subnet['id']:
                        self._update_arp_entry(fixed_ip['ip_address'],
                                               p['mac_address'],
                                               subnet['id'],
                                               'add',
                                               device=device,
                                               device_exists=device_exists)
                for allowed_address_pair in p.get('allowed_address_pairs', []):
                    if ('/' not in str(allowed_address_pair['ip_address'])
                            or common_utils.is_cidr_host(
                                allowed_address_pair['ip_address'])):
                        ip_address = common_utils.cidr_to_ip(
                            allowed_address_pair['ip_address'])
                        ip_version = common_utils.get_ip_version(ip_address)
                        if ip_version == subnet_ip_version:
                            self._update_arp_entry(
                                ip_address,
                                allowed_address_pair['mac_address'],
                                subnet['id'],
                                'add',
                                device=device,
                                device_exists=device_exists)

        # subnet_ports does not have snat port if the port is still unbound
        # by the time this function is called. So ensure to add arp entry
        # for snat port if port details are updated in router info.
        for p in self.get_snat_interfaces():
            for fixed_ip in p['fixed_ips']:
                if fixed_ip['subnet_id'] == subnet['id']:
                    self._update_arp_entry(fixed_ip['ip_address'],
                                           p['mac_address'],
                                           subnet['id'],
                                           'add',
                                           device=device,
                                           device_exists=device_exists)
        self._process_arp_cache_for_internal_port(subnet['id'])
Exemple #8
0
    def scan_fip_ports(self, ri):
        # don't scan if not dvr or count is not None
        if ri.dist_fip_count is not None:
            return

        # scan system for any existing fip ports
        ri.dist_fip_count = 0
        rtr_2_fip_interface = self.get_rtr_ext_device_name(ri.router_id)
        device = ip_lib.IPDevice(rtr_2_fip_interface, namespace=ri.ns_name)
        if device.exists():
            existing_cidrs = [addr["cidr"] for addr in device.addr.list()]
            fip_cidrs = [c for c in existing_cidrs if common_utils.is_cidr_host(c)]
            for fip_cidr in fip_cidrs:
                fip_ip = fip_cidr.split("/")[0]
                rule_pr = self._rule_priorities.allocate(fip_ip)
                ri.floating_ips_dict[fip_ip] = rule_pr
            ri.dist_fip_count = len(fip_cidrs)
Exemple #9
0
    def scan_fip_ports(self, ri):
        # don't scan if not dvr or count is not None
        if ri.dist_fip_count is not None:
            return

        # scan system for any existing fip ports
        ri.dist_fip_count = 0
        rtr_2_fip_interface = self.get_rtr_ext_device_name(ri.router_id)
        if ip_lib.device_exists(rtr_2_fip_interface, namespace=ri.ns_name):
            device = ip_lib.IPDevice(rtr_2_fip_interface, namespace=ri.ns_name)
            existing_cidrs = [addr['cidr'] for addr in device.addr.list()]
            fip_cidrs = [c for c in existing_cidrs if
                         common_utils.is_cidr_host(c)]
            for fip_cidr in fip_cidrs:
                fip_ip = fip_cidr.split('/')[0]
                rule_pr = self._rule_priorities.allocate(fip_ip)
                ri.floating_ips_dict[fip_ip] = rule_pr
            ri.dist_fip_count = len(fip_cidrs)
Exemple #10
0
    def process_floating_ip_addresses(self, interface_name):
        """Configure IP addresses on router's external gateway interface.

        Ensures addresses for existing floating IPs and cleans up
        those that should not longer be configured.
        """

        fip_statuses = {}
        if interface_name is None:
            LOG.debug("No Interface for floating IPs router: %s", self.router["id"])
            return fip_statuses

        device = ip_lib.IPDevice(interface_name, namespace=self.ns_name)
        existing_cidrs = self.get_router_cidrs(device)
        new_cidrs = set()

        floating_ips = self.get_floating_ips()
        # Loop once to ensure that floating ips are configured.
        for fip in floating_ips:
            fip_ip = fip["floating_ip_address"]
            ip_cidr = common_utils.ip_to_cidr(fip_ip)
            new_cidrs.add(ip_cidr)
            fip_statuses[fip["id"]] = l3_constants.FLOATINGIP_STATUS_ACTIVE
            if ip_cidr not in existing_cidrs:
                fip_statuses[fip["id"]] = self.add_floating_ip(fip, interface_name, device)
                LOG.debug(
                    "Floating ip %(id)s added, status %(status)s",
                    {"id": fip["id"], "status": fip_statuses.get(fip["id"])},
                )

                # mark the status as not changed. we can't remove it because
                # that's how the caller determines that it was removed
                if fip_statuses[fip["id"]] == fip["status"]:
                    fip_statuses[fip["id"]] = FLOATINGIP_STATUS_NOCHANGE
        fips_to_remove = (ip_cidr for ip_cidr in existing_cidrs - new_cidrs if common_utils.is_cidr_host(ip_cidr))
        for ip_cidr in fips_to_remove:
            LOG.debug(
                "Removing floating ip %s from interface %s in " "namespace %s", ip_cidr, interface_name, self.ns_name
            )
            self.remove_floating_ip(device, ip_cidr)

        return fip_statuses
Exemple #11
0
    def process_floating_ip_addresses(self, interface_name):
        """Configure IP addresses on router's external gateway interface.

        Ensures addresses for existing floating IPs and cleans up
        those that should not longer be configured.
        """

        fip_statuses = {}
        if interface_name is None:
            LOG.debug('No Interface for floating IPs router: %s',
                      self.router['id'])
            return fip_statuses

        device = ip_lib.IPDevice(interface_name, namespace=self.ns_name)
        existing_cidrs = self.get_router_cidrs(device)
        new_cidrs = set()

        floating_ips = self.get_floating_ips()
        # Loop once to ensure that floating ips are configured.
        for fip in floating_ips:
            fip_ip = fip['floating_ip_address']
            ip_cidr = common_utils.ip_to_cidr(fip_ip)
            new_cidrs.add(ip_cidr)
            fip_statuses[fip['id']] = l3_constants.FLOATINGIP_STATUS_ACTIVE
            if ip_cidr not in existing_cidrs:
                fip_statuses[fip['id']] = self.add_floating_ip(
                    fip, interface_name, device)
                LOG.debug('Floating ip %(id)s added, status %(status)s',
                          {'id': fip['id'],
                           'status': fip_statuses.get(fip['id'])})

        fips_to_remove = (
            ip_cidr for ip_cidr in existing_cidrs - new_cidrs
            if common_utils.is_cidr_host(ip_cidr))
        for ip_cidr in fips_to_remove:
            self.remove_floating_ip(device, ip_cidr)

        return fip_statuses
Exemple #12
0
 def scan_fip_ports(self, ri):
     # scan system for any existing fip ports
     rtr_2_fip_interface = self.get_rtr_ext_device_name(ri.router_id)
     device = ip_lib.IPDevice(rtr_2_fip_interface, namespace=ri.ns_name)
     if device.exists():
         if len(ri.get_router_cidrs(device)):
             self.rtr_fip_connect = True
         else:
             self.rtr_fip_connect = False
         # On upgrade, there could be stale IP addresses configured, check
         # and remove them once.
         # TODO(haleyb): this can go away after a cycle or two
         if not self._stale_fips_checked:
             stale_cidrs = (
                 ip for ip in router_info.RouterInfo.get_router_cidrs(
                     ri, device)
                 if common_utils.is_cidr_host(ip))
             for ip_cidr in stale_cidrs:
                 LOG.debug("Removing stale floating ip %s from interface "
                           "%s in namespace %s",
                           ip_cidr, rtr_2_fip_interface, ri.ns_name)
                 device.delete_addr_and_conntrack_state(ip_cidr)
             self._stale_fips_checked = True
Exemple #13
0
 def test_is_cidr_host_ipv6_32(self):
     self.assertFalse(utils.is_cidr_host('2000::1/32'))
Exemple #14
0
 def test_is_cidr_host_ipv6_netaddr(self):
     net = netaddr.IPNetwork("2000::1")
     self.assertTrue(utils.is_cidr_host(net))
Exemple #15
0
 def test_is_cidr_host_ipv6(self):
     self.assertTrue(utils.is_cidr_host('2000::1/128'))
Exemple #16
0
 def test_is_cidr_host_ipv4(self):
     self.assertTrue(utils.is_cidr_host('15.1.2.3/32'))
Exemple #17
0
 def test_is_cidr_host_ipv6_32(self):
     self.assertFalse(utils.is_cidr_host('2000::1/32'))
Exemple #18
0
 def test_is_cidr_host_ipv6_netaddr(self):
     net = netaddr.IPNetwork("2000::1")
     self.assertTrue(utils.is_cidr_host(net))
Exemple #19
0
 def test_is_cidr_host_ipv6(self):
     self.assertTrue(utils.is_cidr_host('2000::1/128'))
Exemple #20
0
 def test_is_cidr_host_ipv4(self):
     self.assertTrue(utils.is_cidr_host('15.1.2.3/32'))