Exemple #1
0
    def getZoneFreeIp(self, zone, startAt=None):
        """
        Return the first available IP address of a zone.
        If startAt is given, start the search from this IP.

        If none available, return an empty string.

        @param zone: DNS zone name in LDAP
        @type zone: str

        @param startAt: IP to start search
        @type startAt: str
        """
        ret = ""
        networks = self.getZoneNetworkAddress(zone)
        if networks:
            # We support only one single reverse zone, that's why we do [0]
            basenetwork = networks[0]
            dotcount = basenetwork.count(".")
            # Build a netmask
            netmask = (dotcount + 1) * 8
            # Build a quad dotted network address
            network = basenetwork + ((3 - dotcount) * ".0")
            if startAt:
                ip = startAt
            else:
                ip = network
            ip = ipNext(network, netmask, ip)
            while ip:
                if not self.ipExists(zone, ip):
                    ret = ip
                    break
                ip = ipNext(network, netmask, ip)
            return ret
        else:
            # return nothing if you don't have any
            # reverse zone
            return ""
Exemple #2
0
Fichier : dns.py Projet : allgi/mmc
    def getZoneFreeIp(self, zone, startAt=None):
        """
        Return the first available IP address of a zone.
        If startAt is given, start the search from this IP.

        If none available, return an empty string.

        @param zone: DNS zone name in LDAP
        @type zone: str

        @param startAt: IP to start search
        @type startAt: str
        """
        ret = ""
        networks = self.getZoneNetworkAddress(zone)
        if networks:
            # We support only one single reverse zone, that's why we do [0]
            basenetwork = networks[0]
            dotcount = basenetwork.count(".")
            # Build a netmask
            netmask = (dotcount + 1) * 8
            # Build a quad dotted network address
            network = basenetwork + ((3 - dotcount) * ".0")
            if startAt: ip = startAt
            else: ip = network
            ip = ipNext(network, netmask, ip)
            while ip:
                if not self.ipExists(zone, ip):
                    ret = ip
                    break
                ip = ipNext(network, netmask, ip)
            return ret
        else:
            # return nothing if you don't have any
            # reverse zone
            return ""
Exemple #3
0
    def getSubnetFreeIp(self, subnet, startAt=None):
        """
        Return the first available IP address of a subnet.
        If startAt is given, start the search from this IP.

        IPs inside subnet dynamic pool range are never returned.

        If none available, return an empty string.

        @param subnet: subnet name in LDAP
        @type subnet: str

        @param startAt: IP to start search
        @type startAt: str
        """
        ret = ""
        subnetDN = self.getSubnet(subnet)
        network = subnetDN[0][1]["cn"][0]
        netmask = int(subnetDN[0][1]["dhcpNetMask"][0])
        poolRange = self.getPoolRange(subnet)
        if poolRange:
            rangeStart, rangeEnd = poolRange
        if startAt: ip = startAt
        else: ip = network
        ip = ipNext(network, netmask, ip)
        while ip:
            if not self.ipExistsInSubnet(subnet, ip):
                if poolRange:
                    if not ipInRange(ip, rangeStart, rangeEnd):
                        ret = ip
                        break
                else:
                    ret = ip
                    break
            ip = ipNext(network, netmask, ip)
        return ret
Exemple #4
0
    def getSubnetFreeIp(self, subnet, startAt = None):
        """
        Return the first available IP address of a subnet.
        If startAt is given, start the search from this IP.

        IPs inside subnet dynamic pool range are never returned.

        If none available, return an empty string.

        @param subnet: subnet name in LDAP
        @type subnet: str

        @param startAt: IP to start search
        @type startAt: str
        """
        ret = ""
        subnetDN = self.getSubnet(subnet)
        network = subnetDN[0][1]["cn"][0]
        netmask = int(subnetDN[0][1]["dhcpNetMask"][0])
        poolRange = self.getPoolRange(subnet)
        if poolRange:
            rangeStart, rangeEnd = poolRange
        if startAt: ip = startAt
        else: ip = network
        ip = ipNext(network, netmask, ip)
        while ip:
            if not self.ipExistsInSubnet(subnet, ip):
                if poolRange:
                    if not ipInRange(ip, rangeStart, rangeEnd):
                        ret = ip
                        break
                else:
                    ret = ip
                    break
            ip = ipNext(network, netmask, ip)
        return ret