Example #1
0
def getSubnetAndZoneFreeIp(subnet, zone, current = None):
    ret = ""
    dhcp = Dhcp()
    dns = Dns()
    ip = dhcp.getSubnetFreeIp(subnet, current)
    while ip:
        if not dns.ipExists(zone, ip):
            ret = ip
            break
        ip = dhcp.getSubnetFreeIp(subnet, ip)
    return ret
Example #2
0
def getSubnetAndZoneFreeIp(subnet, zone, current=None):
    ret = ""
    dhcp = Dhcp()
    dns = Dns()
    ip = dhcp.getSubnetFreeIp(subnet, current)
    while ip:
        if not dns.ipExists(zone, ip):
            ret = ip
            break
        ip = dhcp.getSubnetFreeIp(subnet, ip)
    return ret
Example #3
0
def setFailoverConfig(primaryIp,
                      secondaryIp,
                      serverPort=647,
                      peerPort=647,
                      delay=30,
                      update=10,
                      balance=3,
                      mclt=1800,
                      split=128):
    return Dhcp().setFailoverConfig(primaryIp, secondaryIp, serverPort,
                                    peerPort, delay, update, balance, mclt,
                                    split)
Example #4
0
def addZoneWithSubnet(zonename,
                      network,
                      netmask,
                      reverse=False,
                      description=None,
                      nameserver=None,
                      nameserverip=None):
    Dns().addZone(zonename, network, netmask, reverse, description, nameserver,
                  nameserverip)
    d = Dhcp()
    d.addSubnet(network, netmask, zonename)
    d.setSubnetOption(network, "domain-name", '"' + zonename + '"')
    if nameserverip:
        d.setSubnetOption(network, "domain-name-servers", nameserverip)
Example #5
0
def addSubnet(network, netmask, name):
    Dhcp().addSubnet(network, netmask, name)
Example #6
0
def setSubnetDescription(subnet, description):
    Dhcp().setSubnetDescription(subnet, description)
Example #7
0
def ipExistsInSubnet(subnet, ip):
    return Dhcp().ipExistsInSubnet(subnet, ip)
Example #8
0
def activate():
    config = NetworkConfig("network")
    logger = logging.getLogger()

    if config.disabled:
        logger.warning("Plugin network: disabled by configuration.")
        return False

    if not config.dhcpEnable and not config.dnsEnable:
        logger.warning("Plugin network: disabled by configuration.")
        return False

    try:
        ldapObj = ldapUserGroupControl()
    except ldap.INVALID_CREDENTIALS:
        logger.error("Can't bind to LDAP: invalid credentials.")
        return False

    if config.dhcpEnable:
        # Test if the DHCP/LDAP schema is available in the directory
        try:
            schema = ldapObj.getSchema("dhcpServer")
            if len(schema) <= 0:
                logger.error("DHCP schema is not included in LDAP directory")
                return False
            # Test if DHCP/LDAP schema contains the dhcpComments attribute
            if "dhcpComments" not in schema:
                logger.error(
                    "DHCP/LDAP schema does not support the dhcpComments attribute. Please use the latest version of DCHP/LDAP schema."
                )
                return False
        except:
            logger.exception("invalid schema")
            return False
    else:
        logger.info("DHCP submodule is disabled")

    if config.dnsEnable:
        # Test if the DNS/LDAP schema is available in the directory
        serverType = config.dnsType
        if serverType == "pdns":
            try:
                schema = ldapObj.getSchema("dNSDomain2")
                if len(schema) <= 0:
                    logger.error(
                        "DNS zone schema (dnsdomain2.schema) is not included in LDAP directory"
                    )
                    return False
            except:
                logger.exception("invalid DNS schema")
                return False
        elif serverType == "bind":
            try:
                schema = ldapObj.getSchema("dNSZone")
                if len(schema) <= 0:
                    logger.error(
                        "DNS zone schema (dnszone.schema) is not included in LDAP directory"
                    )
                    return False
            except:
                logger.exception("invalid DNS schema")
                return False
        else:
            logger.error("%s : Unknown DNS server." % serverType)
            return False
    else:
        logger.info("DNS submodule is disabled")

    if config.dhcpEnable:
        # Create DHCP ou
        head, path = config.dhcpDN.split(",", 1)
        ouName = head.split("=")[1]
        ldapObj.addOu(ouName, path)
        # Create DHCP config base structure
        d = Dhcp()
        try:
            d.addServiceConfig("DHCP config")
            logger.info("Created DHCP config object")
        except ldap.ALREADY_EXISTS:
            pass
        hostname = d.configDhcp.dhcpHostname
        try:
            d.addServer(hostname)
            d.setServiceConfigStatement("not", "authoritative")
            logging.info("The DHCP server '%s' was added." % hostname)
        except ldap.ALREADY_EXISTS:
            pass
        d.setServiceServerStatus(hostname, "primary")
        logging.info(
            "The server '%s' has been set as the primary DHCP server" %
            hostname)

    # Create DNS config base structure
    if config.dnsEnable:
        # Create DNS ou
        head, path = config.dnsDN.split(",", 1)
        ouName = head.split("=")[1]
        ldapObj.addOu(ouName, path)
        if serverType == "bind":
            try:
                gidNumber = grp.getgrnam(config.bindGroup)
            except KeyError:
                logger.error('The group "%s" does not exist.' %
                             config.bindGroup)
                return False
            gidNumber = gidNumber[2]

            try:
                os.mkdir(config.bindLdapDir)
                os.chmod(config.bindLdapDir, 02750)
                os.chown(config.bindLdapDir, -1, gidNumber)
            except OSError, e:
                # errno = 17 is "File exists"
                if e.errno != 17: raise

            if not os.path.exists(config.bindLdap):
                f = open(config.bindLdap, "w")
                f.close()
                os.chmod(config.bindLdap, 0640)
                os.chown(config.bindLdap, -1, gidNumber)
