summaryrefslogtreecommitdiffstats
path: root/src/sbin
diff options
context:
space:
mode:
authorNarayan Desai <desai@mcs.anl.gov>2005-09-28 20:22:43 +0000
committerNarayan Desai <desai@mcs.anl.gov>2005-09-28 20:22:43 +0000
commit6524e283574659d46777d0b0ae05cfe7c808c861 (patch)
tree10c20e6183a570e42bb9a701d1b0346987144702 /src/sbin
parent65f2bc4937bd4d022521ec9028a09c6652c81b4f (diff)
downloadbcfg2-6524e283574659d46777d0b0ae05cfe7c808c861.tar.gz
bcfg2-6524e283574659d46777d0b0ae05cfe7c808c861.tar.bz2
bcfg2-6524e283574659d46777d0b0ae05cfe7c808c861.zip
fix fqdn matchups
no stdout, please 2005/09/28 15:05:27-05:00 anl.gov!desai speed up 2005/09/28 14:26:59-05:00 anl.gov!desai fix looping (Logical change 1.326) git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@1328 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/sbin')
-rw-r--r--src/sbin/GenerateHostInfo59
1 files changed, 31 insertions, 28 deletions
diff --git a/src/sbin/GenerateHostInfo b/src/sbin/GenerateHostInfo
index 547237bbc..d6fd69a25 100644
--- a/src/sbin/GenerateHostInfo
+++ b/src/sbin/GenerateHostInfo
@@ -7,25 +7,8 @@ __revision__ = '$Revision$'
from ConfigParser import ConfigParser
from elementtree.ElementTree import Element, SubElement, parse
-from os import system
-from socket import gethostbyname, gaierror
-
-def buildfqdncache(domain_list, host_list):
- '''build dictionary of hostname to fqdns'''
- fqdncache = {}
- for nodename in host_list:
- if nodename.count('.') > 0:
- fqdncache[nodename] = nodename
- fqdncache[nodename] = ""
- for domain in domain_list:
- try:
- fqdn = "%s.%s" % (nodename, domain)
- gethostbyname(fqdn)
- fqdncache[nodename] = fqdn
- break
- except gaierror:
- continue
- return fqdncache
+from os import system, fork, execl, dup2, wait
+import sys
def pretty_print(element, level=0):
'''Produce a pretty-printed text representation of element'''
@@ -55,17 +38,37 @@ if __name__ == '__main__':
metaElement = parse(metadatapath)
hostlist = [client.get('name') for client in metaElement.findall("Client")]
- fqdn_cache = buildfqdncache(domainlist, hostlist)
-
-
HostInfo = Element("HostInformation")
- for host in hostlist:
- record = SubElement(HostInfo, "HostInfo",
- attrib={"name" : host,"fqdn" : fqdn_cache[host]})
- if system( 'ping -c 1 ' + fqdn_cache[host] + ' &>/dev/null') != 0:
- record.set("pingable", 'N')
+ pids = {}
+ fullnames = {}
+ null = open('/dev/null', 'w+')
+ while hostlist or pids:
+ if hostlist and len(pids.keys()) < 15:
+ host = hostlist.pop()
+ pid = fork()
+ if pid == 0:
+ # in child
+ dup2(null.fileno(), sys.__stdin__.fileno())
+ dup2(null.fileno(), sys.__stdout__.fileno())
+ dup2(null.fileno(), sys.__stderr__.fileno())
+ execl('/bin/ping', 'ping', '-W', '5', '-c', '1', host)
+ else:
+ pids[pid] = host
else:
- record.set("pingable", 'Y')
+ try:
+ (cpid, status) = wait()
+ chost = pids[cpid]
+ del pids[cpid]
+ if status == 0:
+ SubElement(HostInfo, "HostInfo", name=chost, fqdn=chost, pingeable='Y')
+ else:
+ if chost.count('.') > 0:
+ fullnames[chost.split('.')[0]] = chost
+ hostlist.append(chost.split('.')[0])
+ else:
+ SubElement(HostInfo, "HostInfo", name=fullnames[chost], fqdn=fullnames[chost], pingeable='N')
+ except:
+ pass
fout = open(hostinfopath, 'w')
fout.write(pretty_print(HostInfo))