Ejemplo n.º 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))
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
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
Ejemplo n.º 5
0
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
Ejemplo n.º 6
0
 def test_sequential_assignment_tiny_pool(self):
     assigner = SequentialAssignment()
     assert_equal(None, assigner.allocate(IPNetwork("192.168.0.0/31")))
Ejemplo n.º 7
0
 def test_sequential_assignment_pool(self):
     assigner = SequentialAssignment()
     assert_equal("192.168.0.1", assigner.allocate(pool))
Ejemplo n.º 8
0
 def test_sequential_assignment_network(self):
     assigner = SequentialAssignment()
     assert_equal("192.168.0.1", assigner.allocate(network))