summaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorNarayan Desai <desai@mcs.anl.gov>2008-08-07 20:16:29 +0000
committerNarayan Desai <desai@mcs.anl.gov>2008-08-07 20:16:29 +0000
commite3e0d8d72e21f58c23ddf51d5af9d9200ee5037a (patch)
tree41808e40ef91e21ae2f61bc8e5748a43e2bd7088 /src/lib
parentc548d3ff9ef0bc01c00a3e5068413aca4cce8a46 (diff)
downloadbcfg2-e3e0d8d72e21f58c23ddf51d5af9d9200ee5037a.tar.gz
bcfg2-e3e0d8d72e21f58c23ddf51d5af9d9200ee5037a.tar.bz2
bcfg2-e3e0d8d72e21f58c23ddf51d5af9d9200ee5037a.zip
Implement GetCurrentEntry api for Statistics and DBStats (prereq for portable bcfg2-admin pull)
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@4869 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/Server/Plugin.py2
-rw-r--r--src/lib/Server/Plugins/DBStats.py21
-rw-r--r--src/lib/Server/Plugins/Statistics.py20
3 files changed, 39 insertions, 4 deletions
diff --git a/src/lib/Server/Plugin.py b/src/lib/Server/Plugin.py
index 4d95fce49..6e3bc3a7c 100644
--- a/src/lib/Server/Plugin.py
+++ b/src/lib/Server/Plugin.py
@@ -111,7 +111,7 @@ class StatisticsPlugin(Plugin):
return []
def GetCurrentEntry(self, client, e_type, e_name):
- return None
+ raise PluginExecutionError
# the rest of the file contains classes for coherent file caching
diff --git a/src/lib/Server/Plugins/DBStats.py b/src/lib/Server/Plugins/DBStats.py
index 6e9be82d0..abe8f17f7 100644
--- a/src/lib/Server/Plugins/DBStats.py
+++ b/src/lib/Server/Plugins/DBStats.py
@@ -1,7 +1,7 @@
import Bcfg2.Server.Plugin
import Bcfg2.Server.Reports.importscript
from Bcfg2.Server.Reports.reports.models import Client
-import lxml.etree, time
+import difflib, lxml.etree, time
class DBStats(Bcfg2.Server.Plugin.StatisticsPlugin):
__name__ = 'DBStats'
@@ -28,4 +28,21 @@ class DBStats(Bcfg2.Server.Plugin.StatisticsPlugin):
return [(a.kind, a.name) for a in
c_inst.current_interaction.extra_items.all()]
-
+ def GetCurrentEntry(self, client, e_type, e_name):
+ c_inst = Client.objects.filter(name=client)[0]
+ entry = c_inst.current_interaction.bad_items.filter(kind=e_type,
+ name=e_name)[0]
+ ret = []
+ data = ('owner', 'group', 'perms')
+ for t in data:
+ if getattr(entry.reason, "current_%s" % t) == '':
+ ret.append(getattr(entry.reason, t))
+ else:
+ ret.append(getattr(entry.reason, "current_%s" % t))
+
+ if entry.reason.current_diff != '':
+ ret.append('\n'.join(difflib.restore(\
+ entry.reason.current_diff.split('\n'), 1)))
+ else:
+ ret.append(None)
+ return ret
diff --git a/src/lib/Server/Plugins/Statistics.py b/src/lib/Server/Plugins/Statistics.py
index b7dc61179..b47ee4410 100644
--- a/src/lib/Server/Plugins/Statistics.py
+++ b/src/lib/Server/Plugins/Statistics.py
@@ -4,7 +4,7 @@ __revision__ = '$Revision$'
from lxml.etree import XML, SubElement, Element, XMLSyntaxError
from time import asctime, localtime, time, strptime, mktime
-import logging, lxml.etree, os
+import binascii, logging, lxml.etree, os
import Bcfg2.Server.Plugin
@@ -125,3 +125,21 @@ class Statistics(Bcfg2.Server.Plugin.StatisticsPlugin):
def GetExtra(self, client):
return [(entry.tag, entry.get('name')) for entry in self.FindCurrent(client).xpath('.//Extra/*')]
+
+ def GetCurrentEntry(self, client, e_type, e_name):
+ curr = self.FindCurrent(client)
+ entry = curr.xpath('.//Bad/%s[@name="%s"]' % (e_type, e_name))
+ cfentry = entry[-1]
+
+ owner = cfentry.get('current_owner', cfentry.get('owner'))
+ group = cfentry.get('current_group', cfentry.get('group'))
+ perms = cfentry.get('current_perms', cfentry.get('perms'))
+ if 'current_bfile' in cfentry.attrib:
+ contents = binascii.a2b_base64(cfentry.get('current_bfile'))
+ elif 'current_bdiff' in cfentry.attrib:
+ diff = binascii.a2b_base64(cfentry.get('current_bdiff'))
+ contents = '\n'.join(difflib.restore(diff.split('\n'), 1))
+ else:
+ contents = None
+
+ return (owner, group, perms, contents)