Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding new scripts #191

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Management-Utilities/fsx-ontap-aws-cli-scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand Down
58 changes: 58 additions & 0 deletions Management-Utilities/fsx-ontap-aws-cli-scripts/list_aws_subnets
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash
#
# This script is used to list all VPCs in the AWS account.
################################################################################
#
usage () {
cat 1>&2 <<EOF
Usage: $(basename $0) [-a] [-r region] [-v vpcId]
Where:
vpcId is the VPC id to list the subnets for.
EOF
exit 1
}
#
# Check if the required tools are installed
for tool in aws jq; do
if which $tool > /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
76 changes: 76 additions & 0 deletions Management-Utilities/fsx-ontap-aws-cli-scripts/list_aws_vpcs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/bin/bash
#
# This script is used to list all VPCs in the AWS account.
################################################################################
#
usage () {
cat 1>&2 <<EOF
Usage: $(basename $0) [-a] [-r region] [-s]
where: -a list - All regions
-r region - List VPCs in the specified region
-s - List all the subnets in the VPC
-q - Supress extraineous output
-h - Print this help message
EOF
exit 1
}

# Check if the required tools are installed
for tool in aws jq; do
if which $tool > /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