Created
September 8, 2013 02:49
-
-
Save alq666/6481451 to your computer and use it in GitHub Desktop.
Compute the count of instances per zone
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import simplejson as json | |
import sys | |
#{ | |
# "results": 91, | |
# "rows": [ | |
# { | |
# "ec2": { | |
# "instance_action": "none", | |
# "instance_id": "i-f9069c96", | |
# "ami_launch_index": "0", | |
# z is a hash {zone: {type: count}} | |
z = {} | |
x = json.load(sys.stdin) | |
for r in x["rows"]: | |
if r["ec2"].get("placement_availability_zone") is None: continue | |
zone = r["ec2"]["placement_availability_zone"] | |
typ = r["ec2"]["instance_type"] | |
if z.get(zone) is None: z[zone] = {} | |
if z[zone].get(typ) is None: z[zone][typ] = 0 | |
z[zone][typ] += 1 | |
for zone in z: | |
for typ in z[zone]: | |
print("{0},{1},{2}".format(zone, typ, z[zone][typ])) |
Author
alq666
commented
Sep 8, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment