Skip to content

Instantly share code, notes, and snippets.

@alq666
Created September 8, 2013 02:49
Show Gist options
  • Save alq666/6481451 to your computer and use it in GitHub Desktop.
Save alq666/6481451 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]))
@alq666
Copy link
Author

alq666 commented Sep 8, 2013

knife search node "role:common-node" -a ec2 -Fj | python instance.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment