summaryrefslogtreecommitdiffstats
path: root/src/sbin/bcfg2-reports
diff options
context:
space:
mode:
authorTim Laszlo <tim.laszlo@gmail.com>2012-10-15 09:20:12 -0500
committerTim Laszlo <tim.laszlo@gmail.com>2012-10-15 09:20:32 -0500
commit96108cfae8b68d6265e4643ea9519bdfd9127752 (patch)
tree2011d9cabf7fc84815fc8d5bc5f06d5cf408a979 /src/sbin/bcfg2-reports
parent9707ee8e4c495133f329000d3e5b89d8b84e5998 (diff)
downloadbcfg2-96108cfae8b68d6265e4643ea9519bdfd9127752.tar.gz
bcfg2-96108cfae8b68d6265e4643ea9519bdfd9127752.tar.bz2
bcfg2-96108cfae8b68d6265e4643ea9519bdfd9127752.zip
bcfg2-reports: updated to new schema
Diffstat (limited to 'src/sbin/bcfg2-reports')
-rwxr-xr-xsrc/sbin/bcfg2-reports42
1 files changed, 20 insertions, 22 deletions
diff --git a/src/sbin/bcfg2-reports b/src/sbin/bcfg2-reports
index ee29944e2..21112826e 100755
--- a/src/sbin/bcfg2-reports
+++ b/src/sbin/bcfg2-reports
@@ -23,8 +23,7 @@ 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, Entries_interactions,
- Entries, TYPE_CHOICES)
+from Bcfg2.Reporting.models import (Client, BaseEntry)
def hosts_by_entry_type(clients, etype, entryspec):
result = []
@@ -32,8 +31,8 @@ def hosts_by_entry_type(clients, etype, entryspec):
for client in clients:
items = getattr(client.current_interaction, etype)()
for item in items:
- if (item.entry.kind == entry[0] and
- item.entry.name == entry[1]):
+ if (item.entry_type == entry[0] and
+ item.name == entry[1]):
result.append(client)
return result
@@ -198,8 +197,8 @@ def main():
print("Host un-expired.")
client.save()
elif options.total:
- managed = client.current_interaction.totalcount
- good = client.current_interaction.goodcount
+ managed = client.current_interaction.total_count
+ good = client.current_interaction.good_count
print("Total managed entries: %d (good: %d)" % (managed, good))
elif mode_family == hostmodes:
if options.bad or options.show:
@@ -255,30 +254,29 @@ def main():
if 'state' in fields:
fields.remove('state')
fields.append("entry state")
+
try:
- entry_obj = Entries.objects.get(
- kind=entries[0][0],
- name=entries[0][1])
- except Entries.DoesNotExist:
- print("No entry %s found" % ":".join(entries[0]))
+ entry_cls = BaseEntry.entry_from_type(entries[0][0])
+ except ValueError:
+ print("Unhandled/unkown type %s" % entries[0][0])
return 2
+ # todo batch fetch this. sqlite could break
for client in clients:
- try:
- entry = \
- Entries_interactions.objects.select_related().get(
- interaction=client.current_interaction,
- entry=entry_obj)
- edata[client] = \
- {"entry state":dict(TYPE_CHOICES)[entry.type],
- "reason":entry.reason}
- result.append(client)
- except Entries_interactions.DoesNotExist:
- pass
+ ents = entry_cls.objects.filter(name=entries[0][1],
+ interaction=client.current_interaction)
+ if len(ents) == 0:
+ continue
+ edata[client] = {"entry state": ents[0].get_state_display(),
+ "reason": ents[0]}
+ result.append(client)
if 'name' not in fields:
fields.insert(0, "name")
+ if not result:
+ print("No match found")
+ return
max_name = max(len(c.name) for c in result)
ffmt = []
for field in fields: