Ejemplo n.º 1
0
def testConflict(ip1Param, ip2Param, netmaskParam, testSubnet=True):
    ipValue, netmaskValue = getIpNetmask(ip2Param, netmaskParam)
    if ipValue is not None:
        if ipValue == ip1Param.getValue():
            return colorRed("SAME AS %s" % ip2Param.getName())

        if testSubnet and netmaskValue is not None:
            if not check.checkIpsInSameSubnet(ipValue, ip1Param.getValue(), netmaskValue):
                netmaskInt = util.ipToInt(netmaskValue)
                ipPrefix = util.intToIp(util.ipToInt(ipValue) & netmaskInt)
                cidr = util.netmaskToCidr(netmaskValue)
                return colorRed("NOT IN SUBNET OF %s/%s" % (ipPrefix, cidr))
    return None
Ejemplo n.º 2
0
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)
Ejemplo n.º 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
Ejemplo n.º 4
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