feat: porting shell scripts to python
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
function listRes() {
|
||||
aws elasticache --region $1 describe-cache-clusters | jq -cr '.CacheClusters[] | [.CacheClusterId, .CacheNodeType, .Engine, .PreferredAvailabilityZone] | @csv' | tr -d \"
|
||||
}
|
||||
|
||||
export -f listRes
|
||||
|
||||
# Generate inventory of ec2 in all regions
|
||||
|
||||
echo "ClusterId,NodeType,Engine,AZ"
|
||||
aws --region=us-east-1 ec2 describe-regions --query Regions[].RegionName --output text | sed -e 's/\t/\n/g' | while read r; do
|
||||
sem -j6 listRes $r
|
||||
done
|
||||
|
||||
sem --wait
|
||||
Executable
+32
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env python3
|
||||
r"""
|
||||
Documentation
|
||||
|
||||
License: This program is released under the MIT License
|
||||
"""
|
||||
|
||||
# Imports
|
||||
import boto3
|
||||
import concurrent.futures
|
||||
|
||||
def getRegions(all_regions=False):
|
||||
ec2 = boto3.client('ec2')
|
||||
response = ec2.describe_regions(AllRegions=all_regions)
|
||||
return [region['RegionName'] for region in response['Regions']]
|
||||
|
||||
def printResources(region_name: str):
|
||||
client = boto3.client('elasticache', region_name=region_name)
|
||||
response = client.describe_cache_clusters()
|
||||
for i in response['CacheClusters']:
|
||||
print(f"{i['CacheClusterId']}, {i['CacheNodeType']}, {i['Engine']}, {i['EngineVersion']}, {i['NumCacheNodes']}, {i['PreferredAvailabilityZone']}")
|
||||
|
||||
# Main function
|
||||
def main() -> None:
|
||||
print("CacheClusterId, CacheNodeType, Engine, EngineVersion, NumCacheNodes, AZ")
|
||||
with concurrent.futures.ProcessPoolExecutor(max_workers=6) as executor:
|
||||
futures = [executor.submit(printResources, region_name=r) for r in getRegions()]
|
||||
results = [future.result() for future in concurrent.futures.wait(futures).done]
|
||||
|
||||
# Call main function
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -1,16 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
function listRes() {
|
||||
aws --region $1 ec2 describe-subnets | jq -cr '.Subnets[] | [.SubnetId, .VpcId, .CidrBlock, .AvailabilityZone] | @csv' | tr -d \"
|
||||
}
|
||||
|
||||
export -f listRes
|
||||
|
||||
# Generate inventory in all regions
|
||||
|
||||
echo "SubnetId,VpcId,CidrBlock,AZ"
|
||||
aws --region=us-east-1 ec2 describe-regions --query Regions[].RegionName --output text | sed -e 's/\t/\n/g' | while read r; do
|
||||
sem -j6 listRes $r
|
||||
done
|
||||
|
||||
sem --wait
|
||||
Executable
+35
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env python3
|
||||
r"""
|
||||
Documentation
|
||||
|
||||
License: This program is released under the MIT License
|
||||
"""
|
||||
|
||||
# Imports
|
||||
import boto3
|
||||
import concurrent.futures
|
||||
|
||||
def getRegions(all_regions=False):
|
||||
ec2 = boto3.client('ec2')
|
||||
response = ec2.describe_regions(AllRegions=all_regions)
|
||||
return [region['RegionName'] for region in response['Regions']]
|
||||
|
||||
def printResources(region_name: str):
|
||||
client = boto3.client('ec2', region_name=region_name)
|
||||
response = client.describe_subnets()
|
||||
for i in response['Subnets']:
|
||||
default_vpc_check = client.describe_vpcs(VpcIds=[i['VpcId']])
|
||||
for v in default_vpc_check['Vpcs']:
|
||||
if not v['IsDefault']:
|
||||
print(f"{i['SubnetId']}, {i['VpcId']}, {i['CidrBlock']}, {i['AvailabilityZone']}")
|
||||
|
||||
# Main function
|
||||
def main() -> None:
|
||||
print("SubnetId, VpcId, CidrBlock, AvailabilityZone")
|
||||
with concurrent.futures.ProcessPoolExecutor(max_workers=6) as executor:
|
||||
futures = [executor.submit(printResources, region_name=r) for r in getRegions()]
|
||||
results = [future.result() for future in concurrent.futures.wait(futures).done]
|
||||
|
||||
# Call main function
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user