Example #9
0
def setHostHWAddress(subnet, host, address):
    Dhcp().setHostHWAddress(subnet, host, address)
Example #10
0
def getHost(subnet, host):
    return Dhcp().getHost(subnet, host)
Example #11
0
def addHostToSubnet(subnet, hostname):
    Dhcp().addHostToSubnet(subnet, hostname)
Example #12
0
def setHostOption(subnet, host, option, value=None):
    Dhcp().setHostOption(subnet, host, option, value)
Example #13
0
def getPool(poolname):
    return Dhcp().getPool(poolname)
Example #14
0
def setSubnetOption(subnet, option, value=None):
    Dhcp().setSubnetOption(subnet, option, value)
Example #15
0
def getSubnets(f):
    return Dhcp().getSubnets(f)
Example #16
0
def getSubnet(subnet):
    return Dhcp().getSubnet(subnet)
Example #17
0
def delSubnet(network):
    Dhcp().delSubnet(network)
Example #18
0
def setPoolRange(poolname, start, end):
    Dhcp().setPoolRange(poolname, start, end)
Example #19
0
def setSubnetNetmask(subnet, netmask):
    Dhcp().setSubnetNetmask(subnet, netmask)
Example #20
0
def delHost(subnet, hostname):
    Dhcp().delHost(subnet, hostname)
Example #21
0
def setSubnetAuthoritative(subnet, flag=True):
    Dhcp().setSubnetAuthoritative(subnet, flag)
Example #22
0
def setHostStatement(subnet, host, option, value=None):
    Dhcp().setHostStatement(subnet, host, option, value)
Example #23
0
def getSubnetHosts(network, filter):
    return Dhcp().getSubnetHosts(network, filter)
Example #24
0
def getHostHWAddress(subnet, host, address):
    Dhcp().getHostHWAddress(subnet, host, address)
Example #25
0
def getSubnetHostsCount(zone):
    return Dhcp().getSubnetHostsCount(zone)
Example #26
0
def hostExistsInSubnet(subnet, hostname):
    return Dhcp().hostExistsInSubnet(subnet, hostname)
Example #27
0
def getPoolsRanges(subnet):
    return Dhcp().getPoolsRanges(subnet)
Example #28
0
def getSubnetFreeIp(subnet, startAt):
    return Dhcp().getSubnetFreeIp(subnet, startAt)
