diff --git a/Management-Utilities/Workload-Factory-API-Samples/list_filesystems b/Management-Utilities/Workload-Factory-API-Samples/list_filesystems index a2e59f14..c94fece5 100755 --- a/Management-Utilities/Workload-Factory-API-Samples/list_filesystems +++ b/Management-Utilities/Workload-Factory-API-Samples/list_filesystems @@ -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: @@ -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 # @@ -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 @@ -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 @@ -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 : @@ -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 diff --git a/Management-Utilities/Workload-Factory-API-Samples/show_fsxn_credentials b/Management-Utilities/Workload-Factory-API-Samples/show_fsxn_credentials index 6cd202d2..bb33a756 100755 --- a/Management-Utilities/Workload-Factory-API-Samples/show_fsxn_credentials +++ b/Management-Utilities/Workload-Factory-API-Samples/show_fsxn_credentials @@ -15,7 +15,7 @@ usage() { cat >&2 < /dev/null 2>&1 if [ $? -ne 127 ]; then cat $tmpdir/${pids[$pid]}.out 2> /dev/null unset pids[$pid] diff --git a/Management-Utilities/fsx-ontap-aws-cli-scripts/list_fsxn_svms b/Management-Utilities/fsx-ontap-aws-cli-scripts/list_fsxn_svms index 27091787..d7e00455 100755 --- a/Management-Utilities/fsx-ontap-aws-cli-scripts/list_fsxn_svms +++ b/Management-Utilities/fsx-ontap-aws-cli-scripts/list_fsxn_svms @@ -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. ################################################################################ @@ -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 @@ -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 @@ -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] diff --git a/Management-Utilities/fsx-ontap-aws-cli-scripts/list_fsxn_volumes b/Management-Utilities/fsx-ontap-aws-cli-scripts/list_fsxn_volumes index af879214..6350457c 100755 --- a/Management-Utilities/fsx-ontap-aws-cli-scripts/list_fsxn_volumes +++ b/Management-Utilities/fsx-ontap-aws-cli-scripts/list_fsxn_volumes @@ -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. ################################################################################ @@ -211,7 +230,7 @@ fi # # Process command line arguments. allRegions=false -excludeRegions="none" +: ${excludeRegions:="none"} region=$(aws configure get region) includeFsName=false excludeRoot=false @@ -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 @@ -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]