Commit d7f3da2b authored by Anders Blomdell's avatar Anders Blomdell
Browse files

Version 2014-01-31 11:45

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