summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/lib/Server/Admin/Reports.py52
-rw-r--r--src/lib/Server/Admin/__init__.py2
2 files changed, 53 insertions, 1 deletions
diff --git a/src/lib/Server/Admin/Reports.py b/src/lib/Server/Admin/Reports.py
new file mode 100644
index 000000000..192afd777
--- /dev/null
+++ b/src/lib/Server/Admin/Reports.py
@@ -0,0 +1,52 @@
+import os, sys, binascii
+try:
+ import Bcfg2.Server.Reports.settings
+except:
+ sys.stderr.write("Failed to load configuration settings. is /etc/bcfg2.conf readable?")
+ sys.exit(1)
+
+project_directory = os.path.dirname(Bcfg2.Server.Reports.settings.__file__)
+project_name = os.path.basename(project_directory)
+sys.path.append(os.path.join(project_directory, '..'))
+project_module = __import__(project_name, '', '', [''])
+sys.path.pop()
+# Set DJANGO_SETTINGS_MODULE appropriately.
+os.environ['DJANGO_SETTINGS_MODULE'] = '%s.settings' % project_name
+
+from Bcfg2.Server.Reports.reports.models import Client
+import Bcfg2.Server.Admin
+
+def timecompare(client1, client2):
+ return cmp(client1.current_interaction.timestamp, \
+ client2.current_interaction.timestamp)
+
+class Reports(Bcfg2.Server.Admin.Mode):
+
+ def __call__(self, args):
+ Bcfg2.Server.Admin.Mode.__call__(self, args)
+ if "-h" in args:
+ print "Usage: "
+ print self.__shorthelp__
+ raise SystemExit(1)
+
+ c_list = Client.objects.all()
+
+ result = list()
+
+ if '-c' in args or '-d' in args:
+ for c_inst in c_list:
+ if '-c' in args and c_inst.current_interaction.isclean() or \
+ '-d' in args and not \
+ c_inst.current_interaction.isclean():
+ result.append(c_inst)
+ else:
+ result = c_list
+
+ if '-s' in args:
+ result.sort(timecompare)
+
+ for c_inst in result:
+ print c_inst, c_inst.current_interaction.timestamp
+
+
+
diff --git a/src/lib/Server/Admin/__init__.py b/src/lib/Server/Admin/__init__.py
index cff9eec6a..e2641bb6d 100644
--- a/src/lib/Server/Admin/__init__.py
+++ b/src/lib/Server/Admin/__init__.py
@@ -1,7 +1,7 @@
__revision__ = '$Revision$'
__all__ = ['Mode', 'Client', 'Compare', 'Fingerprint', 'Init', 'Minestruct',
- 'Pull', 'Query', 'Tidy', 'Viz']
+ 'Pull', 'Query', 'Reports', 'Tidy', 'Viz']
import ConfigParser, lxml.etree, logging