#!/usr/bin/env python

import urllib2
import json
from optparse import OptionParser

parser = OptionParser()

parser.add_option("-2", "--v2", action="store_true", dest="v2", default=False)
(options, args) = parser.parse_args()

if (options.v2):
    version = "v2"
else:
    version = "v3"

url = 'http://localhost:8080/%s/nodes' % version


r = urllib2.Request(url)
r.add_header('Accept', 'application/json')
u = urllib2.urlopen(r)

print( "%-24s %s %25s" % ( 'Name', 'Facts', 'Report'))
for i in sorted(json.load(u), key = lambda o: o['facts_timestamp']):
    print( "%-24s %s %s" % (
        i['name'],
        i['facts_timestamp'],
        i['report_timestamp'],
        ))
u.close()
