Skip to content

Commit af9bcfb

Browse files
committed
Added a -p option to include management and NAS IP address.
1 parent d8a29c2 commit af9bcfb

File tree

1 file changed

+33
-14
lines changed

1 file changed

+33
-14
lines changed

Management-Utilities/fsx-ontap-aws-cli-scripts/list_fsxn_svms

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
# o Region
1919
# o File system ID
2020
# o File System Name - optional
21+
# o The managment and NAS IP address of the SVM - optional
2122
# o SVM ID
2223
# o SVM Name
2324
################################################################################
@@ -27,9 +28,10 @@
2728
################################################################################
2829
usage () {
2930
cat 1>&2 <<EOF
30-
Usage $(basename $0) [-r region] [-a] [-n] [-i fileSystemID] [-f fileSystemName]
31+
Usage $(basename $0) [-r region] [-a] [-n] [-p] [-i fileSystemID] [-f fileSystemName]
3132
Where: -a means all regions
3233
-n means to include file systems name
34+
-p means to include the management and NAS IP address
3335
-i means to only include SVMs that reside under the FSxN file system with the fileSystemID.
3436
-f means to only include SVMs that reside under the FSxN file system with the file system name.
3537
EOF
@@ -55,15 +57,18 @@ fi
5557
# Process command line arguments.
5658
allRegions=false
5759
includeFsName=false
60+
includeIp=false
5861
region=$(aws configure list | egrep '^.*egion ' | awk '{print $2}')
59-
while getopts "hanr:i:f:" option; do
62+
while getopts "hanr:i:f:p" option; do
6063
case "$option" in
6164
r) region="$OPTARG"
6265
;;
6366
a) allRegions=true
6467
;;
6568
n) includeFsName=true
6669
;;
70+
p) includeIp=true
71+
;;
6772
i) fileSystemID="$OPTARG"
6873
;;
6974
f) fileSystemName="$OPTARG"
@@ -99,27 +104,41 @@ if [ "$allRegions" = "true" ]; then
99104
else
100105
regions=($region)
101106
fi
102-
103-
if [ ! -z "$fileSystemName" ]; then
104-
fileSystemID=$(aws fsx describe-file-systems --output=json --region=$region 2> /dev/null | jq -r '.FileSystems[] | if((.Tags[] | select(.Key == "Name") .Value) == "'"${fileSystemName}"'") then .FileSystemId else empty end' 2> /dev/null)
105-
if [ -z "$fileSystemID" ]; then
106-
echo "Error, failed to find a file system with the name '$fileSystemName'. Maybe in a different region?" 1>&2
107-
exit 1
108-
fi
109-
fi
110107
#
111108
# Loop on all the regions.
112109
for region in ${regions[*]}; do
110+
if [ ! -z "$fileSystemName" ]; then
111+
fileSystemID=$(aws fsx describe-file-systems --output=json --region=$region 2> /dev/null | jq -r '.FileSystems[] | if((.Tags[] | select(.Key == "Name") .Value) == "'"${fileSystemName}"'") then .FileSystemId else empty end' 2> /dev/null)
112+
if [ -z "$fileSystemID" ]; then
113+
if [ "$allRegions" != "true" ]; then
114+
echo "Error, failed to find a file system with the name '$fileSystemName'. Maybe in a different region?" 1>&2
115+
exit 1
116+
else
117+
#
118+
# If there isn't a file system with that name in this region, then just skip region.
119+
continue
120+
fi
121+
fi
122+
fi
123+
113124
if [ -z "$fileSystemID" ]; then
114-
aws fsx describe-storage-virtual-machines --region=$region | jq -r '.StorageVirtualMachines[] | .FileSystemId + "," + .StorageVirtualMachineId + "," + .Name' | sort > $tmpout
125+
filter=""
126+
else
127+
filter="--filter Name=file-system-id,Values=$fileSystemID"
128+
fi
129+
aws fsx describe-storage-virtual-machines --region=$region $filter | jq -r '.StorageVirtualMachines[] | "\(.FileSystemId),\(.StorageVirtualMachineId),\(.Endpoints.Nfs.IpAddresses[0]),\(.Name)"' | sort > $tmpout
130+
if [ $includeIp == "true" ]; then
131+
ipFmt="%16s"
132+
ipHeader="IP"
115133
else
116-
aws fsx describe-storage-virtual-machines --region=$region | jq -r '.StorageVirtualMachines[] | if(.FileSystemId == "'$fileSystemID'") then .FileSystemId + "," + .StorageVirtualMachineId + "," + .Name else empty end' | sort > $tmpout
134+
ipFmt="%0s"
135+
ipHeader=""
117136
fi
118137

119138
if [ $includeFsName == "true" ]; then
120139
aws fsx describe-file-systems --region=$region | jq -r '.FileSystems[] | .FileSystemId + "," + (.Tags[] | select(.Key == "Name") .Value)' > $tmpout2
121-
awk -F, -v region=$region 'BEGIN {first=1; maxNameLen=0; while(getline < "'$tmpout2'") {fss[$1]=$2; if(length($2) > maxNameLen) {maxNameLen=length($2)}}; maxNameLen +=2; formatStr="%12s %20s%-"maxNameLen"s %23s %s\n"}; {if(first) {printf "\n"; printf formatStr, "Region", "FileSystem ID", "(Name)", "SVM ID", "SVM Name"; first=0}; name="("fss[$1]")"; printf formatStr, region, $1, name, $2, $3}' < $tmpout
140+
awk -F, -v region=$region -v ipFmt=$ipFmt -v ipHeader=$ipHeader 'BEGIN {first=1; maxNameLen=0; while(getline < "'$tmpout2'") {fss[$1]=$2; if(length($2) > maxNameLen) {maxNameLen=length($2)}}; maxNameLen +=2; formatStr="%12s %20s%-"maxNameLen"s %23s "ipFmt" %s\n"}; {if(first) {printf "\n"; printf formatStr, "Region", "FileSystem ID", "(Name)", "SVM ID", ipHeader, "SVM Name"; first=0}; if(ipHeader != "IP") {ip=""} else {ip=$3}; name="("fss[$1]")"; printf formatStr, region, $1, name, $2, ip, $4}' < $tmpout
122141
else
123-
awk -F, -v region=$region 'BEGIN {first=1; formatStr="%12s %23s %23s %s\n"}; {if(first) {printf "\n"; printf formatStr, "Region", "FileSystem ID", "SVM ID", "SVM Name"; first=0}; printf formatStr, region, $1, $2, $3}' < $tmpout
142+
awk -F, -v region=$region -v ipFmt=$ipFmt -v ipHeader=$ipHeader 'BEGIN {first=1; formatStr="%12s %23s %23s "ipFmt" %s\n"}; {if(first) {printf "\n"; printf formatStr, "Region", "FileSystem ID", "SVM ID", ipHeader, "SVM Name"; first=0}; if(ipHeader != "IP") {ip=""} else {ip=$3}; printf formatStr, region, $1, $2, ip, $4}' < $tmpout
124143
fi
125144
done

0 commit comments

Comments
 (0)