Example #29
0
def setPoolsRanges(subnet, ranges):
    return Dhcp().setPoolsRanges(subnet, ranges)
Example #30
0
def addZoneWithSubnet(zonename, network, netmask, reverse = False, description = None, nameserver = None, nameserverip = None):
    Dns().addZone(zonename, network, netmask, reverse, description, nameserver, nameserverip)
    d = Dhcp()
    d.addSubnet(network, netmask, zonename)
    d.setSubnetOption(network, "domain-name", '"' + zonename +'"')
    if nameserverip: d.setSubnetOption(network, "domain-name-servers", nameserverip)
Example #31
0
def addPool(subnet, poolname, start, end):
    Dhcp().addPool(subnet, poolname, start, end)
Example #32
0
def activate():
    config = NetworkConfig("network")
    logger = logging.getLogger()

    if config.disabled:
        logger.warning("Plugin network: disabled by configuration.")
        return False

    try:
        ldapObj = ldapUserGroupControl()
    except ldap.INVALID_CREDENTIALS:
        logger.error("Can't bind to LDAP: invalid credentials.")
        return False

    # Test if the DHCP/LDAP schema is available in the directory
    try:
        schema = ldapObj.getSchema("dhcpServer")
        if len(schema) <= 0:
            logger.error("DHCP schema is not included in LDAP directory");
            return False
        # Test if DHCP/LDAP schema contains the dhcpComments attribute
        if "dhcpComments" not in schema:
            logger.error("DHCP/LDAP schema does not support the dhcpComments attribute. Please use the latest version of DCHP/LDAP schema.")
            return False
    except:
        logger.exception("invalid schema")
        return False

    # Test if the DNS/LDAP schema is available in the directory
    serverType = config.dnsType
    if serverType == "pdns":
        try:
            schema = ldapObj.getSchema("dNSDomain2")
            if len(schema) <= 0:
                logger.error("DNS zone schema (dnsdomain2.schema) is not included in LDAP directory");
                return False
        except:
            logger.exception("invalid DNS schema")
            return False
    elif serverType == "bind":
        try:
            schema = ldapObj.getSchema("dNSZone")
            if len(schema) <= 0:
                logger.error("DNS zone schema (dnszone.schema) is not included in LDAP directory");
                return False
        except:
            logger.exception("invalid DNS schema")
            return False
    else:
        logger.error("%s : Unknown DNS server."%serverType);
        return False

    # Create required OUs
    config = NetworkConfig("network")
    for dn in [config.dhcpDN, config.dnsDN]:
        head, path = dn.split(",", 1)
        ouName = head.split("=")[1]
        ldapObj.addOu(ouName, path)

    # Create DHCP config base structure
    d = Dhcp()
    try:
        d.addServiceConfig("DHCP config")
        logger.info("Created DHCP config object")
    except ldap.ALREADY_EXISTS:
        pass
    hostname = d.configDhcp.dhcpHostname
    try:
        d.addServer(hostname)
        d.setServiceConfigStatement("not", "authoritative")
        logging.info("The DHCP server '%s' was added." % hostname)
    except ldap.ALREADY_EXISTS:
        pass
    d.setServiceServerStatus(hostname, "primary")
    logging.info("The server '%s' has been set as the primary DHCP server" % hostname)

    # Create DNS config base structure
    if serverType == "bind":
        try:
            gidNumber = grp.getgrnam(config.bindGroup)
        except KeyError:
            logger.error('The group "%s" does not exist.' % config.bindGroup)
            return False
        gidNumber = gidNumber[2]

        try:
            os.mkdir(config.bindLdapDir)
            os.chmod(config.bindLdapDir, 02750)
            os.chown(config.bindLdapDir, -1, gidNumber)
        except OSError, e:
            # errno = 17 is "File exists"
            if e.errno != 17: raise

        if not os.path.exists(config.bindLdap):
            f = open(config.bindLdap, "w")
            f.close()
            os.chmod(config.bindLdap, 0640)
            os.chown(config.bindLdap, -1, gidNumber)
Example #33
0
def delPool(poolname):
    Dhcp().delPool(poolname)