Browse files

Merge pull request #7 from InformatiQ/master

new output format and more details in output for SG
  • Loading branch information...
2 parents ec22c5d + 680b69e commit d070c3157ba53b54efcf993beedef2a2ef83a974 @cosmin cosmin committed Oct 18, 2013
Showing with 13 additions and 2 deletions.
  1. +6 −1 ec2audit/app.py
  2. +7 −1 ec2audit/output.py
View
7 ec2audit/app.py
@@ -32,6 +32,9 @@ def instance_data(i):
data[key] = i.__dict__[key]
data['security_groups'] = sorted([g.name for g in i.groups])
+ data['vpc_id'] = i.vpc_id
+ data['subnet_id'] = i.subnet_id
+ data['instance_type'] = i.instance_type
if i.block_device_mapping:
data['volumes'] = NaturalOrderDict()
@@ -119,6 +122,8 @@ def sg_data(sg):
data['inbound'] = handle_rules(sg, sg.rules)
if sg.rules_egress:
data['outbound'] = handle_rules(sg, sg.rules_egress)
+ data['name'] = sg.name
+ data['vpc_id'] = sg.vpc_id
return sg.name, data
def get_ec2_security_groups(ec2):
@@ -127,7 +132,7 @@ def get_ec2_security_groups(ec2):
def run(params):
access_key, secret_key = get_aws_credentials(params)
region = params['<region>']
- if params['--format'] not in ['j', 'y', 'p', 'json', 'yaml', 'pprint']:
+ if params['--format'] not in ['j', 'y', 'p', 'json', 'yaml', 'pprint', 'db']:
exit_with_error('Error: format must be one of json or yaml\n')
con = ec2.connect_to_region(region,
View
8 ec2audit/output.py
@@ -11,6 +11,9 @@ def to_stdout(data, fmt):
elif fmt.startswith('p'):
from pprint import pprint
pprint(data)
+ elif fmt.startswith('db'):
+ from pprint import pprint
+ pprint(data.values()[0])
def to_dir(data, fmt, output):
if fmt.startswith('j'):
@@ -25,7 +28,10 @@ def to_dir(data, fmt, output):
from pprint import pprint
ext = 'py'
dump = lambda data, f: pprint(data, f)
-
+ elif fmt.startswith('db'):
+ import json
+ ext = 'db'
+ dump = lambda data, f: json.dump(data[data.keys()[0]], f, indent=4)
mkdirp(output)
for dtype, items in data.items():
base = join(output, dtype)

0 comments on commit d070c31

Please sign in to comment.