diff --git a/src/hostinfo.py b/src/hostinfo.py index 35641c4b5cf2d4df564a278d25abd6ceabd189c8..862f10a7b3c7b115796b6c14541cd67dfbf6c42b 100755 --- a/src/hostinfo.py +++ b/src/hostinfo.py @@ -76,6 +76,11 @@ if not hasattr(__builtins__, "True"): attr_weight = { ('host', 'name') : 1, + ('disk', 'host') : 1, + ('disk', 'root') : 2, + ('disk', 'id') : 3, + ('disk', 'size') : 4, + ('disk', 'format') : 5, ('interface', 'ip') : 1, ('interface', 'ether') : 2, ('subnet', 'network') : 1, @@ -155,6 +160,7 @@ tag_weight = { ('host', 'role') : (1, None), ('host', 'automount') : (2, lambda a,b: cmp(a.host[0],b.host[0])), ('host', 'mio') : (3, None), + ('host', 'qemu') : (4, None), ('interface', 'kickstart') : (1, None), ('interface', 'ip') : (2, None), ('interface', 'ipv6') : (3, None), diff --git a/src/hostinfo/automount.py b/src/hostinfo/automount.py index 283f22de8c537b9aae855d9c75ba153a4944393f..4b2a24f525c4cbe388b2a06a5af8cfed27e7dd6c 100755 --- a/src/hostinfo/automount.py +++ b/src/hostinfo/automount.py @@ -1,3 +1,5 @@ +import hostinfo.util as util + def generate(tree, auto_domain): result = [] result.append(("auto.home", auto_map(tree, 'auto.home', auto_domain))) @@ -6,19 +8,23 @@ def generate(tree, auto_domain): def auto_map(tree, map_name, auto_domain): auto = {} - for h in tree._host_: - for a in h._automount_: - if a.map[0] == map_name: - for e in a._entry_: - host = h.name[0] - if auto_domain: - host += auto_domain - path = '/'.join([a.root[0], e.path[0]]) - auto[e.key[0]] = "%s:%s" % (host, path) - ak = auto.keys() - ak.sort() + where = {} + for e in tree._host_._automount_._entry_: + if e.map[1] == map_name: + host = e.name[2] + key = e.key[0] + if auto_domain: + host += auto_domain + path = '/'.join([e.root[1], e.path[0]]) + if key in where: + raise util.HostinfoException( + 'Duplicate automount entries %s:%s' + % (map_name, key), + where=[e, where[key]]) + where[key] = e + auto[key] = "%s:%s" % (host, path) result = "" - for k in ak: + for k in sorted(auto): result += "%-15s %s\n" % (k, auto[k]) return result diff --git a/src/hostinfo/parser.py b/src/hostinfo/parser.py index 2c4e4a760a16e3f5525b2e27965ffe4bfa645946..2fbd4fdd48c68ec21ab63f41e473521310e8a221 100755 --- a/src/hostinfo/parser.py +++ b/src/hostinfo/parser.py @@ -521,7 +521,7 @@ class Parser: parent = self.current[-1] parent._add(Comment(data, self.parser.CurrentLineNumber)) -def parse(source, include_comments=False): +def parse(source, include_comments=False, url=None): """Parse the given 'source' returning an easily traversable tree""" (scheme, host, path, param, query, frag) = urlparse.urlparse(source) if not scheme: @@ -540,7 +540,7 @@ def parse(source, include_comments=False): pass pass pass - return Parser(data, url=source, mtime=mtime, + return Parser(data, url=url or source, mtime=mtime, include_comments=include_comments).tree def parse_string(source, include_comments=False): diff --git a/src/hostinfo/yp.py b/src/hostinfo/yp.py index ee9a3bc3ad0be08a392100f4bb9318290a72ba1a..6f8b12a279ba7b573b5b07f48f7966aad62f011b 100755 --- a/src/hostinfo/yp.py +++ b/src/hostinfo/yp.py @@ -1,5 +1,6 @@ #from hostinfo.util import fqn, aton, ntoa, by_ip, by_mac import hostinfo.util as util +from hostinfo.automount import auto_map def generate(tree, auto_domain): result = [] @@ -93,7 +94,8 @@ def netgroup(tree): return False return True for g in tree._host_._interface_._netgroup_: - for ip in filter(exclude, g._parent._ip_): + for ip in filter(exclude, + list(g._parent._ip_) + list(g._parent._ipv6_)): if not g.name[0:] in netgroup: netgroup[g.name[0:]] = [ ] pass @@ -102,7 +104,8 @@ def netgroup(tree): pass pass for k in tree._host_._interface_._kickstart_: - for ip in filter(exclude, k._parent._ip_): + for ip in filter(exclude, + list(k._parent._ip_) + list(k._parent._ipv6_)): entry = "(%s,,)" % util.fqn(tree, ip)[0:-1] key = "ks-%s" % k.file[0:] if not key in netgroup: @@ -127,22 +130,3 @@ def netgroup(tree): pass return result -def auto_map(tree, map_name, auto_domain): - auto = {} - for h in tree._host_: - for a in h._automount_: - if a.map[0] == map_name: - for e in a._entry_: - host = h.name[0] - if auto_domain: - host += auto_domain - path = '/'.join([a.root[0], e.path[0]]) - auto[e.key[0]] = "%s:%s" % (host, path) - ak = auto.keys() - ak.sort() - result = "" - for k in ak: - result += "%-15s %s\n" % (k, auto[k]) - return result - -