Skip to content

Commit

Permalink
issue #95 - convert VPC to boto3
Browse files Browse the repository at this point in the history
  • Loading branch information
jantman committed Jan 30, 2016
1 parent 0cdf906 commit 79702e2
Show file tree
Hide file tree
Showing 4 changed files with 291 additions and 131 deletions.
44 changes: 22 additions & 22 deletions awslimitchecker/services/vpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
"""

import abc # noqa
import boto
import boto.vpc
import logging
from collections import defaultdict

Expand All @@ -58,10 +56,8 @@ def connect(self):
"""Connect to API if not already connected; set self.conn."""
if self.conn is not None:
return
elif self.region:
self.conn = self.connect_via(boto.vpc.connect_to_region)
else:
self.conn = boto.connect_vpc()
self.conn = self.connect_client('ec2')

def find_usage(self):
"""
Expand All @@ -84,19 +80,20 @@ def find_usage(self):
def _find_usage_vpcs(self):
"""find usage for VPCs"""
# overall number of VPCs
vpcs = boto_query_wrapper(self.conn.get_all_vpcs)
vpcs = boto_query_wrapper(self.conn.describe_vpcs,
alc_no_paginate=True)
self.limits['VPCs']._add_current_usage(
len(vpcs),
len(vpcs['Vpcs']),
aws_type='AWS::EC2::VPC'
)

def _find_usage_subnets(self):
"""find usage for Subnets"""
# subnets per VPC
subnets = defaultdict(int)
for subnet in boto_query_wrapper(self.conn.get_all_subnets):
# boto.vpc.subnet.Subnet
subnets[subnet.vpc_id] += 1
for subnet in boto_query_wrapper(self.conn.describe_subnets,
alc_no_paginate=True)['Subnets']:
subnets[subnet['VpcId']] += 1
for vpc_id in subnets:
self.limits['Subnets per VPC']._add_current_usage(
subnets[vpc_id],
Expand All @@ -108,14 +105,15 @@ def _find_usage_ACLs(self):
"""find usage for ACLs"""
# Network ACLs per VPC
acls = defaultdict(int)
for acl in boto_query_wrapper(self.conn.get_all_network_acls):
# boto.vpc.networkacl.NetworkAcl
acls[acl.vpc_id] += 1
result = boto_query_wrapper(self.conn.describe_network_acls,
alc_no_paginate=True)
for acl in result['NetworkAcls']:
acls[acl['VpcId']] += 1
# Rules per network ACL
self.limits['Rules per network ACL']._add_current_usage(
len(acl.network_acl_entries),
len(acl['Entries']),
aws_type='AWS::EC2::NetworkAcl',
resource_id=acl.id
resource_id=acl['NetworkAclId']
)
for vpc_id in acls:
self.limits['Network ACLs per VPC']._add_current_usage(
Expand All @@ -128,14 +126,15 @@ def _find_usage_route_tables(self):
"""find usage for route tables"""
# Route tables per VPC
tables = defaultdict(int)
for table in boto_query_wrapper(self.conn.get_all_route_tables):
# boto.vpc.routetable.RouteTable
tables[table.vpc_id] += 1
result = boto_query_wrapper(self.conn.describe_route_tables,
alc_no_paginate=True)
for table in result['RouteTables']:
tables[table['VpcId']] += 1
# Entries per route table
self.limits['Entries per route table']._add_current_usage(
len(table.routes),
len(table['Routes']),
aws_type='AWS::EC2::RouteTable',
resource_id=table.id
resource_id=table['RouteTableId']
)
for vpc_id in tables:
self.limits['Route tables per VPC']._add_current_usage(
Expand All @@ -147,9 +146,10 @@ def _find_usage_route_tables(self):
def _find_usage_gateways(self):
"""find usage for Internet Gateways"""
# Internet gateways
gws = boto_query_wrapper(self.conn.get_all_internet_gateways)
gws = boto_query_wrapper(self.conn.describe_internet_gateways,
alc_no_paginate=True)
self.limits['Internet gateways']._add_current_usage(
len(gws),
len(gws['InternetGateways']),
aws_type='AWS::EC2::InternetGateway',
)

Expand Down
Loading

0 comments on commit 79702e2

Please sign in to comment.