Skip to content

Instantly share code, notes, and snippets.

@acumenix
Forked from alq666/instance.py
Created October 9, 2019 05:54
Show Gist options
  • Save acumenix/c7aa6d74da471560dc6225886d52b151 to your computer and use it in GitHub Desktop.
Save acumenix/c7aa6d74da471560dc6225886d52b151 to your computer and use it in GitHub Desktop.
Compute the count of instances per zone
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]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment