Instantly share code, notes, and snippets.

Embed
What would you like to do?
import json
import sys
from collections import OrderedDict
from pprint import pprint
osds = {}
ssdosds = {}
#with open('json.out') as f:
data = json.load(sys.stdin)
#data = json.load(f)
#pprint(data['nodes'])
for osd in data['nodes']:
if osd['type'] == "osd":
osds[osd['id']] = dict([("name", osd['name']),("utilization", osd['utilization'])])
sortedosds = OrderedDict(sorted(osds.iteritems(), key=lambda x: x[1]['utilization']))
for ssdhost in data['nodes']:
if ssdhost['type'] == "dssd":
#print(ssdhost['children'])
for osdid in ssdhost['children']:
ssdosds[osdid] = dict([("name", osds[osdid]['name']),("utilization", osds[osdid]['utilization'])])
sortedssdosds = OrderedDict(sorted(ssdosds.iteritems(), key=lambda x: x[1]['utilization']))
for key,val in sortedssdosds.items():
print val['name'], "\tutilization:", val['utilization']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment