summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNarayan Desai <desai@mcs.anl.gov>2008-08-06 19:12:44 +0000
committerNarayan Desai <desai@mcs.anl.gov>2008-08-06 19:12:44 +0000
commit8bec0056b9d8f1accb9cbaa485c6011980d381df (patch)
treeb496838e3693b1ff0302a57db2053cf3923a50f8 /src
parent42ce77fd3274783e17a4f4b619d052f427d25099 (diff)
downloadbcfg2-8bec0056b9d8f1accb9cbaa485c6011980d381df.tar.gz
bcfg2-8bec0056b9d8f1accb9cbaa485c6011980d381df.tar.bz2
bcfg2-8bec0056b9d8f1accb9cbaa485c6011980d381df.zip
Switch bcfg2-admin minestruct to use the new statistics api to get at data in either of statistics.xml or dbstats directly
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@4862 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src')
-rw-r--r--src/lib/Server/Admin/Minestruct.py28
-rw-r--r--src/lib/Server/Plugins/DBStats.py6
-rw-r--r--src/lib/Server/Plugins/Statistics.py6
3 files changed, 20 insertions, 20 deletions
diff --git a/src/lib/Server/Admin/Minestruct.py b/src/lib/Server/Admin/Minestruct.py
index 61a277d2d..b63bdd2b5 100644
--- a/src/lib/Server/Admin/Minestruct.py
+++ b/src/lib/Server/Admin/Minestruct.py
@@ -2,14 +2,11 @@
import Bcfg2.Server.Admin
import lxml.etree
-class Minestruct(Bcfg2.Server.Admin.Mode):
+class Minestruct(Bcfg2.Server.Admin.StructureMode):
'''Pull extra entries out of statistics'''
__shorthelp__ = 'bcfg2-admin minestruct <client> [-f file-name] [-g groups]'
__longhelp__ = __shorthelp__ + '\n\tExtract extra entry lists from statistics'
- def __init__(self, cfile):
- Bcfg2.Server.Admin.Mode.__init__(self, cfile)
-
def __call__(self, args):
Bcfg2.Server.Admin.Mode.__call__(self, args)
if len(args) == 0:
@@ -43,19 +40,13 @@ class Minestruct(Bcfg2.Server.Admin.Mode):
continue
else:
client = arg
- stats = self.load_stats(client)
- if len(stats.getchildren()) == 2:
- # client is dirty
- current = [ent for ent in stats.getchildren() if ent.get('state') == 'dirty'][0]
- else:
- current = stats.getchildren()[0]
- extra = current.find('Extra').getchildren()
+ extra = self.statistics.GetExtra(client)
root = lxml.etree.Element("Base")
self.log.info("Found %d extra entries" % (len(extra)))
if len(groups) == 0:
- for entry in extra:
- self.log.info("%s: %s" % (entry.tag, entry.get('name')))
- root.append(lxml.etree.Element(entry.tag, name=entry.get('name')))
+ for tag, name in extra:
+ self.log.info("%s: %s" % (tag, name))
+ lxml.etree.SubElement(root, tag, name=name)
else:
groups_root = lxml.etree.Element("Group", name=groups[0])
root.append(groups_root)
@@ -64,8 +55,9 @@ class Minestruct(Bcfg2.Server.Admin.Mode):
groups_root.append(temp)
groups_root = temp
for entry in extra:
- self.log.info("%s: %s" % (entry.tag, entry.get('name')))
- groups_root.append(lxml.etree.Element(entry.tag, name=entry.get('name')))
+ self.log.info("%s: %s" % (tag, name))
+ lxml.etree.SubElement(groups_root, tag, name=name)
+
tree = lxml.etree.ElementTree(root)
if write_to_file == True:
try:
@@ -73,5 +65,7 @@ class Minestruct(Bcfg2.Server.Admin.Mode):
except IOError:
self.log.info("Failed to write to file: %s" % (output_file))
raise SystemExit(1)
- tree.write(f)
+ tree.write(f, pretty_print=True)
+ else:
+ print lxml.etree.tostring(tree, pretty_print=True)
diff --git a/src/lib/Server/Plugins/DBStats.py b/src/lib/Server/Plugins/DBStats.py
index b0d6779a6..6e9be82d0 100644
--- a/src/lib/Server/Plugins/DBStats.py
+++ b/src/lib/Server/Plugins/DBStats.py
@@ -1,5 +1,6 @@
import Bcfg2.Server.Plugin
import Bcfg2.Server.Reports.importscript
+from Bcfg2.Server.Reports.reports.models import Client
import lxml.etree, time
class DBStats(Bcfg2.Server.Plugin.StatisticsPlugin):
@@ -22,4 +23,9 @@ class DBStats(Bcfg2.Server.Plugin.StatisticsPlugin):
Bcfg2.Server.Reports.importscript.load_stats(
self.core.metadata.clientdata, container, 0, True)
+ def GetExtra(self, client):
+ c_inst = Client.objects.filter(name=client)[0]
+ return [(a.kind, a.name) for a in
+ c_inst.current_interaction.extra_items.all()]
+
diff --git a/src/lib/Server/Plugins/Statistics.py b/src/lib/Server/Plugins/Statistics.py
index 41de7ba4b..b7dc61179 100644
--- a/src/lib/Server/Plugins/Statistics.py
+++ b/src/lib/Server/Plugins/Statistics.py
@@ -119,9 +119,9 @@ class Statistics(Bcfg2.Server.Plugin.StatisticsPlugin):
self.data.WriteBack()
def FindCurrent(self, client):
- rt = self.data.element.xpath('//Node[@name="%s"]' % client)
- maxtime = max([time.strptime(stat.get('time')) for stat in rt.findall('Statistics')])
- return [stat for stat in rt.findall('Statistics') if time.strptime(stat.get('time')) == maxtime][0]
+ rt = self.data.element.xpath('//Node[@name="%s"]' % client)[0]
+ maxtime = max([strptime(stat.get('time')) for stat in rt.findall('Statistics')])
+ return [stat for stat in rt.findall('Statistics') if strptime(stat.get('time')) == maxtime][0]
def GetExtra(self, client):
return [(entry.tag, entry.get('name')) for entry in self.FindCurrent(client).xpath('.//Extra/*')]