summaryrefslogtreecommitdiffstats
path: root/src/sbin/bcfg2-ping-sweep
diff options
context:
space:
mode:
authorNarayan Desai <desai@mcs.anl.gov>2006-09-15 02:41:44 +0000
committerNarayan Desai <desai@mcs.anl.gov>2006-09-15 02:41:44 +0000
commitf156b115bd7b0868e36f62573d75f51e756b29ae (patch)
tree18370935349782eb3dd008add6949358ba733fc5 /src/sbin/bcfg2-ping-sweep
parenta6781fdff0e1ede8ed3bed5a2886127c9a42b408 (diff)
downloadbcfg2-f156b115bd7b0868e36f62573d75f51e756b29ae.tar.gz
bcfg2-f156b115bd7b0868e36f62573d75f51e756b29ae.tar.bz2
bcfg2-f156b115bd7b0868e36f62573d75f51e756b29ae.zip
Rename GenerateHostInfo to bcfg2-ping-sweep
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@2255 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/sbin/bcfg2-ping-sweep')
-rwxr-xr-xsrc/sbin/bcfg2-ping-sweep63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/sbin/bcfg2-ping-sweep b/src/sbin/bcfg2-ping-sweep
new file mode 100755
index 000000000..ddb8c36e8
--- /dev/null
+++ b/src/sbin/bcfg2-ping-sweep
@@ -0,0 +1,63 @@
+#!/usr/bin/env python
+#GenerateHostInfo - Joey Hagedorn - hagedorn@mcs.anl.gov
+
+'''Generates hostinfo.xml at a regular interval'''
+__revision__ = '$Revision$'
+
+from os import dup2, execl, fork, uname, wait
+import lxml.etree, sys, time, ConfigParser
+
+if __name__ == '__main__':
+ c = ConfigParser.ConfigParser()
+ c.read(['/etc/bcfg2.conf'])
+ configpath = "%s/etc/report-configuration.xml" % c.get('server', 'repository')
+ clientdatapath = "%s/Metadata/clients.xml" % c.get('server', 'repository')
+
+ clientElement = lxml.etree.parse(clientdatapath)
+ hostlist = [client.get('name') for client in clientElement.findall("Client")]
+
+ pids = {}
+ null = open('/dev/null', 'w+')
+
+ #use uname to detect OS and use -t for darwin and -w for linux
+ #/bin/ping on linux /sbin/ping on os x
+ osname = uname()[0]
+
+
+ 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())
+ if osname == 'Linux':
+ execl('/bin/ping', 'ping', '-w', '5', '-c', '1', host)
+ elif osname == 'Darwin':
+ execl('/sbin/ping', 'ping', '-t', '5', '-c', '1', host)
+ elif osname == 'SunOS':
+ execl('/usr/sbin/ping', 'ping', host, '56', '1')
+ else: #default
+ execl('/bin/ping', 'ping', '-w', '5', '-c', '1', host)
+ else:
+ pids[pid] = host
+ else:
+ try:
+ (cpid, status) = wait()
+ except OSError:
+ continue
+ chost = pids[cpid]
+ del pids[cpid]
+ elm = clientElement.xpath("//Client[@name='%s']"%chost)[0]
+ if status == 0:
+ elm.set("pingable",'Y')
+ elm.set("pingtime", str(time.time()))
+ else:
+ elm.set("pingable",'N')
+
+ fout = open(clientdatapath, 'w')
+ fout.write(lxml.etree.tostring(clientElement.getroot()))
+ fout.close()
+