Exemple #1
0
    def deleteHost(self, host):
        """
        Delete host.

        @param host string: host
        """
        host = host.rstrip(".")
        map = self.map
        record = map.get(host)
        if not record:
            raise j.exceptions.RuntimeError("Invalid host name")

        for r in record:
            file = r["file"]
            old_ip = r["ip"]
            zone = dns.zone.from_file(file,
                                      os.path.basename(file),
                                      relativize=False)
            for k, v in zone.nodes.copy().items():
                if k.to_text() == "%s." % host:
                    zone.delete_node(k)
            # update version
            for k, v in zone.nodes.items():
                for ds in v.rdatasets:
                    if ds.rdtype == dns.rdatatype.SOA:
                        for item in ds.items:
                            item.serial += 1

            zone.to_file(file, relativize=False)
        self.restart()
Exemple #2
0
 def deleteHost(self, host):
     host = host.rstrip('.')
     map = self.map
     record = map.get(host)
     if not record:
         raise RuntimeError("Invalid host name")
     
     for r in record:
         file = r['file']
         old_ip = r['ip']
         zone = dns.zone.from_file(file, os.path.basename(file),relativize=False)
         for k, v in zone.nodes.copy().iteritems():
             if k.to_text() == "%s." % host:
                 zone.delete_node(k)
         # update version
         for k, v in zone.nodes.iteritems():
             for ds in v.rdatasets:
                 if ds.rdtype == dns.rdatatype.SOA:
                     for item in ds.items:
                         item.serial += 1
         
         zone.to_file(file, relativize=False)
     self.restart()
Exemple #3
0
        # fill instance node with SRV and TXT rdata
        for rec_type in ('srv', 'txt'):
            for r in zeroconf_results[key][rec_type]:
                inst_node.find_rdataset(dns.rdataclass.IN,
                                        dns.rdatatype.from_text(rec_type),
                                        create=True).add(dns.rdata.from_text(
                                            dns.rdataclass.IN,
                                            dns.rdatatype.from_text(rec_type),
                                            r),
                                                         ttl=ttl)

    # delete empty nodes in zone after iterating through all the results
    for name, node in zone.nodes.items():
        if not node.rdatasets:
            zone.delete_node(name)
    return zone


try:
    cgi_mode = True if 'GATEWAY_INTERFACE' in os.environ and \
        os.environ['GATEWAY_INTERFACE'].find('CGI') == 0 else False

    options = prepare_options(cgi_mode)

    sed_pattern, sed_repl = options.instname_sed \
        if options.instname_sed is not None else (None, None)

    results = zeroconf_search_multi(types=options.service,
                                    domains=options.domain,
                                    name=options.instance_name,
Exemple #4
0
print "Cogiendo la zona del dominio ", domain
zone_file = "%s" % domain

try:
    zone = dns.zone.from_file(zone_file, domain)
    print "Origen de la zona:", zone.origin

    for (name, ttl, rdata) in zone.iterate_rdatas(SOA):
        serial = rdata.serial
        new_serial = serial + 1
        print "Cambiando serial del SOA de %d a %d" % (serial, new_serial)
        rdata.serial = new_serial

    node_delete = "www2"
    print "Eliminando nodo", node_delete
    zone.delete_node(node_delete)

    A_change = "mail"
    new_IP = "192.168.2.100"
    print "Cambiando IPV4 del nodo", A_change, "al", new_IP
    rdataset = zone.find_rdataset(A_change, rdtype=A)
    for rdata in rdataset:
        rdata.address = new_IP

    rdataset = zone.find_rdataset("@", rdtype=NS)
    new_ttl = rdataset.ttl / 2
    print "Cambiando el TTL de todos los NS a", new_ttl
    rdataset.ttl = new_ttl

    A_add = "www3"
    print "Añadir nuevo nodo www3:", A_add
        # fill instance node with SRV and TXT rdata
        for rec_type in ('srv', 'txt'):
            for r in zeroconf_results[key][rec_type]:
                inst_node.find_rdataset(dns.rdataclass.IN,
                                        dns.rdatatype.from_text(rec_type),
                                        create=True).add(
                    dns.rdata.from_text(dns.rdataclass.IN,
                                        dns.rdatatype.from_text(rec_type),
                                        r),
                    ttl=ttl)

    # delete empty nodes in zone after iterating through all the results
    for name, node in zone.nodes.items():
        if not node.rdatasets:
            zone.delete_node(name)
    return zone


try:
    cgi_mode = True if 'GATEWAY_INTERFACE' in os.environ and \
        os.environ['GATEWAY_INTERFACE'].find('CGI') == 0 else False

    options = prepare_options(cgi_mode)

    sed_pattern, sed_repl = options.instname_sed \
        if options.instname_sed is not None else (None, None)

    results = zeroconf_search_multi(types=options.service,
                                    domains=options.domain,
                                    name=options.instance_name,