diff --git a/ocw/lib/dump_state.py b/ocw/lib/dump_state.py index f7256626..dacb0237 100644 --- a/ocw/lib/dump_state.py +++ b/ocw/lib/dump_state.py @@ -65,6 +65,12 @@ def dump_state(): namespace, EC2(namespace).count_all_volumes ) + Influx().dump_resource( + ProviderChoice.EC2.value, + Influx.VPC_QUANTITY, + namespace, + EC2(namespace).count_all_vpc + ) except Exception: logger.exception( "[%s] Dump state failed!: \n %s", namespace, traceback.format_exc() diff --git a/ocw/lib/ec2.py b/ocw/lib/ec2.py index 92b80340..f1834b73 100644 --- a/ocw/lib/ec2.py +++ b/ocw/lib/ec2.py @@ -345,6 +345,13 @@ def count_all_volumes(self) -> int: all_volumes_cnt += len(response['Volumes']) return all_volumes_cnt + def count_all_vpc(self) -> int: + all_vpcs = 0 + for region in self.all_regions: + response = self.ec2_client(region).describe_vpcs(Filters=[{'Name': 'isDefault', 'Values': ['false']}]) + all_vpcs += len(response['Vpcs']) + return all_vpcs + def cleanup_images(self, valid_period_days: float) -> None: self.log_dbg('Call cleanup_images') for region in self.all_regions: diff --git a/ocw/lib/influx.py b/ocw/lib/influx.py index 9b921c5f..5e5f48f4 100644 --- a/ocw/lib/influx.py +++ b/ocw/lib/influx.py @@ -19,6 +19,7 @@ class Influx: DISK_QUANTITY: str = "disk_quantity" VOLUMES_QUANTITY: str = "volumes_quanity" IMAGE_VERSION_QUANTITY: str = "img_version_quantity" + VPC_QUANTITY: str = "vpc_quantity" NAMESPACE_TAG: str = "namespace" def __init__(self) -> None: diff --git a/tests/test_ec2.py b/tests/test_ec2.py index ff1f9474..501e333e 100644 --- a/tests/test_ec2.py +++ b/tests/test_ec2.py @@ -532,3 +532,7 @@ def test_count_all_volumes(ec2_patch): 'Tags': [{'Key': 'pcw_ignore', 'Value': '1'}]}, ] } assert ec2_patch.count_all_volumes() == 3 + + +def test_count_all_vpcs(ec2_patch_for_vpc): + assert ec2_patch_for_vpc.count_all_vpc() == 1