Beispiel #1
0
def get_next_ip(s):
    """ip=ip+1, include x.x.x.0 and x.x.x.255,

    :param s: string type of ip .
    :returns: ip+1
    :raises:
    """
    return str(long2ip(ip2long(s) + 1))
Beispiel #2
0
def get_next_valid_ip(s):
    """ip = ip + 1, omit x.x.x.0 and x.x.x.255,

    :param s: string type of ip .
    :returns: string type of ip+1
    :raises:
    """
    b = str(long2ip(ip2long(s) + 1))
    if b.split('.')[3] == "0" or b.split('.')[3] == "255":
        b = get_next_valid_ip(b)
    return b
Beispiel #3
0
 def to_python(self, value):
     if isinstance(value, IPAddressField):
         return value
     if '.' in value or ':' in value:
         return value
     if value in EMPTY_VALUES:
         return ''
     if value[:4] == 'ipv6':
         return ipv6.long2ip(int(value[4:]))
     else:
         return ipv4.long2ip(int(value[4:]))
def get_next_ip(ports):
    max_ip = -1
    for port in ports:
        fixed_ip = port["fixed_ips"]
        if not fixed_ip:
            continue
        fixed_ip = fixed_ip[0]["ip_address"]
        max_ip = max(max_ip, ip2long(fixed_ip))
    if max_ip <= 0:
        raise Exception("Next IP address could not be determined" " (You have no existing Fixed IPs!)")
    new_fixed_ip = long2ip(max_ip + 1)
    return new_fixed_ip
def get_next_ip(ports):
    max_ip = -1
    for port in ports:
        fixed_ip = port['fixed_ips']
        if not fixed_ip:
            continue
        fixed_ip = fixed_ip[0]['ip_address']
        max_ip = max(max_ip, ip2long(fixed_ip))
    if max_ip <= 0:
        raise Exception("Next IP address could not be determined"
                        " (You have no existing Fixed IPs!)")
    new_fixed_ip = long2ip(max_ip + 1)
    return new_fixed_ip
Beispiel #6
0
def _get_next_fixed_ip(ports):
    """
    Expects the output from user-specific neutron port-list. will determine the
    next available fixed IP by 'counting' the highest allocated IP address and
    adding one to it.
    """
    try:
        from iptools.ipv4 import ip2long, long2ip
    except ImportError:
        raise Exception("For this script, we need iptools. pip install iptools")
    max_ip = -1
    for port in ports:
        fixed_ip = port["fixed_ips"]
        if not fixed_ip:
            continue
        fixed_ip = fixed_ip[0]["ip_address"]
        max_ip = max(max_ip, ip2long(fixed_ip))
    if max_ip <= 0:
        raise Exception("Next IP address could not be determined" " (You have no existing Fixed IPs!)")
    new_fixed_ip = long2ip(max_ip + 1)
    return new_fixed_ip
Beispiel #7
0
def _get_next_fixed_ip(ports):
    """
    Expects the output from user-specific neutron port-list. will determine the
    next available fixed IP by 'counting' the highest allocated IP address and
    adding one to it.
    """
    try:
        from iptools.ipv4 import ip2long, long2ip
    except ImportError:
        raise Exception("For this script, we need iptools. pip install iptools")
    max_ip = -1
    for port in ports:
        fixed_ip = port['fixed_ips']
        if not fixed_ip:
            continue
        fixed_ip = fixed_ip[0]['ip_address']
        max_ip = max(max_ip, ip2long(fixed_ip))
    if max_ip <= 0:
        raise Exception("Next IP address could not be determined"
                        " (You have no existing Fixed IPs!)")
    new_fixed_ip = long2ip(max_ip + 1)
    return new_fixed_ip