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"):
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),
......
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
......
......@@ -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):
......
#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
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