예제 #1
0
def _assign_host_tunnel_addr(ipip_pools):
    """
    Claims an IPIP-enabled IP address from the first pool with some
    space.

    Stores the result in the host's config as its tunnel address.

    Exits on failure.
    :param ipip_pools:  List of IPPools to search for an address.
    """
    for ipip_pool in ipip_pools:
        v4_addrs, _ = client.auto_assign_ips(
            num_v4=1, num_v6=0,
            handle_id=None,
            attributes={},
            pool=(ipip_pool, None),
            host=hostname
        )
        if v4_addrs:
            # Successfully allocated an address.  Unpack the list.
            [ip_addr] = v4_addrs
            break
    else:
        # Failed to allocate an address, the pools must be full.
        print_paragraph(
            "Failed to allocate an IP address from an IPIP-enabled pool "
            "for the host's IPIP tunnel device.  Pools are likely "
            "exhausted."
        )
        sys.exit(1)
    # If we get here, we've allocated a new IPIP-enabled address,
    # Store it in etcd so that Felix will pick it up.
    client.set_per_host_config(hostname, "IpInIpTunnelAddr",
                               str(ip_addr))
예제 #2
0
def _assign_host_tunnel_addr(ipip_pools):
    """
    Claims an IPIP-enabled IP address from the first pool with some
    space.

    Stores the result in the host's config as its tunnel address.

    Exits on failure.
    :param ipip_pools:  List of IPPools to search for an address.
    """
    for ipip_pool in ipip_pools:
        v4_addrs, _ = client.auto_assign_ips(num_v4=1,
                                             num_v6=0,
                                             handle_id=None,
                                             attributes={},
                                             pool=(ipip_pool, None),
                                             host=hostname)
        if v4_addrs:
            # Successfully allocated an address.  Unpack the list.
            [ip_addr] = v4_addrs
            break
    else:
        # Failed to allocate an address, the pools must be full.
        print_paragraph(
            "Failed to allocate an IP address from an IPIP-enabled pool "
            "for the host's IPIP tunnel device.  Pools are likely "
            "exhausted.")
        sys.exit(1)
    # If we get here, we've allocated a new IPIP-enabled address,
    # Store it in etcd so that Felix will pick it up.
    client.set_per_host_config(hostname, "IpInIpTunnelAddr", str(ip_addr))
예제 #3
0
def assign_any(v4_count, v6_count, pool=(None, None)):
    """
    Reserve <count> IP(s) from the datastore to be applied to a container

    :param arguments: v4_count = Count of IPv4 addresses
                      v6_count = Count of IPv6 addresses
                      pool = tuple(<IPv4 cidr>, <IPv6 cidr>)
    :return: tuple(list(IPv4 IPAddresses), list(IPv6 IPAddresses))
    """
    v4_list, v6_list = client.auto_assign_ips(v4_count, v6_count, None, {},
                                              pool=pool)
    if not any((v4_list, v6_list)):
        sys.exit("Failed to allocate any IPs (requested {0} IPv4s and {1} IPv6s). "
                 "Pools are likely exhausted.".format(v4_count, v6_count))

    return (v4_list, v6_list)
예제 #4
0
def assign_any(v4_count, v6_count, pool=(None, None)):
    """
    Reserve <count> IP(s) from the datastore to be applied to a container

    :param arguments: v4_count = Count of IPv4 addresses
                      v6_count = Count of IPv6 addresses
                      pool = tuple(<IPv4 cidr>, <IPv6 cidr>)
    :return: tuple(list(IPv4 IPAddresses), list(IPv6 IPAddresses))
    """
    v4_list, v6_list = client.auto_assign_ips(v4_count,
                                              v6_count,
                                              None, {},
                                              pool=pool)
    if not any((v4_list, v6_list)):
        sys.exit(
            "Failed to allocate any IPs (requested {0} IPv4s and {1} IPv6s). "
            "Pools are likely exhausted.".format(v4_count, v6_count))

    return (v4_list, v6_list)