Exemple #1
0
    def test_sequential_assignment_full_pool(self):
        four_pool = IPNetwork("192.168.0.0/30")
        assigner = SequentialAssignment()

        assert_equal("192.168.0.1", assigner.allocate(four_pool))
        assert_equal("192.168.0.2", assigner.allocate(four_pool))
        assert_equal(None, assigner.allocate(four_pool))
def assign_ip(version):
    """
    Assign a IP address from the configured pools.
    :param version: 4 for IPv4, 6 for IPv6.
    :return: An IPAddress, or None if an IP couldn't be
             assigned
    """
    ip = None

    assert version in [4, 6]
    # For each configured pool, attempt to assign an IP before giving up.
    for pool in client.get_ip_pools(version):
        assigner = SequentialAssignment()
        ip = assigner.allocate(pool)
        if ip is not None:
            ip = IPNetwork(ip)
            break
    return ip
def assign_ip(version):
    """
    Assign a IP address from the configured pools.
    :param version: 4 for IPv4, 6 for IPv6.
    :return: An IPAddress, or None if an IP couldn't be
             assigned
    """
    ip = None

    assert version in [4, 6]
    # For each configured pool, attempt to assign an IP before giving up.
    for pool in client.get_ip_pools(version):
        assigner = SequentialAssignment()
        ip = assigner.allocate(pool)
        if ip is not None:
            ip = IPNetwork(ip)
            break
    return ip
def assign_ipv4():
    """
    Assign a IPv4 address from the configured pools.
    :return: An IPAddress, or None if an IP couldn't be
             assigned
    """
    ip = None

    # For each configured pool, attempt to assign an IP before giving up.
    for pool in datastore.get_ip_pools("v4"):
        assigner = SequentialAssignment()
        ip = assigner.allocate(pool)
        if ip is not None:
            _log.info("Found free address %s in pool %s", ip, pool)
            ip = IPAddress(ip)
            break
        else:
            _log.error("Couldn't assign address in pool %s", pool)
    return ip
def assign_ipv4():
    """
    Assign a IPv4 address from the configured pools.
    :return: An IPAddress, or None if an IP couldn't be
             assigned
    """
    ip = None

    # For each configured pool, attempt to assign an IP before giving up.
    for pool in datastore.get_ip_pools("v4"):
        assigner = SequentialAssignment()
        ip = assigner.allocate(pool)
        if ip is not None:
            _log.info("Found free address %s in pool %s", ip, pool)
            ip = IPAddress(ip)
            break
        else:
            _log.error("Couldn't assign address in pool %s", pool)
    return ip
Exemple #6
0
 def test_sequential_assignment_tiny_pool(self):
     assigner = SequentialAssignment()
     assert_equal(None, assigner.allocate(IPNetwork("192.168.0.0/31")))
Exemple #7
0
 def test_sequential_assignment_pool(self):
     assigner = SequentialAssignment()
     assert_equal("192.168.0.1", assigner.allocate(pool))
Exemple #8
0
 def test_sequential_assignment_network(self):
     assigner = SequentialAssignment()
     assert_equal("192.168.0.1", assigner.allocate(network))