summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoey Hagedorn <hagedorn@mcs.anl.gov>2006-01-10 17:48:22 +0000
committerJoey Hagedorn <hagedorn@mcs.anl.gov>2006-01-10 17:48:22 +0000
commite5e6fede58c1fbe1c9dfbfe8b535b5a39b9e6caf (patch)
tree5b450c8382b753e57776fecc0273dadb10c3ce4c
parent0f95b5db21e8a9247834befa21fe56b8d9f7e16e (diff)
downloadbcfg2-e5e6fede58c1fbe1c9dfbfe8b535b5a39b9e6caf.tar.gz
bcfg2-e5e6fede58c1fbe1c9dfbfe8b535b5a39b9e6caf.tar.bz2
bcfg2-e5e6fede58c1fbe1c9dfbfe8b535b5a39b9e6caf.zip
made changes to phase out GenerateHostInfo and Hostinfo.xml file. now uses clients.xml metadata file for ping info
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@1660 ce84e21b-d406-0410-9b95-82705330c041
-rw-r--r--src/sbin/GenerateHostInfo59
-rw-r--r--src/sbin/StatReports10
2 files changed, 25 insertions, 44 deletions
diff --git a/src/sbin/GenerateHostInfo b/src/sbin/GenerateHostInfo
index e6d166877..4b34ade89 100644
--- a/src/sbin/GenerateHostInfo
+++ b/src/sbin/GenerateHostInfo
@@ -6,42 +6,24 @@
__revision__ = '$Revision$'
from ConfigParser import ConfigParser
-from lxml.etree import Element, SubElement, parse
+from lxml.etree import Element, SubElement, parse, dump, tostring
from os import fork, execl, dup2, wait
import sys
-def pretty_print(element, level=0):
- '''Produce a pretty-printed text representation of element'''
- if element.text:
- fmt = "%s<%%s %%s>%%s</%%s>" % (level*" ")
- data = (element.tag, (" ".join(["%s='%s'" % keyval for keyval in element.attrib.iteritems()])),
- element.text, element.tag)
- children = element.getchildren()
- if children:
- fmt = "%s<%%s %%s>\n" % (level*" ",) + (len(children) * "%s") + "%s</%%s>\n" % (level*" ")
- data = (element.tag, ) + (" ".join(["%s='%s'" % (key, element.attrib[key]) for key in element.attrib]),)
- data += tuple([pretty_print(entry, level+2) for entry in children]) + (element.tag, )
- else:
- fmt = "%s<%%s %%s/>\n" % (level * " ")
- data = (element.tag, " ".join(["%s='%s'" % (key, element.attrib[key]) for key in element.attrib]))
- return fmt % data
-
-
if __name__ == '__main__':
c = ConfigParser()
c.read(['/etc/bcfg2.conf'])
configpath = "%s/etc/report-configuration.xml" % c.get('server', 'repository')
- #hostinfopath = "%s/etc/hostinfo.xml" % c.get('server', 'repository')
clientdatapath = "%s/Metadata/clients.xml" % c.get('server', 'repository')
sendmailpath = c.get('statistics','sendmailpath')
clientElement = parse(clientdatapath)
hostlist = [client.get('name') for client in clientElement.findall("Client")]
- #HostInfo = Element("HostInformation")
pids = {}
fullnames = {}
null = open('/dev/null', 'w+')
+
while hostlist or pids:
if hostlist and len(pids.keys()) < 15:
host = hostlist.pop()
@@ -57,22 +39,31 @@ if __name__ == '__main__':
else:
try:
(cpid, status) = wait()
- chost = pids[cpid]
- del pids[cpid]
- if status == 0:
- #SubElement(HostInfo, "HostInfo", name=chost, fqdn=chost, pingable='Y')
- clientElement.xpath("/Clients/Client[@name=%s]"%chost).set("pingable",'Y')
+ except OSError:
+ continue
+
+ chost = pids[cpid]
+ del pids[cpid]
+ if status == 0:
+ #if '-v' in sys.argv:
+ print "Alive: %s (fullname: %s):"%(chost,fullnames[chost])
+ #SubElement(HostInfo, "HostInfo", name=chost, fqdn=chost, pingable='Y')
+ clientElement.xpath("//Client[@name='%s']"%(fullnames[chost]))[0].set("pingable",'Y')
+ #also set pingtime, if you can get it
+ else:
+ if chost.count('.') > 0:
+ fullnames[chost.split('.')[0]] = chost
+ hostlist.append(chost.split('.')[0])
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], pingable='N')
- clientElement.xpath("/Clients/Client[@name=%s]"%chost).set("pingable",'N')
- except:
- pass
+ print "Dead: %s (fullname: %s):"%(chost,fullnames[chost])
+
+ #SubElement(HostInfo, "HostInfo", name=fullnames[chost], fqdn=fullnames[chost], pingable='N')
+ clientElement.xpath("//Client[@name='%s']"%(fullnames[chost]))[0].set("pingable",'N')
+ #also set pingtime if you can get it
+
+ dump(clientElement.getroot())
fout = open(clientdatapath, 'w')
- fout.write(pretty_print(clientElement))
+ fout.write(tostring(clientElement.getroot()))
fout.close()
diff --git a/src/sbin/StatReports b/src/sbin/StatReports
index d08d38a57..cb74eb4bb 100644
--- a/src/sbin/StatReports
+++ b/src/sbin/StatReports
@@ -150,7 +150,6 @@ if __name__ == '__main__':
c.read(['/etc/bcfg2.conf'])
configpath = "%s/etc/report-configuration.xml" % c.get('server', 'repository')
statpath = "%s/etc/statistics.xml" % c.get('server', 'repository')
- hostinfopath = "%s/etc/hostinfo.xml" % c.get('server', 'repository')
clientsdatapath = "%s/Metadata/clients.xml" % c.get('server', 'repository')
transformpath = "/usr/share/bcfg2/xsl-transforms/"
#websrcspath = "/usr/share/bcfg2/web-rprt-srcs/"
@@ -196,12 +195,6 @@ if __name__ == '__main__':
except (IOError, XMLSyntaxError):
print("StatReports: Failed to parse %s"%(clientsdatapath))
raise SystemExit, 1
- try:
- hostinfodata = XML(open(hostinfopath).read())
- except (IOError, XMLSyntaxError):
- print("StatReports: Failed to parse %s. Is GenerateHostInfo in your path?"%(hostinfopath))
- raise SystemExit, 1
-
#Merge data from three sources
nodereport = Element("Report", attrib={"time" : asctime()})
@@ -212,9 +205,6 @@ if __name__ == '__main__':
for client in clientsdata.findall("Client"):
nodel = Element("Node", attrib={"name" : client.get("name")})
nodel.append(client)
- for hostinfo in hostinfodata.findall("HostInfo"):
- if hostinfo.get("name") == client.get("name"):
- nodel.append(hostinfo)
for nod in statsdata.findall("Node"):
if client.get('name').find(nod.get('name')) == 0: