Commit 0c3508f1 authored by Anders Blomdell's avatar Anders Blomdell
Browse files

Version 2011-09-22 12:47

M  src/hostinfo.py
A  src/hostinfo/role.py
parent 1eaf1523
......@@ -11,6 +11,7 @@ import hostinfo.parser
import hostinfo.pxelinux
import hostinfo.samba
import hostinfo.yp
import hostinfo.role
import optparse
import os
import sys
......@@ -221,6 +222,9 @@ if __name__ == '__main__':
optParser.add_option("--dhcpd",
action="store", metavar="DIR",
help="generate DIR/dhcpd.conf file")
optParser.add_option("--ethers",
action="store", metavar="FILE",
help="Generate ethers FILE")
optParser.add_option("--ifconfig",
action="store", metavar="DIR",
help="Generate DIR/ifcfg-eth*")
......@@ -236,6 +240,9 @@ if __name__ == '__main__':
optParser.add_option("--named",
action="store", metavar="DIR",
help="Generate DIR/named.conf and DIR/named/*")
optParser.add_option("--netgroup",
action="store", metavar="FILE",
help="Generate netgroup FILE")
optParser.add_option("--next_server",
action="store", metavar="HOST",
help="Use HOST as DHCP next-server")
......@@ -245,6 +252,10 @@ if __name__ == '__main__':
optParser.add_option("--pxelinux",
action="store", metavar="DIR",
help="symlink DIR/<ethernet> to <kickstart>")
optParser.add_option("--role",
default=[],
action="append", metavar="ROLE",
help="check if machine has ROLE")
optParser.add_option("--samba",
action="store", metavar="FILE",
help="generate samba share FILE")
......@@ -287,6 +298,9 @@ if __name__ == '__main__':
file[name] = hostinfo.dhcpd.conf(tree, host, kickstart,
next_server=options.next_server)
if options.ethers:
file[options.ethers] = hostinfo.yp.ethers(tree)
if options.ifconfig:
for (f, c) in hostinfo.ifconfig.generate(tree, host):
file["%s/%s" % (options.ifconfig, f)] = c
......@@ -303,6 +317,9 @@ if __name__ == '__main__':
for (f, c) in hostinfo.named.generate(tree, host):
file["%s/%s" % (options.named, f)] = c
if options.netgroup:
file[options.netgroup] = hostinfo.yp.netgroup(tree)
if options.pxelinux:
ksinfo = ""
for (mac, host, ksfile) in hostinfo.pxelinux.generate(tree, host):
......@@ -315,6 +332,11 @@ if __name__ == '__main__':
result += tree._xml(attr_sort=attr_sort, tag_sort=tag_sort)
print result.encode("utf-8")
if options.role:
roles = hostinfo.role.generate(tree, host, options.role)
# print "Roles:",",".join(roles)
sys.exit(len(roles) != len(options.role))
if options.yp:
for (f, c) in hostinfo.yp.generate(tree, options.yp_auto_domain):
file["%s/%s" % (options.yp, f)] = c
......
def generate(tree, host, roles):
result = []
by_role = {}
for r in tree._host_._role_:
role = r.name[0]
if host == r.name[1] and role in roles:
result.append(role)
pass
if role in by_role:
raise Exception("Duplicate roles '%s' on %s, %s" %
(role, host, by_role[role]) )
by_role[role] = 1
pass
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