|
18 | 18 | # o Region |
19 | 19 | # o File system ID |
20 | 20 | # o File System Name - optional |
| 21 | +# o The managment and NAS IP address of the SVM - optional |
21 | 22 | # o SVM ID |
22 | 23 | # o SVM Name |
23 | 24 | ################################################################################ |
|
27 | 28 | ################################################################################ |
28 | 29 | usage () { |
29 | 30 | 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] |
31 | 32 | Where: -a means all regions |
32 | 33 | -n means to include file systems name |
| 34 | + -p means to include the management and NAS IP address |
33 | 35 | -i means to only include SVMs that reside under the FSxN file system with the fileSystemID. |
34 | 36 | -f means to only include SVMs that reside under the FSxN file system with the file system name. |
35 | 37 | EOF |
|
55 | 57 | # Process command line arguments. |
56 | 58 | allRegions=false |
57 | 59 | includeFsName=false |
| 60 | +includeIp=false |
58 | 61 | 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 |
60 | 63 | case "$option" in |
61 | 64 | r) region="$OPTARG" |
62 | 65 | ;; |
63 | 66 | a) allRegions=true |
64 | 67 | ;; |
65 | 68 | n) includeFsName=true |
66 | 69 | ;; |
| 70 | + p) includeIp=true |
| 71 | + ;; |
67 | 72 | i) fileSystemID="$OPTARG" |
68 | 73 | ;; |
69 | 74 | f) fileSystemName="$OPTARG" |
@@ -99,27 +104,41 @@ if [ "$allRegions" = "true" ]; then |
99 | 104 | else |
100 | 105 | regions=($region) |
101 | 106 | 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 |
110 | 107 | # |
111 | 108 | # Loop on all the regions. |
112 | 109 | 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 | + |
113 | 124 | 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" |
115 | 133 | 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="" |
117 | 136 | fi |
118 | 137 |
|
119 | 138 | if [ $includeFsName == "true" ]; then |
120 | 139 | 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 |
122 | 141 | 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 |
124 | 143 | fi |
125 | 144 | done |
0 commit comments