diff --git a/Management-Utilities/fsx-ontap-aws-cli-scripts/README.md b/Management-Utilities/fsx-ontap-aws-cli-scripts/README.md index cf4277f..7f42b1e 100644 --- a/Management-Utilities/fsx-ontap-aws-cli-scripts/README.md +++ b/Management-Utilities/fsx-ontap-aws-cli-scripts/README.md @@ -21,6 +21,8 @@ Before running the UNIX based scripts, make sure the following package is instal |list_fsx_filesystems.ps1 | List all the FSx for NetApp ONTAP filesystems that the user has access to, written in PowerShell. | |list_fsxn_volumes | List all the FSx for NetApp ONTAP volumes that the user has access to. | |list_fsxn_svms | List all the storage virtual machines that the user access to. | +|list_aws_subnets | List all the aws subnets. | +|list_aws_vpcs | List all the aws vpcs. | |delete_fsxn_filesystem | Deletes an FSx for NetApp ONTAP filesystem. | |delete_fsxn_svm | Deletes an svm. | |delete_fsxn_volume | Deletes a volume. | diff --git a/Management-Utilities/fsx-ontap-aws-cli-scripts/list_aws_subnets b/Management-Utilities/fsx-ontap-aws-cli-scripts/list_aws_subnets new file mode 100755 index 0000000..66be940 --- /dev/null +++ b/Management-Utilities/fsx-ontap-aws-cli-scripts/list_aws_subnets @@ -0,0 +1,58 @@ +#!/bin/bash +# +# This script is used to list all VPCs in the AWS account. +################################################################################ +# +usage () { + cat 1>&2 < /dev/null 2>&1; then + : + else + echo "Error, $tool command is rquired to run this script." + exit 1 + fi +done + +allRegions=False +regions="" +vpcId="" +while getopts "ar:hv:" opt; do + case $opt in + a) allRegions=True + ;; + r) regions=$OPTARG + ;; + v) vpcId=$OPTARG + ;; + *) usage + ;; + esac +done + +if [ "$allRegions" == "True" ]; then + regions=$(aws ec2 describe-regions --query "Regions[].RegionName" --output=text) +else + if [ -z "$regions" ]; then + regions=$(aws configure get region) + fi +fi + +for region in $regions; do + if [ "$allRegions" == "True" ]; then + printf "\nRegion: $region\n" + fi + if [ -z "$vpcId" ]; then + aws ec2 describe-subnets | jq -r '.Subnets[] | .VpcId + "," + .SubnetId + "," + .CidrBlock + "," + (first(.Tags[] | select(.Key == "Name").Value) // "")' | awk -F, 'BEGIN {formatStr="%21s %24s %18s %s\n"; printf(formatStr, "VPC Id", "Subnet ID", "CIDR", "Name")} {printf(formatStr , $1, $2, $3, $4)}' + else + aws ec2 describe-subnets --filters '[{"Name": "vpc-id", "Values": ["'$vpcId'"]}]' | jq -r '.Subnets[] | .VpcId + "," + .SubnetId + "," + .CidrBlock + "," + (first(.Tags[] | select(.Key == "Name").Value) // "")' | awk -F, 'BEGIN {formatStr="%21s %24s %18s %s\n"; printf(formatStr, "VPC Id", "Subnet ID", "CIDR", "Name")} {printf(formatStr , $1, $2, $3, $4)}' + fi +done diff --git a/Management-Utilities/fsx-ontap-aws-cli-scripts/list_aws_vpcs b/Management-Utilities/fsx-ontap-aws-cli-scripts/list_aws_vpcs new file mode 100755 index 0000000..3ecdc96 --- /dev/null +++ b/Management-Utilities/fsx-ontap-aws-cli-scripts/list_aws_vpcs @@ -0,0 +1,76 @@ +#!/bin/bash +# +# This script is used to list all VPCs in the AWS account. +################################################################################ +# +usage () { + cat 1>&2 < /dev/null 2>&1; then + : + else + echo "Error, $tool command is rquired to run this script." + exit 1 + fi +done + +allRegions=False +regions="" +subnets=False +quiet=False +while getopts "qsar:h" opt; do + case $opt in + a) allRegions=True + ;; + r) regions=$OPTARG + ;; + s) subnets=True + ;; + q) quiet=True + ;; + *) usage + ;; + esac +done + +tmpout=/tmp/list_aws_vpcs.$$ +trap 'rm -f $tmpout' exit + +if [ "$allRegions" == "True" ]; then + regions=$(aws ec2 describe-regions --query "Regions[].RegionName" --output=text) +else + if [ -z "$regions" ]; then + regions=$(aws configure get region) + fi +fi + +vpcFormatStr="%21s %19s %s\n" +for region in $regions; do + [ "$quiet" != "True" ] && printf "\nRegion: $region\n" + first=True + aws ec2 describe-vpcs --region $region | jq -r '.Vpcs[] | .VpcId + " " + .CidrBlock + " " + (if (.Tags != null) then (.Tags[] | (select(.Key == "Name") .Value)) else "" end)' | \ + while read vpcId cidr name; do + if [ "$quiet" != "True" -a "$first" == "True" ]; then + printf "\n$vpcFormatStr" "VPC IP" "CIDR" "Name" + first=False + fi + echo "$vpcId,$cidr,$name" | awk -F, '{printf "'"$vpcFormatStr"'", $1, $2, $3}' + + if [ "$subnets" == "True" ]; then + printf "\n\tSubnets:\n" + aws ec2 describe-subnets --filters '[{"Name": "vpc-id", "Values": ["'$vpcId'"]}]' | jq -r '.Subnets[] | .VpcId + " " + .SubnetId + " " + .CidrBlock + " " + (first(.Tags[] | select(.Key == "Name").Value) // "")' | awk 'BEGIN {formatStr="\t\t%24s %18s %s\n"; printf(formatStr, "Subnet ID", "CIDR", "Name")} {name=$4; for (i=5; i<=NF; i++) {name=name " " $(i)}; printf(formatStr , $2, $3, name)}' + first=True + fi + done +done