Skip to content
Snippets Groups Projects
Commit 522ba9d6 authored by Anders Blomdell's avatar Anders Blomdell
Browse files

Version 2006-05-05 11:58

M  src/hostinfo.py
M  src/hostinfo/named.py
A  src/hostinfo/samba.py
parent 0e1c8de0
Branches
No related tags found
No related merge requests found
......@@ -7,6 +7,7 @@ import hostinfo.macosx_auto
import hostinfo.mio
import hostinfo.named
import hostinfo.parser
import hostinfo.samba
import hostinfo.yp
import optparse
import os
......@@ -145,10 +146,13 @@ def tag_sort(parent, a, b):
return None
if __name__ == '__main__':
optParser = VerboseOptionParser(usage="%prog [options] targets*")
optParser = VerboseOptionParser(usage="%prog [options] [hostinfo]")
optParser.add_option("--host",
action="store",
help="The host to generate information for")
optParser.add_option("--dfs",
action="store", metavar="DIR",
help="generate DIR/*/(dfslink|autolink)")
optParser.add_option("--dhcpd",
action="store", metavar="DIR",
help="generate DIR/dhcpd.conf file")
......@@ -167,6 +171,9 @@ if __name__ == '__main__':
optParser.add_option("--pretty",
action="store_true", default=False,
help="pretty-print XML tree")
optParser.add_option("--samba",
action="store", metavar="FILE",
help="generate samba share FILE")
optParser.add_option("--yp",
action="store", metavar="DIR",
help="generate DIR/{hosts,ethers} information")
......@@ -184,6 +191,11 @@ if __name__ == '__main__':
raise Exception("Only one hostinfo file allowed")
file = {}
symlink = {}
if options.dfs:
for (f, c) in hostinfo.samba.msdfs(tree):
symlink["%s/%s" % (options.dfs, f)] = c
if options.dhcpd:
file["%s/dhcpd.conf" % options.dhcpd] = hostinfo.dhcpd.conf(tree, host)
......@@ -213,6 +225,9 @@ if __name__ == '__main__':
for (f, c) in hostinfo.yp.generate(tree):
file["%s/%s" % (options.yp, f)] = c
if options.samba:
file[options.samba] = hostinfo.samba.share(tree, host)
result = 1
for name in file.keys():
write = False
......@@ -231,4 +246,17 @@ if __name__ == '__main__':
f.write(file[name].encode("iso8859-1"))
f.close()
for name in symlink.keys():
if os.path.lexists(name) and not os.path.islink(name):
print "'%s' esists but is not a link"
elif not os.path.lexists(name):
print "Creating '%s' -> '%s'" % (name, symlink[name])
os.symlink(symlink[name], name)
result = 0
elif os.readlink(name) != symlink[name]:
print "Changing '%s' -> '%s'" % (name, symlink[name])
os.unlink(name)
os.symlink(symlink[name], name)
result = 0
sys.exit(result)
......@@ -30,6 +30,11 @@ def generate(tree, host):
conf = "include \"/etc/rndc.key\";\n"
conf += "options {\n"
conf += " directory \"/etc/named\"; notify no;\n"
conf += " forward first;\n"
conf += " forwarders {\n"
conf += " 130.235.20.3;\n"
conf += " 130.235.132.90;\n"
conf += " };\n"
conf += "};\n"
conf += "zone \".\" {\n"
conf += " type hint; file \"root.hints\"; \n"
......
from hostinfo.util import fqn
def msdfs(tree):
result = []
result.extend(dfs(tree, 'home', '/home', 'auto.home'))
result.extend(dfs(tree, 'work', '/work', 'auto.work'))
return result
def share(tree, host):
result = ""
for h in [h for h in tree._host_ if h.name[0] == host]:
for a in [a for a in h._automount_ if a.samba[0]]:
result += "\n".join([
"[%s]" % a.samba[0],
" browseable = no",
" path = %s" % a.root[0],
" writable = yes",
" create mode = 0664",
" directory mode = 0775"
])
result += "\n\n"
return result
def dfs(tree, dir, mount, map_name):
auto = []
for h in tree._host_:
for a in h._automount_:
if a.map[0] == map_name:
for e in a._entry_:
if a.samba[0]:
link = "msdfs:%s/%s/%s" % (h.name[0], a.samba[0],
e.path[0])
link = link.replace('/', '\\')
else:
link = "%s/%s" % (mount, e.key[0])
auto.append(('%s/%s' % (dir, e.key[0]), link))
return auto
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment