Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ Where: refresh_token - Is a refresh token used to obtain an access token needed
token by going to https://services.cloud.netapp.com/refresh-token
blueXP_account_ID - is the BlueXP account ID. Run 'list_bluexp_accts' to get a
list of accounts you have access to.
credentials_ID - is the Workload Factory credentials ID for the AWS account.
credentials_ID - Limit the list to only the file systems that are associated with
the specified credentials ID.
Run 'list_credentials' to get a list of Workload Factory
credentials you have access to.
aws_region - is the AWS region where you want the list of FSx file system from.
aws_region - Limit the list to only the file systems in the specified AWS region.

Instead of passing parameters on the command line, you can set the
following environment variables:
Expand Down Expand Up @@ -84,10 +85,6 @@ required_options["REFRESH_TOKEN"]='Error: A BlueXP refresh tokon is required to
required_options["BLUEXP_ACCOUNT_ID"]='Error: A BlueXP account ID is required to run this script.
You can get the list of accounts you have access to by running the "list_bluexp_accts" script
found in this GitHub repository: https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples\n\n'
required_options["CREDENTIALS_ID"]='Error: The Workload Factory credentials ID used to list resources is required to run this script.
You can get a list of credentials by running the "list_credentials" script
found in this GitHub repository: https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples\n\n'
required_options["AWS_REGION"]='Error: The AWS region where the file system is located is required.\n\n'

check_required_options
#
Expand All @@ -106,8 +103,19 @@ if [ -z "$token" ]; then
exit 1
fi

jq_query='.items[] | "\(.id),\(.name),\(.region),\(.deploymentType),\(.status.status)"'
run_curl GET "$token" "https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/fsx/v2/credentials/${CREDENTIALS_ID}/regions/${AWS_REGION}/file-systems" $tmpout $tmperr
jq_query='.items[] | "\(.id),\(.name),\(.region),\(.deploymentType),\(.status.status)," + (.credentialsIds | join(" "))'
if [ ! -z "$AWS_REGION" ]; then
regionPayload='"regions":["'"$AWS_REGION"'"]'
else
regionPayload=''
fi
if [ ! -z "$CREDENTIALS_ID" ]; then
credentialsPayload='"credentialsIds":["'"$CREDENTIALS_ID"'"]'
else
credentialsPayload=''
fi
payload="{${regionPayload}${regionPayload:+,}${credentialsPayload}}"
run_curl POST "$token" "https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/fsx/v2/file-systems/discovery" $tmpout $tmperr "$payload"
if jq -r "$jq_query" $tmpout > $tmpout2 2> $tmperr; then
:
else
Expand All @@ -119,7 +127,7 @@ fi
# Check to see if there are more.
nextToken=$(jq -r '.nextToken' $tmpout)
while [ "$nextToken" != "null" ]; do
run_curl GET "$token" "https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/fsx/v2/credentials/${CREDENTIALS_ID}/regions/${AWS_REGION}/file-systems?nextToken=${nextToken}" $tmpout $tmperr
run_curl POST "$token" "https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/fsx/v2/file-systems/discovery?nextToken=${nextToken}" $tmpout $tmperr "$payload"
if jq -r "$jq_query" $tmpout >> $tmpout2 2> $tmperr; then
:
else
Expand All @@ -129,8 +137,9 @@ while [ "$nextToken" != "null" ]; do
fi
nextToken=$(jq -r '.nextToken' $tmpout)
done

jq_query='.items[] | .clusterUuid + "," + .name + ",N/A,On-Prem," + if(.connected) then "AVAILABLE" else "UNKNOWN" end'
#
# Check to see if there are any on-prem systems.
jq_query='.items[] | .clusterUuid + "," + .name + ",N/A,On-Prem," + if(.connected) then "AVAILABLE," else "UNKNOWN," end + .credentialId'
run_curl GET "$token" "https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/onprem/v1/onprems" $tmpout $tmperr
if jq -r "$jq_query" $tmpout >> $tmpout2 2> $tmperr; then
:
Expand All @@ -153,4 +162,4 @@ while [ "$nextToken" != "null" ]; do
fi
nextToken=$(jq -r '.nextToken' $tmpout)
done
sort -t, -f -k 2,2 $tmpout2 | column -t -s, -N ID,Name,Region,Deployment_Type,Status
sort -t, -f -k 2,2 $tmpout2 | column -t -s, -N ID,Name,Region,Deployment_Type,Status,Credential_IDs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
usage() {
cat >&2 <<EOF

Usage: $(basename $0) -t refresh_token -a blueXP_account_ID -f filesystem_ID [-o]
Usage: $(basename $0) -t refresh_token -a blueXP_account_ID -f filesystem_ID
This script is used to show the FSx for ONTAP credentails that Workload
Factory has for the specified file system.

Expand Down Expand Up @@ -63,13 +63,11 @@ fi
# Process command line options.
#
# Set defaults.
filter="filter=$(urlencode "type eq 'AWS_ASSUME_ROLE'")"
while getopts "ht:a:of:" opt; do
while getopts "ht:a:f:" opt; do
case $opt in
t) REFRESH_TOKEN="$OPTARG" ;;
a) BLUEXP_ACCOUNT_ID="$OPTARG" ;;
f) FILESYSTEM_ID="$OPTARG" ;;
o) filter="";; # No filter, list all credentials.
*) usage ;;
esac
done
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,25 @@ start_watchdog () {
fi
}

################################################################################
# The following function echos "true" if the first argument is found in the
# second argument, which is a space separated list of values. Otherwise
# it echos "false".
################################################################################
inArray() {

region=$1
regions="$2"
for r in $regions; do
if [ "$r" == "$region" ]; then
echo "true"
return 1
fi
done
echo "false"
return 0
}

################################################################################
# This function is used to get the list of file systems for the region passed
# as the first argument.
Expand Down Expand Up @@ -267,7 +286,7 @@ showStatus=false
showARN=false
showBackup=false
region=$(aws configure get region)
excludeRegions="none"
: ${excludeRegions:="none"}
maxTime=20
#
# Process command line arguments.
Expand Down Expand Up @@ -332,7 +351,10 @@ if [ "$allRegions" == "true" ]; then
allFsxnRegions=$(curl -s https://api.regional-table.region-services.aws.a2z.com/index.json | jq -r '.prices[] | select(.attributes."aws:serviceName" == "Amazon FSx for NetApp ONTAP") .attributes."aws:region"' | egrep -v "$excludeRegions")
for reg in $allEndabledRegions; do
for fsxnReg in $allFsxnRegions; do
if [ $reg == $fsxnReg ]; then
#
# Since for some crazy reason AWS decided to add duplicate entries in their
# regional table, we need to make sure we don't add duplicates to our list of regions.
if [ $reg == $fsxnReg ] && [ $(inArray $reg "${regions[*]}") == "false" ]; then
regions+=($reg)
fi
done
Expand Down Expand Up @@ -379,7 +401,7 @@ for region in ${regions[*]}; do
done

while [ ${#pids[@]} -gt 0 ]; do
wait -n -p pid "${!pids[@]}"
wait -n -p pid "${!pids[@]}" > /dev/null 2>&1
if [ $? -ne 127 ]; then
cat $tmpdir/${pids[$pid]}.out 2> /dev/null
unset pids[$pid]
Expand Down
28 changes: 25 additions & 3 deletions Management-Utilities/fsx-ontap-aws-cli-scripts/list_fsxn_svms
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,25 @@ start_watchdog () {
fi
}

################################################################################
# The following function echos "true" if the first argument is found in the
# second argument, which is a space separated list of values. Otherwise
# it echos "false".
################################################################################
inArray() {

region=$1
regions="$2"
for r in $regions; do
if [ "$r" == "$region" ]; then
echo "true"
return 1
fi
done
echo "false"
return 0
}

################################################################################
# This function will list all the SVMs in the specified region.
################################################################################
Expand Down Expand Up @@ -135,7 +154,7 @@ allRegions=false
includeFsName=false
includeIp=false
region=$(aws configure get region)
excludeRegions="none"
: ${excludeRegions:="none"}
maxTime=20
while getopts "haX:nr:i:f:pe:t:" option; do
case "$option" in
Expand Down Expand Up @@ -176,7 +195,10 @@ if [ "$allRegions" = "true" ]; then
allFsxnRegions=$(curl -s https://api.regional-table.region-services.aws.a2z.com/index.json | jq -r '.prices[] | select(.attributes."aws:serviceName" == "Amazon FSx for NetApp ONTAP") .attributes."aws:region"' | egrep -v "$excludeRegions")
for reg in $allEndabledRegions; do
for fsxnReg in $allFsxnRegions; do
if [ $reg == $fsxnReg ]; then
#
# Since for some crazy reason AWS decided to add duplicate entries in their
# regional table, we need to make sure we don't add duplicates to our list of regions.
if [ $reg == $fsxnReg ] && [ $(inArray $reg "${regions[*]}") == "false" ]; then
regions+=($reg)
fi
done
Expand All @@ -198,7 +220,7 @@ for region in ${regions[*]}; do
done

while [ ${#pids[@]} -gt 0 ]; do
wait -n -p pid "${!pids[@]}"
wait -n -p pid "${!pids[@]}" > /dev/null 2>&1
if [ $? -ne 127 ]; then
cat $tmpdir/${pids[$pid]}.out 2> /dev/null
unset pids[$pid]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,25 @@ start_watchdog () {
fi
}

################################################################################
# The following function echos "true" if the first argument is found in the
# second argument, which is a space separated list of values. Otherwise
# it echos "false".
################################################################################
inArray() {

region=$1
regions="$2"
for r in $regions; do
if [ "$r" == "$region" ]; then
echo "true"
return 1
fi
done
echo "false"
return 0
}

################################################################################
# This function will get the list of volumes for a given region.
################################################################################
Expand Down Expand Up @@ -211,7 +230,7 @@ fi
#
# Process command line arguments.
allRegions=false
excludeRegions="none"
: ${excludeRegions:="none"}
region=$(aws configure get region)
includeFsName=false
excludeRoot=false
Expand Down Expand Up @@ -274,7 +293,10 @@ if [ "$allRegions" = "true" ]; then
allFsxnRegions=$(curl -s https://api.regional-table.region-services.aws.a2z.com/index.json | jq -r '.prices[] | select(.attributes."aws:serviceName" == "Amazon FSx for NetApp ONTAP") .attributes."aws:region"' | egrep -v $excludeRegions)
for reg in $allEndabledRegions; do
for fsxnReg in $allFsxnRegions; do
if [ $reg == $fsxnReg ]; then
#
# Since for some crazy reason AWS decided to add duplicate entries in their
# regional table, we need to make sure we don't add duplicates to our list of regions.
if [ $reg == $fsxnReg ] && [ $(inArray $reg "${regions[*]}") == "false" ]; then
regions+=($reg)
fi
done
Expand All @@ -296,7 +318,7 @@ for region in ${regions[*]}; do
done

while [ ${#pids[@]} -gt 0 ]; do
wait -n -p pid "${!pids[@]}"
wait -n -p pid "${!pids[@]}" > /dev/null 2>&1
if [ $? -ne 127 ]; then
cat $tmpdir/${pids[$pid]}.out 2> /dev/null
unset pids[$pid]
Expand Down
Loading