diff --git a/src/hostinfo.py b/src/hostinfo.py index e373e311451597f68bbfcd28f1ace1b066df4940..b42a260da9451731ddc080c53d518007636ba030 100755 --- a/src/hostinfo.py +++ b/src/hostinfo.py @@ -1,8 +1,9 @@ -#!/usr/bin/python2 +#!/usr/bin/python import copy import hostinfo.dhcpd import hostinfo.ifconfig +import hostinfo.macosx_auto import hostinfo.mio import hostinfo.named import hostinfo.parser @@ -154,6 +155,9 @@ if __name__ == '__main__': optParser.add_option("--ifconfig", action="store", metavar="DIR", help="Generate DIR/ifcfg-eth*") + optParser.add_option("--macosx_auto", + action="store", metavar="DIR", + help="Generate MacOSX autmount maps") optParser.add_option("--mio", action="store_true", default=False, help="output mio tree") @@ -187,6 +191,10 @@ if __name__ == '__main__': for (f, c) in hostinfo.ifconfig.generate(tree, host): file["%s/%s" % (options.ifconfig, f)] = c + if options.macosx_auto: + for (f, c) in hostinfo.macosx_auto.generate(tree): + file["%s/%s" % (options.macosx_auto, f)] = c + if options.mio: mio = hostinfo.mio.generate(tree) print mio.encode("iso8859-1") diff --git a/src/hostinfo/macosx_auto.py b/src/hostinfo/macosx_auto.py new file mode 100755 index 0000000000000000000000000000000000000000..18d2efb697ef7ffc55b43141467fad4dbd16a956 --- /dev/null +++ b/src/hostinfo/macosx_auto.py @@ -0,0 +1,28 @@ +from hostinfo.util import fqn + +def generate(tree): + maps = {} + for am in tree._host_._automount_: + maps[am.map[0]] = am.map[0] + + result = [] + for m in maps.keys(): + result.append((m, auto_map(tree, m))) + return result + +def auto_map(tree, map_name): + auto = {} + for h in tree._host_: + for a in h._automount_: + if a.map[0] == map_name: + for e in a._entry_: + path = '/'.join([a.root[0], e.path[0]]) + auto[e.key[0]] = "%s:%s" % (h.name[0],path) + ak = auto.keys() + ak.sort() + result = "" + for k in ak: + result += "%-15s rw,resvport,nosuid %s\n" % (k, auto[k]) + return result + + diff --git a/src/hostinfo/named.py b/src/hostinfo/named.py index d6ab19f2e133c0d7cd30beecb9d148cae3f96639..7310824867e89472167c4e8f6053be1c65363def 100755 --- a/src/hostinfo/named.py +++ b/src/hostinfo/named.py @@ -93,7 +93,7 @@ def header(tree, domain, origin=None): result += ";\n" for ns in tree._host_._interface_._nameserver_: - if ns.domain[0] == domain: + if ns.domain[0] == domain and ns.primary[0] == 'yes': result += " IN NS %s\n" % fqn(tree, ns) result += ";\n" @@ -178,7 +178,8 @@ def reverse_local(tree, nameserver): if ns.name[0:] == nameserver: h = copy.copy(ns._parent._parent) i = copy.copy(ns._parent) - i._add(hostinfo.parser.Node("nameserver")) + print h.name[0] + i._add(hostinfo.parser.Node("nameserver", attr={"primary":"yes"})) h._add(i) t._add(h) break diff --git a/src/hostinfo/yp.py b/src/hostinfo/yp.py index c0e55b85733d2a06c127c9b743a25f6b2f059a8d..db5fcaeb364ef66b373b3099ff157fa7ede9ed1a 100755 --- a/src/hostinfo/yp.py +++ b/src/hostinfo/yp.py @@ -15,6 +15,8 @@ def hosts(tree): for i in tree._host_._interface_: if i.ip[0]: host[i.ip[0]] = i.name[0:] + for a in i._alias_: + host[i.ip[0]] += " %s" % a.name[0] key = host.keys() key.sort(by_ip) for k in key: @@ -26,11 +28,16 @@ def ethers(tree): host = {} for i in tree._host_._interface_: if i.ethernet[0]: - host[i.ethernet[0]] = i.name[0:] + host[i.ethernet[0]] = [ i.name[0:] ] + try: + host[i.ethernet[0]].append(fqn(tree, i)[0:-1]) + except: + pass key = host.keys() key.sort(by_mac) for k in key: - result += "%-15s %s\n" % (k, host[k]) + for h in host[k]: + result += "%-15s %s\n" % (k, h) return result def netgroup(tree): @@ -67,11 +74,12 @@ def netgroup(tree): def auto_map(tree, map_name): auto = {} - for a in tree._host_._automount_: - if a.map[0] == map_name: - for e in a._entry_: - auto[e.key[0]] = "%s:%s" % (a.host[0],e.path[0]) - + for h in tree._host_: + for a in h._automount_: + if a.map[0] == map_name: + for e in a._entry_: + path = '/'.join([a.root[0], e.path[0]]) + auto[e.key[0]] = "%s:%s" % (h.name[0],path) ak = auto.keys() ak.sort() result = ""