Beispiel #1
0
    def test_loads_default_ipv6_generator_when_not_configured(self):
        args = dict(used_by_tenant="1", mac_address="00:11:22:33:44:55")

        ip_generator = ipv6.address_generator_factory("fe::/64", **args)

        self.assertTrue(isinstance(ip_generator,
                              tenant_based_generator.TenantBasedIpV6Generator))
Beispiel #2
0
    def test_loads_default_ipv6_generator_when_not_configured(self):
        args = dict(used_by_tenant="1", mac_address="00:11:22:33:44:55")

        ip_generator = ipv6.address_generator_factory("fe::/64", **args)

        self.assertTrue(
            isinstance(ip_generator,
                       tenant_based_generator.TenantBasedIpV6Generator))
Beispiel #3
0
    def test_loads_ipv6_generator_factory_from_config_file(self):
        args = dict(tenant_id="1", mac_address="00:11:22:33:44:55")
        with unit.StubConfig(ipv6_generator=self.mock_generator_name):
            ip_generator = ipv6.address_generator_factory("fe::/64", **args)

        self.assertEqual(ip_generator.kwargs, args)
        self.assertTrue(
            isinstance(ip_generator, mock_generator.MockIpV6Generator))
Beispiel #4
0
    def test_loads_ipv6_generator_factory_from_config_file(self):
        args = dict(tenant_id="1", mac_address="00:11:22:33:44:55")
        with unit.StubConfig(ipv6_generator=self.mock_generatore_name):
            ip_generator = ipv6.address_generator_factory("fe::/64",
                                                                 **args)

        self.assertEqual(ip_generator.kwargs, args)
        self.assertTrue(isinstance(ip_generator,
                                   mock_generator.MockIpV6Generator))
Beispiel #5
0
    def _generate_ip(self, **kwargs):
        if self.is_ipv6():
            generator = ipv6.address_generator_factory(self.cidr, **kwargs)
            address = next((address for address in IpAddressIterator(generator)
                            if self.does_address_exists(address) is False),
                           None)
        else:
            generator = ipv4.plugin().get_generator(self)
            address = next(
                (address for address in IpAddressIterator(generator)
                 if self._address_is_allocatable(self.policy(), address)),
                None)

        if not address:
            self.update(is_full=True)
            raise exception.NoMoreAddressesError(_("IpBlock is full"))
        return address
Beispiel #6
0
    def _generate_ip(self, **kwargs):
        if self.is_ipv6():
            generator = ipv6.address_generator_factory(self.cidr,
                                                       **kwargs)
            address = next((address for address in IpAddressIterator(generator)
                           if self.does_address_exists(address) is False),
                           None)
        else:
            generator = ipv4.plugin().get_generator(self)
            address = next((address for address in IpAddressIterator(generator)
                            if self._address_is_allocatable(self.policy(),
                                                            address)),
                           None)

        if not address:
            self.update(is_full=True)
            raise exception.NoMoreAddressesError(_("IpBlock is full"))
        return address
Beispiel #7
0
    def _generate_ip_address(self, **kwargs):
        if self.is_ipv6():
            address_generator = ipv6.address_generator_factory(self.cidr,
                                                               **kwargs)

            return utils.find(lambda address:
                              self.does_address_exists(address) is False,
                              IpAddressIterator(address_generator))
        else:
            generator = ipv4.address_generator_factory(self)
            policy = self.policy()
            address = utils.find(lambda address:
                                 self._address_is_allocatable(policy, address),
                                 IpAddressIterator(generator))

            if address:
                return address

            self.update(is_full=True)
            raise exception.NoMoreAddressesError(_("IpBlock is full"))
Beispiel #8
0
    def test_does_not_raise_error_if_generator_does_not_require_params(self):
        with unit.StubConfig(ipv6_generator=self.mock_generatore_name):
            ip_generator = ipv6.address_generator_factory("fe::/64")

        self.assertIsNotNone(ip_generator)
Beispiel #9
0
    def test_does_not_raise_error_if_generator_does_not_require_params(self):
        with unit.StubConfig(ipv6_generator=self.mock_generator_name):
            ip_generator = ipv6.address_generator_factory("fe::/64")

        self.assertIsNotNone(ip_generator)