def deploy_dns(comm, opts): """Put inital data to DNS database and configure DNS server. @param comm a communicator. The following proxies should be available: - Tartarus.deployPrx.Server of type Tartarus::DNS::Server - Tartarys.deployPrx.DNSService of type Tartarus::core::Service @param opts a dictionary {name, value}. The following options are used: *Name* *Type* *Madatory* *Comment* domain String M n/a ip String M n/a hostname String M n/a mask Int M n/a """ prx = comm.propertyToProxy('Tartarus.deployPrx.DNSService') _checked_configure(prx, opts.get('dns_force')) prx = comm.propertyToProxy('Tartarus.deployPrx.DNS') srv = DNS.ServerPrx.checkedCast(prx) _process_zones(srv, _LOCAL_DATA) domain = opts['domain'] ns = 'ns.' + domain krb = 'kerberos.' + domain ip = opts['ip'] fqdn = opts['hostname'] hostmaster = '%s.%s' % (opts['name'], domain) z = srv.createZone(domain, SOA(ns, hostmaster, 0, 43200, 3600, 604800, 3600)) records = [ R(domain, T.NS, ns, -1, -1), R(domain, T.A, ip, -1, -1), R(krb, T.CNAME, fqdn, -1, -1), R('_kerberos._udp.' + domain, T.SRV, '0 88 ' + krb, 0, -1), R('_kerberos._tcp.' + domain, T.SRV, '0 88 ' + krb, 0, -1), R('_kpasswd._udp.' + domain, T.SRV, '0 464 ' + krb, 0, -1), R('_kerberos-adm._tcp.' + domain, T.SRV, '0 749 ' + krb, 0, -1), R('_kerberos.' + domain, T.TXT, domain.upper(), -1, -1), ] if fqdn != domain: records.append(R(fqdn, T.A, ip, -1, -1)) if ns != domain and ns != fqdn: records.append(R(ns, T.CNAME, fqdn, -1, -1)) z.addRecords(records) rzone = _reverse_zone_name(ip, opts['mask']) z = srv.createZone(rzone, SOA(ns, hostmaster, 0, 43200, 3600, 604800, 3600)) z.addRecords([R(rzone, T.NS, ns, -1, -1), _ptr_record(ip, fqdn, rzone)]) srv_opts = [] if 'recursor' in opts: srv_opts.append(DNS.ServerOption('recursor', opts['recursor'])) if 'allow_recursion' in opts: srv_opts.append( DNS.ServerOption('allow-recursion', opts['allow_recursion'])) srv.setOptions(srv_opts)
def test(com, server): for opt in server.getOptions(): print "%s=%s" % (opt.name, opt.value) server.changeOptions([DNS.ServerOption('recursor', '192.168.33.1')]) for opt in server.getOptions(): print "%s=%s" % (opt.name, opt.value) server.changeOptions([DNS.ServerOption('recursor', '')]) for opt in server.getOptions(): print "%s=%s" % (opt.name, opt.value)
def test(com, server): d = server.getZone('asdffdsa.org') oldr = DNS.Record( name='bar.asdffdsa.org.', type=DNS.RecordType.A, data='192.168.44.28', ttl=-1, prio=-1 # ingored ) newr = DNS.Record(name='bar.asdffdsa.org.', type=DNS.RecordType.A, data='192.168.44.27', ttl=-1, prio=-1) newr.data = '192.168.44.27' d.replaceRecord(oldr, newr)
def dns_deploy(wiz): wiz.dialog.info('Configuring DNS...') opts = wiz.opts wiz.dns_service.configure({'force': 'force'}) prx = wiz.comm.propertyToProxy('Tartarus.deployPrx.DNS') srv = DNS.ServerPrx.checkedCast(prx) _process_zones(srv, _LOCAL_DATA) domain = opts['domain'] ns = 'ns.' + domain krb = 'kerberos.' + domain ip = opts['ip'] fqdn = opts['hostname'] hostmaster = opts['hostmaster'] z = srv.createZone(domain, SOA(ns, hostmaster, 0, 43200, 3600, 604800, 3600)) records = [ R(domain, T.NS, ns, -1, -1), R(domain, T.A, ip, -1, -1), R(krb, T.CNAME, fqdn, -1, -1), R('_kerberos._udp.' + domain, T.SRV, '0 88 ' + krb, 0, -1), R('_kerberos._tcp.' + domain, T.SRV, '0 88 ' + krb, 0, -1), R('_kpasswd._udp.' + domain, T.SRV, '0 464 ' + krb, 0, -1), R('_kerberos-adm._tcp.' + domain, T.SRV, '0 749 ' + krb, 0, -1), R('_kerberos.' + domain, T.TXT, domain.upper(), -1, -1), ] if fqdn != domain: records.append(R(fqdn, T.A, ip, -1, -1)) if ns != domain and ns != fqdn: records.append(R(ns, T.CNAME, fqdn, -1, -1)) z.addRecords(records) rzone = _reverse_zone_name(ip, opts['mask']) z = srv.createZone(rzone, SOA(ns, hostmaster, 0, 43200, 3600, 604800, 3600)) z.addRecords([R(rzone, T.NS, ns, -1, -1), _ptr_record(ip, fqdn, rzone)]) srv_opts = [] if 'recursor' in opts: srv_opts.append(DNS.ServerOption('recursor', opts['recursor'])) if 'allow_recursion' in opts: srv_opts.append( DNS.ServerOption('allow-recursion', opts['allow_recursion'])) srv.setOptions(srv_opts)
def test(com, server): d = server.getZone('asdffdsa.org') d.dropRecord(DNS.Record( name='bar.asdffdsa.org.', type=DNS.RecordType.A, data='192.168.44.28', ttl=-1, prio=-1 # ingored ))
def test(com, server): d = server.getZone('asdffdsa.org') d.addRecord( DNS.Record(name='bar.asdffdsa.org.', type=DNS.RecordType.A, data='192.168.44.28', ttl=84600, prio=0))
def getSOA(self, con, current): cur = self._dbh.execute( con, "SELECT content FROM records " "WHERE type='SOA' and domain_id=%s", utils.name(current)) res = cur.fetchall() if len(res) != 1: raise utils.NoSuchObject return I.SOARecord(*utils.str2soar(res[0][0]))
def _pack_records(self, qresult): return [ I.Record(name=n, type=I.RecordType.__dict__[t], data=c, ttl=(ttl if ttl else -1), prio=(prio if prio else -1)) for n, t, c, ttl, prio in qresult ]
def test(com, server): soar = DNS.SOARecord(nameserver='localhost.', hostmaster='nobody.asdffdsa.org', serial=0, refresh=43200, retry=3600, expire=604800, ttl=3600) d = server.createZone('asdffdsa.org', soar) print d.getName()
def test(com, server): d = server.getZone('asdffdsa.org') records = [ DNS.Record(name="xx%d.asdffdsa.org." % num, type=DNS.RecordType.A, data='192.168.44.%d' % num, ttl=-1, prio=-1) for num in xrange(44, 55) ] d.addRecords(records)
def _ptr_record(ip, fqdn, zone): """Make PTR record from ip, host fqdn and reverse zone name. zone is in form of [[b.]c.]d.in-addr.arpa (without a terminating dot) """ octets = ip.split('.') octets.reverse() if len(octets) != 4: raise DNS.ConfigError('Invalud IPv4 adress', ip) n = zone.count('.') if n < 2: raise C.ConfigError('Invalid reverse zone name', zone) elif n > 4: name = octets[0] + '.' else: name = '.'.join(octets[:(5 - n)]) + '.' return DNS.Record(name + zone, DNS.RecordType.PTR, fqdn, -1, -1)
def getOptions(self, current): try: return [ I.ServerOption(*pair) for pair in cfgfile.parse(self._config_file) if pair[0] in self._supported_options ] except IOError: raise ICore.ConfigError("Failed to read configuration file", self._config_file)
def _mask2octets(mask): """Get a number of significant octetns in network address. The only argument is a network mask (an integer). """ if isinstance(mask, basestring): mask = int(mask) if mask < 8 or mask >= 32: raise DNS.ConfigError("Wrong network mask", str(mask)) if mask == 8: return 1 if 8 < mask <= 16: return 2 else: return 3
def test(com, server): d = server.getZone('asdffdsa.org') soar = DNS.SOARecord( nameserver='asdffdsa.org', hostmaster='nobody.asdffdsa.org', serial=0, refresh=43200, retry=3600, expire=604800, ttl=3600 ) d.setSOA(soar) soar.hostmaster='root.asdffdsa.org' d.setSOA(soar) print d.getSOA()