Commit 453b57b1 authored by Anders Blomdell's avatar Anders Blomdell
Browse files

Add compare function to files, filter out serial number from named zone files when comparing

parent eae03a6c
......@@ -283,34 +283,34 @@ if __name__ == '__main__':
if options.automount:
for (f, c) in hostinfo.automount.generate(tree,options.auto_domain):
file["%s/%s" % (options.automount, f)] = c
file["%s/%s" % (options.automount, f)] = (c, None)
if options.dhcpd:
file["%s/dhcpd.conf" % options.dhcpd] = hostinfo.dhcpd.generate(
tree, options)
file["%s/dhcpd.conf" % options.dhcpd] = (
hostinfo.dhcpd.generate(tree, options), None)
pass
if options.dhcpd6:
file["%s/dhcpd6.conf" % options.dhcpd6] = hostinfo.dhcpd_ipv6.generate(
tree, options)
file["%s/dhcpd6.conf" % options.dhcpd6] = (
hostinfo.dhcpd_ipv6.generate(tree, options))
pass
if options.ethers:
file[options.ethers] = hostinfo.yp.ethers(tree)
file[options.ethers] = (hostinfo.yp.ethers(tree), None)
if options.ifconfig:
for (f, c) in hostinfo.ifconfig.generate(tree, host):
file["%s/%s" % (options.ifconfig, f)] = c
file["%s/%s" % (options.ifconfig, f)] = (c, None)
if options.kickstart_info:
ksinfo = ""
for (mac, host, ksfile) in hostinfo.pxelinux.generate(tree, host):
ksinfo += "%s %s %s\n" % (mac, host, ksfile)
file[options.kickstart_info] = ksinfo
file[options.kickstart_info] = (ksinfo, None)
if options.macosx_auto:
for (f, c) in hostinfo.macosx_auto.generate(tree):
file["%s/%s" % (options.macosx_auto, f)] = c
file["%s/%s" % (options.macosx_auto, f)] = (c, None)
if options.mio:
mio = hostinfo.mio.generate(tree)
......@@ -323,11 +323,11 @@ if __name__ == '__main__':
pass
if options.named:
for (f, c) in hostinfo.named.generate(tree, options):
file["%s/%s" % (options.named, f)] = c
for (f, c, e) in hostinfo.named.generate(tree, options):
file["%s/%s" % (options.named, f)] = (c, e)
if options.netgroup:
file[options.netgroup] = hostinfo.yp.netgroup(tree)
file[options.netgroup] = tuple(hostinfo.yp.netgroup(tree), None)
if options.pretty:
result = "<?xml version='1.0' encoding='utf-8'?>\n\n"
......@@ -353,10 +353,10 @@ if __name__ == '__main__':
if options.yp:
for (f, c) in hostinfo.yp.generate(tree, options.yp_auto_domain):
file["%s/%s" % (options.yp, f)] = c
file["%s/%s" % (options.yp, f)] = (c, None)
if options.samba:
file[options.samba] = hostinfo.samba.share(tree, host)
file[options.samba] = (hostinfo.samba.share(tree, host), None)
result = 1
for name in file.keys():
......@@ -365,7 +365,14 @@ if __name__ == '__main__':
f = open(name)
conf = f.read()
f.close()
write = conf != file[name]
content, equal = file[name]
if equal == None:
write = conf != content
pass
else:
write = not equal(conf, content)
pass
pass
except IOError as e:
write = True
......@@ -373,7 +380,7 @@ if __name__ == '__main__':
print(name)
result = 0
f = open(name, "w")
f.write(file[name])
f.write(file[name][0])
f.close()
for name in symlink.keys():
......
......@@ -12,6 +12,20 @@ class NoNameserverException(Exception):
class InvalidHostnameException(Exception):
pass
def equal_zone(c1, c2):
for l1, l2 in zip(c1.split('\n'), c2.split('\n')):
if l1 == l2:
continue
else:
m1 = re.match('^\s*[0-9]+\s*;\s*Serial\s*$', l1)
m2 = re.match('^\s*[0-9]+\s*;\s*Serial\s*$', l2)
if m1 and m2:
continue
else:
return False
pass
pass
return True
def generate(tree, options):
#
......@@ -51,17 +65,17 @@ def generate(tree, options):
|zone \"%(name)s\" {
| type master; file \"hosts-%(name)s\";
|};""" % dict(name=f))
result.append(("named/hosts-%s" % f, str(forward[f])))
result.append(("named/hosts-%s" % f, str(forward[f]), equal_zone))
pass
for r in [ r for r in sorted(reverse) if reverse[r] ]:
conf.append_lines("""
|zone \"%(name)s\" {
| type master; file \"%(name)s\";
|};""" % dict(name=r))
result.append(("named/%s" % r, str(reverse[r])))
result.append(("named/%s" % r, str(reverse[r]), equal_zone))
pass
result.append(("named.conf", str(conf)))
result.append(("named.conf", str(conf), None))
return result
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment