Skip to content

Commit

Permalink
Ability to check all vpcs in the region #1
Browse files Browse the repository at this point in the history
  • Loading branch information
leandrodamascena committed May 24, 2020
1 parent 78cb09e commit 5ec2aef
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
4 changes: 2 additions & 2 deletions aws-network-discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def show_options(args="sys.argv[1:]"):
parser.add_argument(
"-v",
"--vpc-id",
required=True,
help="Inform VPC to analyze"
required=False,
help="Inform VPC to analyze. If not informed, script try all vpcs."
)
parser.add_argument(
"-r",
Expand Down
16 changes: 13 additions & 3 deletions commands/vpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,18 @@ def run(self):
if self.region_name is not None:
region_name = self.region_name

""" init class awscommands """
awscommands = AwsCommands(VpcOptions(session=session, vpc_id=self.vpc_id, region_name=region_name))
awscommands.run()
""" if vpc is none, get all vpcs and check """
if self.vpc_id is None:
client = session.client('ec2')
vpcs = client.describe_vpcs()
for data in vpcs['Vpcs']:
""" init class awscommands """
awscommands = AwsCommands(VpcOptions(session=session, vpc_id=data['VpcId'], region_name=region_name)).run()
else:
""" init class awscommands """
awscommands = AwsCommands(VpcOptions(session=session, vpc_id=self.vpc_id, region_name=region_name)).run()





9 changes: 5 additions & 4 deletions shared/internal/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ def run(self):
)

dataresponse = response['Vpcs'][0]
message = "VPC: {}\nCIDR Block: {}\nTenancy: {}\nIs default: {}".format(self.vpc_options.vpc_id,
dataresponse['CidrBlock'],
dataresponse['InstanceTenancy'],
dataresponse['IsDefault'])
message = "------------------------------------------------------\n"
message = message + "VPC: {}\nCIDR Block: {}\nTenancy: {}\nIs default: {}".format(self.vpc_options.vpc_id,
dataresponse['CidrBlock'],
dataresponse['InstanceTenancy'],
dataresponse['IsDefault'])
print(message)

return True
Expand Down

0 comments on commit 5ec2aef

Please sign in to comment.