Example #1
0
 def _allocate_specific_ip(self, address, **kwargs):
     ip_block = utils.find(lambda ip_block: ip_block.contains(address),
                           self.ip_blocks)
     if ip_block:
         try:
             return ip_block.allocate_ip(address=address, **kwargs)
         except DuplicateAddressError:
             pass
Example #2
0
 def find_allowed_ip(self, address):
     ip = utils.find(lambda ip: ip.address == address, self.ips_allowed())
     if ip is None:
         raise ModelNotFoundError(
             _("Ip Address %(address)s hasnt been allowed "
               "on interface %(vif_id)s") %
             (dict(address=address, vif_id=self.virtual_interface_id)))
     return ip
Example #3
0
 def _allocate_specific_ip(self, address, **kwargs):
     ip_block = utils.find(lambda ip_block: ip_block.contains(address),
                           self.ip_blocks)
     if ip_block:
         try:
             return ip_block.allocate_ip(address=address, **kwargs)
         except DuplicateAddressError:
             pass
Example #4
0
 def find_allowed_ip(self, address):
     ip = utils.find(lambda ip: ip.address == address,
                     self.ips_allowed())
     if ip is None:
         raise ModelNotFoundError(
             _("Ip Address %(address)s hasnt been allowed "
               "on interface %(vif_id)s")
             % (dict(address=address,
                     vif_id=self.virtual_interface_id)))
     return ip
Example #5
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"))
Example #6
0
    def test_data_without_links(self):
        collection = [{'id': "resource1"}, {'id': "resource2"}]
        next_page_marker = None
        current_page_url = "http://abc.com/resources?limit=2&marker=resource0"

        view = PaginatedDataView('ip_blocks', collection, current_page_url,
                                 next_page_marker)
        self.assertTrue('ip_blocks_links' not in view.data_for_json())
        data_for_xml = find(lambda obj: isinstance(obj, AtomLink),
                            view.data_for_xml()['ip_blocks'])
        self.assertIsNone(data_for_xml)
Example #7
0
    def test_data_without_links(self):
        collection = [{'id': "resource1"}, {'id': "resource2"}]
        next_page_marker = None
        current_page_url = "http://abc.com/resources?limit=2&marker=resource0"

        view = PaginatedDataView('ip_blocks', collection, current_page_url,
                                 next_page_marker)
        self.assertTrue('ip_blocks_links' not in view.data_for_json())
        data_for_xml = find(lambda obj: isinstance(obj, AtomLink),
                            view.data_for_xml()['ip_blocks'])
        self.assertIsNone(data_for_xml)
Example #8
0
    def test_links_data_for_xml(self):
        collection = [{'id': "resource1"}, {'id': "resource2"}]
        next_page_marker = "resource2"
        current_page_url = "http://abc.com/resources?limit=2&marker=resource0"
        expected_href = "http://abc.com/resources?limit=2&marker=resource2"

        data = PaginatedDataView('ip_blocks', collection, current_page_url,
                                 next_page_marker).data_for_xml()

        actual_link = find(lambda obj: isinstance(obj, AtomLink),
                           data['ip_blocks'])
        self.assertUrlEqual(actual_link.href, expected_href)
        self.assertUrlEqual(actual_link.rel, "next")
Example #9
0
    def test_links_data_for_xml(self):
        collection = [{'id': "resource1"}, {'id': "resource2"}]
        next_page_marker = "resource2"
        current_page_url = "http://abc.com/resources?limit=2&marker=resource0"
        expected_href = "http://abc.com/resources?limit=2&marker=resource2"

        data = PaginatedDataView('ip_blocks', collection, current_page_url,
                                 next_page_marker).data_for_xml()

        actual_link = find(lambda obj: isinstance(obj, AtomLink),
                           data['ip_blocks'])
        self.assertUrlEqual(actual_link.href, expected_href)
        self.assertUrlEqual(actual_link.rel, "next")
Example #10
0
    def test_find_returns_none_when_no_matching_item_found(self):
        items = [1, 2, 3, 4]

        item = utils.find((lambda item: item == 8), items)

        self.assertEqual(item, None)
Example #11
0
    def test_find_returns_first_item_matching_predicate(self):
        items = [1, 2, 3, 4]

        item = utils.find((lambda item: item == 2), items)

        self.assertEqual(item, 2)
Example #12
0
    def test_find_returns_none_when_no_matching_item_found(self):
        items = [1, 2, 3, 4]

        item = utils.find((lambda item: item == 8), items)

        self.assertEqual(item, None)
Example #13
0
    def test_find_returns_first_item_matching_predicate(self):
        items = [1, 2, 3, 4]

        item = utils.find((lambda item: item == 2), items)

        self.assertEqual(item, 2)