From 0e1c8de0dbcc6f4554bd1c0ecec8619a217922f0 Mon Sep 17 00:00:00 2001
From: Anders Blomdell <anders.blomdell@control.lth.se>
Date: Tue, 20 Sep 2005 15:58:02 +0200
Subject: [PATCH] Version 2005-09-20 15:58

M  src/hostinfo.py
A  src/hostinfo/macosx_auto.py
M  src/hostinfo/named.py
M  src/hostinfo/yp.py
---
 src/hostinfo.py             | 10 +++++++++-
 src/hostinfo/macosx_auto.py | 28 ++++++++++++++++++++++++++++
 src/hostinfo/named.py       |  5 +++--
 src/hostinfo/yp.py          | 22 +++++++++++++++-------
 4 files changed, 55 insertions(+), 10 deletions(-)
 create mode 100755 src/hostinfo/macosx_auto.py

diff --git a/src/hostinfo.py b/src/hostinfo.py
index e373e31..b42a260 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 0000000..18d2efb
--- /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 d6ab19f..7310824 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 c0e55b8..db5fcae 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 = ""
-- 
GitLab