def getIpNetmask(ipParam, netmaskParam):
    ipValue = None
    netmaskValue = None
    if ipParam.isSet():
        v = ipParam.getValue()
        if "/" in v:
            ipValue, cidr = v.split("/")
            netmaskValue = util.intToIp(util.cidrToNetmaskInt(int(cidr)))
        else:
            ipValue = v
            if netmaskParam.isSet():
                netmaskValue = netmaskParam.getValue()
    return (ipValue, netmaskValue)
    def getConfigMap(self):
        m = dict([(p.getName(), p.getValue()) for p in self.__getOrderedParamList()])

        ip = m[pdesc.PARAM_IP_ADDRESS]

        # config expects the ip mode param
        m[pdesc.PARAM_IP_MODE] = pdesc.IP_DHCP if ip == pdesc.IP_DHCP else pdesc.IP_STATIC

        # config expects the netmask param and ip not in cidr notation
        if ip != pdesc.IP_DHCP and "/" in ip:
            ip2, cidr = ip.split("/")
            netmask = util.intToIp(util.cidrToNetmaskInt(int(cidr)))
            m[pdesc.PARAM_IP_ADDRESS] = ip2
            m[pdesc.PARAM_IP_NETMASK] = netmask

        # blank out ntp if special case - no ntp
        if pdesc.PARAM_NTP in m and m[pdesc.PARAM_NTP] == pdesc.NO_NTP:
            m[pdesc.PARAM_NTP] = ""

        return m
Exemple #3
0
    def getConfigMap(self):
        m = dict([(p.getName(), p.getValue())
                  for p in self.__getOrderedParamList()])

        ip = m[pdesc.PARAM_IP_ADDRESS]

        # config expects the ip mode param
        m[pdesc.
          PARAM_IP_MODE] = pdesc.IP_DHCP if ip == pdesc.IP_DHCP else pdesc.IP_STATIC

        # config expects the netmask param and ip not in cidr notation
        if ip != pdesc.IP_DHCP and "/" in ip:
            ip2, cidr = ip.split("/")
            netmask = util.intToIp(util.cidrToNetmaskInt(int(cidr)))
            m[pdesc.PARAM_IP_ADDRESS] = ip2
            m[pdesc.PARAM_IP_NETMASK] = netmask

        # blank out ntp if special case - no ntp
        if pdesc.PARAM_NTP in m and m[pdesc.PARAM_NTP] == pdesc.NO_NTP:
            m[pdesc.PARAM_NTP] = ""

        return m
Exemple #4
0
import util
import re

ipRegex = re.compile(
    r"^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"
)
hostRegex = re.compile(
    r"^([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]{0,61}[A-Za-z0-9])$")
hostOrDomainRegex = re.compile(
    r"^(([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]{0,61}[A-Za-z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]{0,61}[A-Za-z0-9])$"
)

# omitting 255.255.255.255 and 255.255.255.254
validCidrs = [i for i in range(0, 31)]
validSubnets = [util.cidrToNetmaskInt(cidr) for cidr in validCidrs]


def checkIp(ip):
    if ipRegex.match(ip) == None:
        return False

    ipInt = util.ipToInt(ip)
    if ipInt == 0:
        return False
    if (ipInt >> 24) == 127:
        return False
    return True


def checkCidr(cidr):
#!/usr/bin/env python

import util
import re

ipRegex = re.compile(r"^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$")
hostRegex = re.compile(r"^([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]{0,61}[A-Za-z0-9])$")
hostOrDomainRegex = re.compile(r"^(([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]{0,61}[A-Za-z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]{0,61}[A-Za-z0-9])$")

# omitting 255.255.255.255 and 255.255.255.254
validCidrs = [i for i in range(0, 31)]
validSubnets = [util.cidrToNetmaskInt(cidr) for cidr in validCidrs]

def checkIp(ip):
    if ipRegex.match(ip) == None:
        return False

    ipInt = util.ipToInt(ip)
    if ipInt == 0:
        return False
    if (ipInt >> 24) == 127:
        return False
    return True

def checkCidr(cidr):
    cidrInt = -1
    try:
        cidrInt = int(cidr)
    except:
        return False