diff --git a/src/hostinfo.py b/src/hostinfo.py index 7968ff121d093456d4be5d84cd493b4ea20b7311..5a2f1d6bbf0f73922afcc5c4edabd0e4b71e8e8b 100755 --- a/src/hostinfo.py +++ b/src/hostinfo.py @@ -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 diff --git a/src/hostinfo/role.py b/src/hostinfo/role.py new file mode 100755 index 0000000000000000000000000000000000000000..bc6d8ee74ebc794e5d94155da41990d3903612e7 --- /dev/null +++ b/src/hostinfo/role.py @@ -0,0 +1,14 @@ +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