Beispiel #1
0
 def ensureIpAddressInIpNet(obj):
     """address must be in network
     """
     if obj.ipNet is not None:
         ipNet = IP(obj.ipNet.ipv4)
         mynet = IP(obj.ipv4)
         if not mynet in ipNet:
             raise Invalid(u"'%s' not in '%s'" % (obj.ipv4, obj.ipNet.ipv4))
Beispiel #2
0
 def _validate(self, value):
     """ validation method for forms """
     ## call parent validations
     TextLine._validate(self, value)
     try:
         ## we only try to initialize an instance of IPy
         ip = IP(value)
     except:
         raise HostIpValidError(value, 1)
     if ip.strNetmask() != '255.255.255.255':
         raise HostNetmaskValidError(value, 1)
Beispiel #3
0
def AllValidSubIpNets(dummy_context):
    uidutil = getUtility(IIntIds)
    validObjects = []
    if IIpNet.providedBy(dummy_context):
        myIpNetIp = IP(dummy_context.ipv4)
        for (oid, oobj) in uidutil.items():
            if IIpNet.providedBy(oobj.object):
                i_IpNetIp = IP(oobj.object.ipv4)
                if i_IpNetIp in myIpNetIp and \
                    oobj.object != dummy_context:
                    validObjects.append(oobj.object)
    else:
        for (oid, oobj) in uidutil.items():
            if IIpNet.providedBy(oobj.object):
                validObjects.append(oobj.object)
    return ComponentsFromObjList(dummy_context, validObjects, 'ipv4')
Beispiel #4
0
 def _validate(self, value):
     """ validation method for forms """
     ## call parent validations
     TextLine._validate(self, value)
     try:
         ## we only try to initialize an instance of IPy
         ip = IP(value)
     except:
         raise NetIpValidError(value, 1)
Beispiel #5
0
 def ensureSubnetInIpNet(obj):
     """publicKey must be valid PEM string
     """
     if obj.parentnet is not None:
         if IIpNet.providedBy(obj.parentnet):
             parentnet = IP(obj.parentnet.ipv4)
         else:
             parentnet = IP(obj.parentnet)
         mynet = IP(obj.ipv4)
         if not mynet in parentnet:
             raise Invalid(u"'%s' not in '%s'" %
                           (obj.ipv4, obj.parentnet.ipv4))
     if obj.subnets is not None:
         mynet = IP(obj.ipv4)
         for subnet_obj in obj.subnets:
             subnet = IP(subnet_obj.ipv4)
             if not subnet in mynet:
                 raise Invalid(u"'%s' not in '%s'" %
                               (subnet_obj.ipv4, obj.ipv4))
Beispiel #6
0
 def getSortKey(self, item, formatter):
     hostIpList = item.getIpList()
     if len(hostIpList) > 0:
         return IP(hostIpList[0])
     return None
Beispiel #7
0
 def containsIp(self, ipString):
     """ is ip(String) part of this network?
     """
     myIp = IP(self.ipv4)
     testIp = IP(ipString)
     return testIp in myIp
Beispiel #8
0
 def getSortKey(self, item, formatter):
     key = self.getter(item, formatter)
     return IP(key).int()