diff --git a/src/hostinfo/ifconfig.py b/src/hostinfo/ifconfig.py index 24c83cdbc0d0c333aee1bffc7bd62fd938ed6806..49d5e65f7a057bcfbd8aa17846e0885858d6754b 100755 --- a/src/hostinfo/ifconfig.py +++ b/src/hostinfo/ifconfig.py @@ -19,6 +19,14 @@ def generate(tree, host): s = subnet(tree, i.ip[0]) else: s = i._static_[0] + if s and s.name_servers[0]: + name_servers = re.split("[, ]+", s.name_servers[0]) + else: + name_servers = [] + if s: + for n in i._nameserver_: + if n.domain[0] == s.domain[0]: + name_servers = [i.ip[0]] + name_servers config += "BOOTPROTO=none\n" config += "IPADDR=%s\n" % i.ip[0] @@ -30,9 +38,9 @@ def generate(tree, host): config += "NETWORK=%s\n" % s.network[0] if s and s.broadcast[0]: config += "BROADCAST=%s\n" % s.broadcast[0] - if s and s.name_servers[0]: + if s and name_servers: ni = 0 - for n in re.split("[, ]+", s.name_servers[0]): + for n in name_servers: ni += 1 config += "DNS%d=%s\n" % (ni, n) if s and s.domain[0]: diff --git a/src/hostinfo/util.py b/src/hostinfo/util.py index 5867ac3926c393eb9badee32c2473d3639551789..19f1048b621353137a1dac1884f80e98272ea6d3 100755 --- a/src/hostinfo/util.py +++ b/src/hostinfo/util.py @@ -17,6 +17,8 @@ def fqn(tree, host): if (s.network[0] and aton(host.ip[0:]) & aton(s.netmask[0]) == aton(s.network[0])): return "%s.%s." % (host.name[1:],s.domain[0]) + raise Exception("No subnet declaration for %s (%s)" % + (host.name[0:], host.ip[0:])) else: raise Exception("'%s' not FQN, but has no ip" % host.name[0:])