feat: added ec2 root volume size and rds allocated storage
This commit is contained in:
+8
-2
@@ -13,6 +13,11 @@ from openpyxl.worksheet.worksheet import Worksheet
|
|||||||
import projectlib.aws
|
import projectlib.aws
|
||||||
|
|
||||||
|
|
||||||
|
def getVolumeSize(region_name: str, id: str) -> int:
|
||||||
|
client = boto3.client('ec2', region_name=region_name)
|
||||||
|
response = client.describe_volumes(VolumeIds=[id])
|
||||||
|
return response['Volumes'][0]['Size']
|
||||||
|
|
||||||
def getResources(region_name: str) -> list[list[str | int]]:
|
def getResources(region_name: str) -> list[list[str | int]]:
|
||||||
return_data = []
|
return_data = []
|
||||||
client = boto3.client('ec2', region_name=region_name)
|
client = boto3.client('ec2', region_name=region_name)
|
||||||
@@ -24,7 +29,8 @@ def getResources(region_name: str) -> list[list[str | int]]:
|
|||||||
if tag['Key'] == "Name":
|
if tag['Key'] == "Name":
|
||||||
name_tag = tag['Value']
|
name_tag = tag['Value']
|
||||||
break
|
break
|
||||||
return_data.append([i['InstanceId'], name_tag, i.get('PlatformDetails'), i['InstanceType'], i['PrivateIpAddress'], i['Placement']['AvailabilityZone']])
|
rootVolSize = getVolumeSize(region_name=region_name, id=i['BlockDeviceMappings'][0]['Ebs']['VolumeId'])
|
||||||
|
return_data.append([i['InstanceId'], name_tag, i.get('PlatformDetails'), i['InstanceType'], i['PrivateIpAddress'], rootVolSize, i['Placement']['AvailabilityZone']])
|
||||||
return return_data
|
return return_data
|
||||||
|
|
||||||
# Main function
|
# Main function
|
||||||
@@ -33,7 +39,7 @@ def main() -> None:
|
|||||||
wb = load_workbook('aws-inventory.xlsx')
|
wb = load_workbook('aws-inventory.xlsx')
|
||||||
ws = wb.create_sheet("Ec2")
|
ws = wb.create_sheet("Ec2")
|
||||||
|
|
||||||
ws.append(["InstanceId","NameTag","Platform","InstanceType","PrivateIpAddress","AZ"])
|
ws.append(["InstanceId","NameTag","Platform","InstanceType","PrivateIpAddress","RootVolumeSize", "AZ"])
|
||||||
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
|
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
|
||||||
results = executor.map(getResources, projectlib.aws.getRegions())
|
results = executor.map(getResources, projectlib.aws.getRegions())
|
||||||
for region_rows in results:
|
for region_rows in results:
|
||||||
|
|||||||
+2
-2
@@ -18,7 +18,7 @@ def getResources(region_name: str) -> list[list[str | int]]:
|
|||||||
client = boto3.client('rds', region_name=region_name)
|
client = boto3.client('rds', region_name=region_name)
|
||||||
response = client.describe_db_instances()
|
response = client.describe_db_instances()
|
||||||
for i in response['DBInstances']:
|
for i in response['DBInstances']:
|
||||||
return_data.append([i['DBInstanceIdentifier'], i['DBInstanceClass'], i['Engine'], i['EngineVersion'], i['MultiAZ'], region_name])
|
return_data.append([i['DBInstanceIdentifier'], i['DBInstanceClass'], i['Engine'], i['EngineVersion'], i['AllocatedStorage'], i['MultiAZ'], region_name])
|
||||||
return return_data
|
return return_data
|
||||||
|
|
||||||
# Main function
|
# Main function
|
||||||
@@ -27,7 +27,7 @@ def main() -> None:
|
|||||||
wb = load_workbook('aws-inventory.xlsx')
|
wb = load_workbook('aws-inventory.xlsx')
|
||||||
ws = wb.create_sheet("RDS")
|
ws = wb.create_sheet("RDS")
|
||||||
|
|
||||||
ws.append(["DBInstanceIdentifier", "DBInstanceClass", "Engine", "EngineVersion", "MultiAZ", "Region"])
|
ws.append(["DBInstanceIdentifier", "DBInstanceClass", "Engine", "EngineVersion", "AllocatedStorage", "MultiAZ", "Region"])
|
||||||
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
|
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
|
||||||
results = executor.map(getResources, projectlib.aws.getRegions())
|
results = executor.map(getResources, projectlib.aws.getRegions())
|
||||||
for region_rows in results:
|
for region_rows in results:
|
||||||
|
|||||||
Reference in New Issue
Block a user