diff --git a/Management-Utilities/Workload-Factory-API-Samples/bluexp_fsxn_discovery b/Management-Utilities/Workload-Factory-API-Samples/bluexp_fsxn_discovery index 0a167ba..0ce40b4 100755 --- a/Management-Utilities/Workload-Factory-API-Samples/bluexp_fsxn_discovery +++ b/Management-Utilities/Workload-Factory-API-Samples/bluexp_fsxn_discovery @@ -100,7 +100,7 @@ required_options["REFRESH_TOKEN"]='Error: A BlueXP refresh token 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 ID of the credentials to delete is required. +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' diff --git a/Management-Utilities/Workload-Factory-API-Samples/cicd_clones_create b/Management-Utilities/Workload-Factory-API-Samples/cicd_clones_create new file mode 100755 index 0000000..717de6d --- /dev/null +++ b/Management-Utilities/Workload-Factory-API-Samples/cicd_clones_create @@ -0,0 +1,124 @@ +#!/bin/bash +# +################################################################################ +# This script is used to create a EDA CI/CD clone. +# +# It is dependent on the 'wf_utils' file that is included in this repo. That +# file contains the 'get_token' function that is used to obtain a valid +# access token that is needed to run the Workload Factory APIs. The file needs +# to either be in the command search path or in the current directory. +################################################################################ + +################################################################################ +# This function just prints the usage of this script and exits the program. +################################################################################ +usage() { + cat >&2 < + export BLUEXP_ACCOUNT_ID= + export PROJECT_ID= +EOF + exit 1 +} + +################################################################################ +# Main logic starts here. +################################################################################ +tmpout=$(mktemp /tmp/list_volumes-out.XXXXXX) +tmpout2=$(mktemp /tmp/list_volumes-out2.XXXXXX) +tmperr=$(mktemp /tmp/list_volumes-err.XXXXXX) +trap 'rm -f $tmpout $tmpout2 $tmperr' exit +# +# Source the wf_utils file. +wf_utils=$(command -v wf_utils) +if [ -z "$wf_utils" ]; then + if [ ! -x "./wf_utils" ]; then + cat >&2 < /dev/null; then + echo "Error: The required command '$cmd' not found. Please install it." >&2 + exit 1 + fi +done + +token=$(get_token) +if [ -z "$token" ]; then + echo "Error: Failed to obtain an access token. Exiting." >&2 + exit 1 +fi + +URL="https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/builders/v1/projects" +run_curl GET "$token" "$URL" $tmpout $tmperr +VOLUME_ID=$(jq -r '.items[] | select(.projectId == "'$PROJECT_ID'") | .volumeId' $tmpout) +if [ -z "$VOLUME_ID" ]; then + echo "Error: Failed to obtain the volume ID for the project. Exiting." >&2 + exit 1 +fi + +body='{ + "cloneName": "'$CLONE_NAME'", + '$SNAPSHOT_NAME' + "parentVolumeId": "'$VOLUME_ID'" +}' + +URL="https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/builders/v1/projects/${PROJECT_ID}/operations/clone" +run_curl POST "$token" "$URL" $tmpout $tmperr "$body" +echo "The CI/CD clone $CLONE_NAME was created and is mountable at $(jq -r '.mountPoints[0].mountPoint' $tmpout)." diff --git a/Management-Utilities/Workload-Factory-API-Samples/cicd_clones_delete b/Management-Utilities/Workload-Factory-API-Samples/cicd_clones_delete new file mode 100755 index 0000000..a9cd9d6 --- /dev/null +++ b/Management-Utilities/Workload-Factory-API-Samples/cicd_clones_delete @@ -0,0 +1,108 @@ +#!/bin/bash +# +################################################################################ +# This script is used to delete a EDA CI/CD clone. +# +# It is dependent on the 'wf_utils' file that is included in this repo. That +# file contains the 'get_token' function that is used to obtain a valid +# access token that is needed to run the Workload Factory APIs. The file needs +# to either be in the command search path or in the current directory. +################################################################################ + +################################################################################ +# This function just prints the usage of this script and exits the program. +################################################################################ +usage() { + cat >&2 < + export BLUEXP_ACCOUNT_ID= + export PROJECT_ID= +EOF + exit 1 +} + +################################################################################ +# Main logic starts here. +################################################################################ +tmpout=$(mktemp /tmp/list_volumes-out.XXXXXX) +tmpout2=$(mktemp /tmp/list_volumes-out2.XXXXXX) +tmperr=$(mktemp /tmp/list_volumes-err.XXXXXX) +trap 'rm -f $tmpout $tmpout2 $tmperr' exit +# +# Source the wf_utils file. +wf_utils=$(command -v wf_utils) +if [ -z "$wf_utils" ]; then + if [ ! -x "./wf_utils" ]; then + cat >&2 < /dev/null; then + echo "Error: The required command '$cmd' not found. Please install it." >&2 + exit 1 + fi +done + +token=$(get_token) +if [ -z "$token" ]; then + echo "Error: Failed to obtain an access token. Exiting." >&2 + exit 1 +fi + +URL="https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/builders/v1/projects/${PROJECT_ID}/operations/clones/${CLONE_VOLUME_ID}" +run_curl DELETE "$token" "$URL" $tmpout $tmperr +echo "The CI/CD clone $CLONE_VOLUME_ID was deleted." diff --git a/Management-Utilities/Workload-Factory-API-Samples/cicd_project_create b/Management-Utilities/Workload-Factory-API-Samples/cicd_project_create new file mode 100755 index 0000000..104f4bc --- /dev/null +++ b/Management-Utilities/Workload-Factory-API-Samples/cicd_project_create @@ -0,0 +1,132 @@ +#!/bin/bash +# +################################################################################ +# This script is used to create a EDA CI/CD project. +# +# It is dependent on the 'wf_utils' file that is included in this repo. That +# file contains the 'get_token' function that is used to obtain a valid +# access token that is needed to run the Workload Factory APIs. The file needs +# to either be in the command search path or in the current directory. +################################################################################ + +################################################################################ +# This function just prints the usage of this script and exits the program. +################################################################################ +usage() { + cat >&2 < + export BLUEXP_ACCOUNT_ID= + export PROJECT_NAME= + export AWS_REGION= +EOF + exit 1 +} + +################################################################################ +# Main logic starts here. +################################################################################ +tmpout=$(mktemp /tmp/list_volumes-out.XXXXXX) +tmpout2=$(mktemp /tmp/list_volumes-out2.XXXXXX) +tmperr=$(mktemp /tmp/list_volumes-err.XXXXXX) +trap 'rm -f $tmpout $tmpout2 $tmperr' exit +# +# Source the wf_utils file. +wf_utils=$(command -v wf_utils) +if [ -z "$wf_utils" ]; then + if [ ! -x "./wf_utils" ]; then + cat >&2 < /dev/null; then + echo "Error: The required command '$cmd' not found. Please install it." >&2 + exit 1 + fi +done + +token=$(get_token) +if [ -z "$token" ]; then + echo "Error: Failed to obtain an access token. Exiting." >&2 + exit 1 +fi + +body='{ + "name": "'$PROJECT_NAME'", + "credentials_id": "'$CREDENTIALS_ID'", + "volumes": [ + { + "id": "'$VOLUME_ID'", + "region": "'$AWS_REGION'", + "fileSystemId": "'$FILESYSTEM_ID'", + "credentialsId": "'$CREDENTIALS_ID'" + } + ], + "operationPolicy": { + "max_clone_number": 0, + "max_clone_size": 0, + "max_days_retention": 0 + } +}' + +URL="https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/builders/v1/projects" +run_curl POST "$token" "$URL" $tmpout $tmperr "$body" +echo "return status=$?" +echo "Project $PROJECT_NAME has been created." diff --git a/Management-Utilities/Workload-Factory-API-Samples/cicd_project_delete b/Management-Utilities/Workload-Factory-API-Samples/cicd_project_delete new file mode 100755 index 0000000..650d09a --- /dev/null +++ b/Management-Utilities/Workload-Factory-API-Samples/cicd_project_delete @@ -0,0 +1,101 @@ +#!/bin/bash +# +################################################################################ +# This script is used to delete a EDA CI/CD project. +# +# It is dependent on the 'wf_utils' file that is included in this repo. That +# file contains the 'get_token' function that is used to obtain a valid +# access token that is needed to run the Workload Factory APIs. The file needs +# to either be in the command search path or in the current directory. +################################################################################ + +################################################################################ +# This function just prints the usage of this script and exits the program. +################################################################################ +usage() { + cat >&2 < + export BLUEXP_ACCOUNT_ID= +EOF + exit 1 +} + +################################################################################ +# Main logic starts here. +################################################################################ +tmpout=$(mktemp /tmp/list_volumes-out.XXXXXX) +tmpout2=$(mktemp /tmp/list_volumes-out2.XXXXXX) +tmperr=$(mktemp /tmp/list_volumes-err.XXXXXX) +trap 'rm -f $tmpout $tmpout2 $tmperr' exit +# +# Source the wf_utils file. +wf_utils=$(command -v wf_utils) +if [ -z "$wf_utils" ]; then + if [ ! -x "./wf_utils" ]; then + cat >&2 < /dev/null; then + echo "Error: The required command '$cmd' not found. Please install it." >&2 + exit 1 + fi +done + +token=$(get_token) +if [ -z "$token" ]; then + echo "Error: Failed to obtain an access token. Exiting." >&2 + exit 1 +fi + +URL="https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/builders/v1/projects/$projectId" +run_curl DELETE "$token" "$URL" $tmpout $tmperr +echo "Project with ID $projectId has been deleted." diff --git a/Management-Utilities/Workload-Factory-API-Samples/eda_project_config_create b/Management-Utilities/Workload-Factory-API-Samples/eda_project_config_create new file mode 100755 index 0000000..b2cd484 --- /dev/null +++ b/Management-Utilities/Workload-Factory-API-Samples/eda_project_config_create @@ -0,0 +1,142 @@ +#!/bin/bash +# +################################################################################ +# This script is used to create the EDA Project filter user has access to. +# +# It is dependent on the 'wf_utils' file that is included in this repo. That +# file contains the 'get_token' function that is used to obtain a valid +# access token that is needed to run the Workload Factory APIs. The file needs +# to either be in the command search path or in the current directory. +################################################################################ + +################################################################################ +# This function just prints the usage of this script and exits the program. +################################################################################ +usage() { + cat >&2 < + export BLUEXP_ACCOUNT_ID= +EOF + exit 1 +} + +################################################################################ +# Main logic starts here. +################################################################################ +tmpout=$(mktemp /tmp/list_volumes-out.XXXXXX) +tmpout2=$(mktemp /tmp/list_volumes-out2.XXXXXX) +tmperr=$(mktemp /tmp/list_volumes-err.XXXXXX) +trap 'rm -f $tmpout $tmpout2 $tmperr' exit +# +# Source the wf_utils file. +wf_utils=$(command -v wf_utils) +if [ -z "$wf_utils" ]; then + if [ ! -x "./wf_utils" ]; then + cat >&2 <&2 + usage +else + if [ ${#filter_types[@]} -gt 0 -a ${#tags[@]} -ne ${#filter_types[@]} ]; then + echo "Error: If you specify the filter types, you must specify a filter type for all the tags." >&2 + usage + fi +fi +# +# Check that the required commands are available. +for cmd in jq curl; do + if ! command -v $cmd &> /dev/null; then + echo "Error: The required command '$cmd' not found. Please install it." >&2 + exit 1 + fi +done + +token=$(get_token) +if [ -z "$token" ]; then + echo "Error: Failed to obtain an access token. Exiting." >&2 + exit 1 +fi + +body='{ "filters": [ { "tags": [ ' +i=0 +while [ $i -lt ${#tags[@]} ]; do + filter_type="multiselect" + if [ ${#filter_types[@]} -gt 0 ]; then + filter_type="${filter_types[$i]}" + if [ $filter_type != "single" -a $filter_type != "multiselect" ]; then + echo "Error: Invalid filter type '$filter_type' for tag '${tags[$i]}'. Filter type must be either 'single' or 'multiselect'." >&2 + usage + fi + fi + body+='{ + "key": "'${tags[$i]}'", + "label": "'${tags[$i]}'", + "type": "'$filter_type'", + "target": "tag" + }' + let i=i+1 + if [ $i -lt ${#tags[@]} ]; then + body+=',' + fi +done +body+='], "resourceProps": [ { + "propName": "OntapVolumeType", + "label": "Volume Type", + "type": "single" } + ] } ], + "status": "active" }' + +URL="https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/builders/v1/configure" +run_curl POST "$token" "$URL" $tmpout $tmperr "$body" +echo "Project filter created." diff --git a/Management-Utilities/Workload-Factory-API-Samples/eda_project_config_delete b/Management-Utilities/Workload-Factory-API-Samples/eda_project_config_delete new file mode 100755 index 0000000..91613fb --- /dev/null +++ b/Management-Utilities/Workload-Factory-API-Samples/eda_project_config_delete @@ -0,0 +1,94 @@ +#!/bin/bash +# +################################################################################ +# This script is used to delete the EDA Project filter user has access to. +# +# It is dependent on the 'wf_utils' file that is included in this repo. That +# file contains the 'get_token' function that is used to obtain a valid +# access token that is needed to run the Workload Factory APIs. The file needs +# to either be in the command search path or in the current directory. +################################################################################ + +################################################################################ +# This function just prints the usage of this script and exits the program. +################################################################################ +usage() { + cat >&2 < + export BLUEXP_ACCOUNT_ID= +EOF + exit 1 +} + +################################################################################ +# Main logic starts here. +################################################################################ +tmpout=$(mktemp /tmp/list_volumes-out.XXXXXX) +tmperr=$(mktemp /tmp/list_volumes-err.XXXXXX) +trap 'rm -f $tmpout $tmperr' exit +# +# Source the wf_utils file. +wf_utils=$(command -v wf_utils) +if [ -z "$wf_utils" ]; then + if [ ! -x "./wf_utils" ]; then + cat >&2 < /dev/null; then + echo "Error: The required command '$cmd' not found. Please install it." >&2 + exit 1 + fi +done + +token=$(get_token) +if [ -z "$token" ]; then + echo "Error: Failed to obtain an access token. Exiting." >&2 + exit 1 +fi + +URL="https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/builders/v1/configure" +run_curl DELETE "$token" "$URL" $tmpout $tmperr +echo "EDA Project filter deleted successfully." diff --git a/Management-Utilities/Workload-Factory-API-Samples/fsxn_credentials_set b/Management-Utilities/Workload-Factory-API-Samples/fsxn_credentials_set index 68ee5b1..03a1db0 100755 --- a/Management-Utilities/Workload-Factory-API-Samples/fsxn_credentials_set +++ b/Management-Utilities/Workload-Factory-API-Samples/fsxn_credentials_set @@ -96,7 +96,7 @@ 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 ID of the credentials to delete is required. +required_options["CREDENTIALS_ID"]='Error: The Workload Factory credentials ID used to manage 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' diff --git a/Management-Utilities/Workload-Factory-API-Samples/link_associate b/Management-Utilities/Workload-Factory-API-Samples/link_associate index 9bc8c6f..b784cbc 100755 --- a/Management-Utilities/Workload-Factory-API-Samples/link_associate +++ b/Management-Utilities/Workload-Factory-API-Samples/link_associate @@ -83,7 +83,7 @@ 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 ID of the credentials to delete is required. +required_options["CREDENTIALS_ID"]='Error: The Workload Factory credentials ID used to manage 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' diff --git a/Management-Utilities/Workload-Factory-API-Samples/link_disassociate b/Management-Utilities/Workload-Factory-API-Samples/link_disassociate index 2bf73be..29b826d 100755 --- a/Management-Utilities/Workload-Factory-API-Samples/link_disassociate +++ b/Management-Utilities/Workload-Factory-API-Samples/link_disassociate @@ -83,7 +83,7 @@ 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 ID of the credentials to delete is required. +required_options["CREDENTIALS_ID"]='Error: The Workload Factory credentials ID used to manage 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' diff --git a/Management-Utilities/Workload-Factory-API-Samples/list_cicd_clones b/Management-Utilities/Workload-Factory-API-Samples/list_cicd_clones new file mode 100755 index 0000000..0c39eaa --- /dev/null +++ b/Management-Utilities/Workload-Factory-API-Samples/list_cicd_clones @@ -0,0 +1,136 @@ +#!/bin/bash +# +################################################################################ +# This script is used to list all the EDA CI/CD clones user has access to. +# +# It is dependent on the 'wf_utils' file that is included in this repo. That +# file contains the 'get_token' function that is used to obtain a valid +# access token that is needed to run the Workload Factory APIs. The file needs +# to either be in the command search path or in the current directory. +################################################################################ + +################################################################################ +# This function just prints the usage of this script and exits the program. +################################################################################ +usage() { + cat >&2 < + export BLUEXP_ACCOUNT_ID= + export PROJECT_ID= +EOF + exit 1 +} + +################################################################################ +# Main logic starts here. +################################################################################ +tmpout=$(mktemp /tmp/list_volumes-out.XXXXXX) +tmpout2=$(mktemp /tmp/list_volumes-out2.XXXXXX) +tmperr=$(mktemp /tmp/list_volumes-err.XXXXXX) +trap 'rm -f $tmpout $tmpout2 $tmperr' exit +# +# Source the wf_utils file. +wf_utils=$(command -v wf_utils) +if [ -z "$wf_utils" ]; then + if [ ! -x "./wf_utils" ]; then + cat >&2 < /dev/null; then + echo "Error: The required command '$cmd' not found. Please install it." >&2 + exit 1 + fi +done + +token=$(get_token) +if [ -z "$token" ]; then + echo "Error: Failed to obtain an access token. Exiting." >&2 + exit 1 +fi + +if [ "$raw" = true ]; then + jq_query='.' +else + jq_query='.items[] | "\(.name) \(.size/1024/1024/1024) \(.daysLeft) \(.volumeUuid) \(.status)"' +fi + +URL="https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/builders/v1/projects/${PROJECT_ID}/operations/clones" +run_curl GET "$token" "$URL" $tmpout $tmperr +if jq -r "$jq_query" $tmpout > $tmpout2 2> $tmperr; then + : +else + echo "Error: Failed to parse the output from the API." >&2 + cat $tmperr >&2 + exit 1 +fi +# +# Check to see if there are more. +nextToken=$(jq -r '.nextToken' $tmpout) +while [ "$nextToken" != "null" ]; do + run_curl GET "$token" "$URL?nextToken=${nextToken}" $tmpout $tmperr + if jq -r "$jq_query" $tmpout >> $tmpout2 2> $tmperr; then + : + else + echo "Error: Failed to parse the output from the API." >&2 + cat $tmperr >&2 + exit 1 + fi + nextToken=$(jq -r '.nextToken' $tmpout) +done +if [ "$raw" = true ]; then + cat $tmpout2 +else + sort -f $tmpout2 | column -t -N "Name,Size (GB),Days Left,Volume UUID,Status" +fi diff --git a/Management-Utilities/Workload-Factory-API-Samples/list_cicd_projects b/Management-Utilities/Workload-Factory-API-Samples/list_cicd_projects new file mode 100755 index 0000000..4f70137 --- /dev/null +++ b/Management-Utilities/Workload-Factory-API-Samples/list_cicd_projects @@ -0,0 +1,129 @@ +#!/bin/bash +# +################################################################################ +# This script is used to list all the EDA CI/CD projects user has access to. +# +# It is dependent on the 'wf_utils' file that is included in this repo. That +# file contains the 'get_token' function that is used to obtain a valid +# access token that is needed to run the Workload Factory APIs. The file needs +# to either be in the command search path or in the current directory. +################################################################################ + +################################################################################ +# This function just prints the usage of this script and exits the program. +################################################################################ +usage() { + cat >&2 < + export BLUEXP_ACCOUNT_ID= +EOF + exit 1 +} + +################################################################################ +# Main logic starts here. +################################################################################ +tmpout=$(mktemp /tmp/list_volumes-out.XXXXXX) +tmpout2=$(mktemp /tmp/list_volumes-out2.XXXXXX) +tmperr=$(mktemp /tmp/list_volumes-err.XXXXXX) +trap 'rm -f $tmpout $tmpout2 $tmperr' exit +# +# Source the wf_utils file. +wf_utils=$(command -v wf_utils) +if [ -z "$wf_utils" ]; then + if [ ! -x "./wf_utils" ]; then + cat >&2 < /dev/null; then + echo "Error: The required command '$cmd' not found. Please install it." >&2 + exit 1 + fi +done + +token=$(get_token) +if [ -z "$token" ]; then + echo "Error: Failed to obtain an access token. Exiting." >&2 + exit 1 +fi + +if [ "$raw" = true ]; then + jq_query='.' +else + jq_query='.items[] | "\(.projectName) \(.projectId) \(.fileSystemId) \(.volumeName) \(.volumeId) \(.numberOfClones)"' +fi + +URL="https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/builders/v1/projects" +run_curl GET "$token" "$URL" $tmpout $tmperr +if jq -r "$jq_query" $tmpout > $tmpout2 2> $tmperr; then + : +else + echo "Error: Failed to parse the output from the API." >&2 + cat $tmperr >&2 + exit 1 +fi +# +# Check to see if there are more. +nextToken=$(jq -r '.nextToken' $tmpout) +while [ "$nextToken" != "null" ]; do + run_curl GET "$token" "$URL?nextToken=${nextToken}" $tmpout $tmperr + if jq -r "$jq_query" $tmpout >> $tmpout2 2> $tmperr; then + : + else + echo "Error: Failed to parse the output from the API." >&2 + cat $tmperr >&2 + exit 1 + fi + nextToken=$(jq -r '.nextToken' $tmpout) +done +if [ "$raw" = true ]; then + cat $tmpout2 +else + sort -f $tmpout2 | column -t -N "Name,Project ID,File System,Volume Name,Volume ID,Number of Clones" +fi diff --git a/Management-Utilities/Workload-Factory-API-Samples/list_eda_project_config b/Management-Utilities/Workload-Factory-API-Samples/list_eda_project_config new file mode 100755 index 0000000..8bdd177 --- /dev/null +++ b/Management-Utilities/Workload-Factory-API-Samples/list_eda_project_config @@ -0,0 +1,116 @@ +#!/bin/bash +# +################################################################################ +# This script is used to list the EDA Project filter user has access to. +# +# It is dependent on the 'wf_utils' file that is included in this repo. That +# file contains the 'get_token' function that is used to obtain a valid +# access token that is needed to run the Workload Factory APIs. The file needs +# to either be in the command search path or in the current directory. +################################################################################ + +################################################################################ +# This function just prints the usage of this script and exits the program. +################################################################################ +usage() { + cat >&2 < + export BLUEXP_ACCOUNT_ID= +EOF + exit 1 +} + +################################################################################ +# Main logic starts here. +################################################################################ +tmpout=$(mktemp /tmp/list_volumes-out.XXXXXX) +tmpout2=$(mktemp /tmp/list_volumes-out2.XXXXXX) +tmperr=$(mktemp /tmp/list_volumes-err.XXXXXX) +trap 'rm -f $tmpout $tmpout2 $tmperr' exit +# +# Source the wf_utils file. +wf_utils=$(command -v wf_utils) +if [ -z "$wf_utils" ]; then + if [ ! -x "./wf_utils" ]; then + cat >&2 < /dev/null; then + echo "Error: The required command '$cmd' not found. Please install it." >&2 + exit 1 + fi +done + +token=$(get_token) +if [ -z "$token" ]; then + echo "Error: Failed to obtain an access token. Exiting." >&2 + exit 1 +fi + +if [ $raw == "true" ]; then + jq_query='.' +else + jq_query='.createdBy as $cb | (.items[] | select(.target == "tag") | "\(.label) \(.key) " + $cb)' +fi + +URL="https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/builders/v1/configure" +run_curl GET "$token" "$URL" $tmpout $tmperr +if jq -r "$jq_query" $tmpout > $tmpout2 2> $tmperr; then + : +else + echo "Error: Failed to parse the output from the API." >&2 + cat $tmperr >&2 + exit 1 +fi + +if [ $raw == "true" ]; then + cat $tmpout2 +else + sort -f $tmpout2 | column -t -N "Label,Key,Created By" +fi diff --git a/Management-Utilities/Workload-Factory-API-Samples/list_filesystems b/Management-Utilities/Workload-Factory-API-Samples/list_filesystems index 3dbb0b3..a2e59f1 100755 --- a/Management-Utilities/Workload-Factory-API-Samples/list_filesystems +++ b/Management-Utilities/Workload-Factory-API-Samples/list_filesystems @@ -84,7 +84,7 @@ 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 ID of the credentials to use to list the file systems is required. +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' diff --git a/Management-Utilities/Workload-Factory-API-Samples/list_snapmirrors b/Management-Utilities/Workload-Factory-API-Samples/list_snapmirrors index 97ed580..9e6352e 100755 --- a/Management-Utilities/Workload-Factory-API-Samples/list_snapmirrors +++ b/Management-Utilities/Workload-Factory-API-Samples/list_snapmirrors @@ -85,7 +85,7 @@ 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 ID of the credentials to delete is required. +required_options["CREDENTIALS_ID"]='Error: The Workload Factory credentials ID used to manage 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' diff --git a/Management-Utilities/Workload-Factory-API-Samples/list_snapshots b/Management-Utilities/Workload-Factory-API-Samples/list_snapshots new file mode 100755 index 0000000..6ff19d9 --- /dev/null +++ b/Management-Utilities/Workload-Factory-API-Samples/list_snapshots @@ -0,0 +1,135 @@ +#!/bin/bash +# +################################################################################ +# This script is used to list all the snapshots that a volume has. +# +# It is dependent on the 'wf_utils' file that is included in this repo. That +# file contains the 'get_token' function that is used to obtain a valid +# access token that is needed to run the Workload Factory APIs. The file needs +# to either be in the command search path or in the current directory. +################################################################################ + +################################################################################ +# This function just prints the usage of this script and exits the program. +################################################################################ +usage() { + cat >&2 < + export BLUEXP_ACCOUNT_ID= + export CREDENTIALS_ID= + export AWS_REGION= + export FILESYSTEM_ID= +EOF + exit 1 +} + +################################################################################ +# Main logic starts here. +################################################################################ +tmpout=$(mktemp /tmp/list_volumes-out.XXXXXX) +tmpout2=$(mktemp /tmp/list_volumes-out2.XXXXXX) +tmperr=$(mktemp /tmp/list_volumes-err.XXXXXX) +trap 'rm -f $tmpout $tmpout2 $tmperr' exit +# +# Source the wf_utils file. +wf_utils=$(command -v wf_utils) +if [ -z "$wf_utils" ]; then + if [ ! -x "./wf_utils" ]; then + cat >&2 < /dev/null; then + echo "Error: The required command '$cmd' not found. Please install it." >&2 + exit 1 + fi +done + +token=$(get_token) +if [ -z "$token" ]; then + echo "Error: Failed to obtain an access token. Exiting." >&2 + exit 1 +fi + +jq_query='.snapshots[] | .name + " " + (.creationTime/1000 | strftime("%Y-%m-%d_%H:%M:%S")) + " " + (.size | tostring)' +run_curl GET "$token" "https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/fsx/v2/credentials/${CREDENTIALS_ID}/regions/${AWS_REGION}/file-systems/${FILESYSTEM_ID}/volumes/${VOLUME_ID}?include=snapshots" $tmpout $tmperr +if jq -r "$jq_query" $tmpout > $tmpout2 2> $tmperr; then + : +else + echo "Error: Failed to parse the output from the API." >&2 + cat $tmperr >&2 + exit 1 +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/${FILESYSTEM_ID}/volumes/${VOLUME_ID}?include=snapshots&nextToken=${nextToken}" $tmpout $tmperr + if jq -r "$jq_query" $tmpout >> $tmpout2 2> $tmperr; then + : + else + echo "Error: Failed to parse the output from the API." >&2 + cat $tmperr >&2 + exit 1 + fi + nextToken=$(jq -r '.nextToken' $tmpout) +done +sort -f $tmpout2 | column -t -N "Name,Date,Size" -R 3 diff --git a/Management-Utilities/Workload-Factory-API-Samples/list_svms b/Management-Utilities/Workload-Factory-API-Samples/list_svms index 72a0964..aa562f6 100755 --- a/Management-Utilities/Workload-Factory-API-Samples/list_svms +++ b/Management-Utilities/Workload-Factory-API-Samples/list_svms @@ -83,7 +83,7 @@ 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 ID of the credentials to delete is required. +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' diff --git a/Management-Utilities/Workload-Factory-API-Samples/list_volumes b/Management-Utilities/Workload-Factory-API-Samples/list_volumes index 403ed8d..b76e48f 100755 --- a/Management-Utilities/Workload-Factory-API-Samples/list_volumes +++ b/Management-Utilities/Workload-Factory-API-Samples/list_volumes @@ -85,7 +85,7 @@ 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 ID of the credentials to delete is required. +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' diff --git a/Management-Utilities/Workload-Factory-API-Samples/snapshot_create b/Management-Utilities/Workload-Factory-API-Samples/snapshot_create index 1a0b510..6d858d3 100755 --- a/Management-Utilities/Workload-Factory-API-Samples/snapshot_create +++ b/Management-Utilities/Workload-Factory-API-Samples/snapshot_create @@ -86,7 +86,7 @@ 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 ID of the credentials to delete is required. +required_options["CREDENTIALS_ID"]='Error: The Workload Factory credentials ID used to manage 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' diff --git a/Management-Utilities/Workload-Factory-API-Samples/volume_clone b/Management-Utilities/Workload-Factory-API-Samples/volume_clone index 94524dd..433dbf0 100755 --- a/Management-Utilities/Workload-Factory-API-Samples/volume_clone +++ b/Management-Utilities/Workload-Factory-API-Samples/volume_clone @@ -87,7 +87,7 @@ 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 ID of the credentials to delete is required. +required_options["CREDENTIALS_ID"]='Error: The Workload Factory credentials ID used to manage 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' diff --git a/Management-Utilities/Workload-Factory-API-Samples/volume_delete b/Management-Utilities/Workload-Factory-API-Samples/volume_delete index a423db6..c2f0667 100755 --- a/Management-Utilities/Workload-Factory-API-Samples/volume_delete +++ b/Management-Utilities/Workload-Factory-API-Samples/volume_delete @@ -88,7 +88,7 @@ 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 ID of the credentials to delete is required. +required_options["CREDENTIALS_ID"]='Error: The Workload Factory credentials ID used to manage 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' diff --git a/Management-Utilities/fsx-ontap-aws-cli-scripts/create_fsxn_filesystem b/Management-Utilities/fsx-ontap-aws-cli-scripts/create_fsxn_filesystem index 3aca0ea..e6df553 100755 --- a/Management-Utilities/fsx-ontap-aws-cli-scripts/create_fsxn_filesystem +++ b/Management-Utilities/fsx-ontap-aws-cli-scripts/create_fsxn_filesystem @@ -20,12 +20,13 @@ ################################################################################ usage () { cat 1>&2 < $tmpout 2>&1 @@ -240,7 +251,7 @@ else if [ $waitForCompletion == "true" ]; then i=0 while [ $i -lt $MaxIterations ]; do - aws fsx describe-file-systems --file-system-ids $fsid --output=json --region=$region > $tmpout 2>&1 + aws fsx describe-file-systems $endpoint_url --file-system-ids $fsid --output=json --region=$region > $tmpout 2>&1 if [ $? -eq 0 ]; then status=$(jq -r '.FileSystems[0].Lifecycle' $tmpout 2> /dev/null) if [ "$status" == "AVAILABLE" ]; then diff --git a/Management-Utilities/fsx-ontap-aws-cli-scripts/create_fsxn_svm b/Management-Utilities/fsx-ontap-aws-cli-scripts/create_fsxn_svm index 2ee3d27..94af7e9 100755 --- a/Management-Utilities/fsx-ontap-aws-cli-scripts/create_fsxn_svm +++ b/Management-Utilities/fsx-ontap-aws-cli-scripts/create_fsxn_svm @@ -21,13 +21,14 @@ ################################################################################ usage () { cat 1>&2 < /dev/null | jq -r ".FileSystems[] | if((.Tags[] | select(.Key == \"Name\") .Value) == \"${fileSystemName}\") then .FileSystemId else empty end" 2> /dev/null) + fsid=$(aws fsx describe-file-systems $endpoint_url --region $region --output=json 2> /dev/null | jq -r ".FileSystems[] | if((.Tags[] | select(.Key == \"Name\") .Value) == \"${fileSystemName}\") then .FileSystemId else empty end" 2> /dev/null) fi if [ -z "$fsid" ]; then @@ -91,7 +94,7 @@ if [ -z "$fsid" ]; then fi # # Create the SVM -aws fsx create-storage-virtual-machine --name $svmName --region=$region --file-system-id "$fsid" --output=json > $tmpout 2>&1 +aws fsx create-storage-virtual-machine $endpoint_url --name $svmName --region=$region --file-system-id "$fsid" --output=json > $tmpout 2>&1 if [ $? != "0" ]; then echo "Failed to create storage virtual machine." 1>&2 @@ -107,7 +110,7 @@ else if [ $waitForCompletion == true ]; then i=0 while [ $i -lt $maxIterations ]; do - aws fsx describe-storage-virtual-machines --storage-virtual-machine-ids $svmId --output=json --region=$region > $tmpout 2>&1 + aws fsx describe-storage-virtual-machines $endpoint_url --storage-virtual-machine-ids $svmId --output=json --region=$region > $tmpout 2>&1 if [ $? -eq 0 ]; then status=$(jq -r '.StorageVirtualMachines[0].Lifecycle' $tmpout 2> /dev/null) if [ "$status" == "CREATED" ]; then diff --git a/Management-Utilities/fsx-ontap-aws-cli-scripts/create_fsxn_volume b/Management-Utilities/fsx-ontap-aws-cli-scripts/create_fsxn_volume index 02a555b..0db9a19 100755 --- a/Management-Utilities/fsx-ontap-aws-cli-scripts/create_fsxn_volume +++ b/Management-Utilities/fsx-ontap-aws-cli-scripts/create_fsxn_volume @@ -21,7 +21,7 @@ ################################################################################ usage () { cat 1>&2 <&2 usage fi ;; - v) volumeStyle=$OPTARG - ;; - a) aggregateOption='"AggregateConfiguration":{"Aggregates":["'$OPTARG'"]},' - ;; - w) waitForCompletion=true - ;; - *) usage - ;; + v) volumeStyle=$OPTARG ;; + a) aggregateOption='"AggregateConfiguration":{"Aggregates":["'$OPTARG'"]},' ;; + w) waitForCompletion=true ;; + *) usage ;; esac done # @@ -95,7 +90,7 @@ if [ $volumeStyle != "FLEXVOL" -a $volumeStyle != "FLEXGROUP" ]; then usage fi -aws fsx create-volume --volume-type ONTAP --name $volumeName --ontap-configuration '{ +aws fsx create-volume --volume-type ONTAP $endpoint_url --name $volumeName --ontap-configuration '{ "JunctionPath": "/'$volumeName'", "SecurityStyle": "UNIX", "SizeInMegabytes" : '$size', @@ -119,7 +114,7 @@ else if [ "$waitForCompletion" == "true" ]; then i=0 while [ $i -lt $maxIterations ]; do - aws fsx describe-volumes --volume-ids $volumeId --region=$region --output=json > $tmpout 2>&1 + aws fsx describe-volumes $endpoint_url --volume-ids $volumeId --region=$region --output=json > $tmpout 2>&1 status=$(jq -r .Volumes[0].Lifecycle $tmpout 2> /dev/null) if [ $status == "CREATED" ]; then printf "\nVolume '$volumeName'($volumeId) has been created.\n" diff --git a/Management-Utilities/fsx-ontap-aws-cli-scripts/delete_fsxn_filesystem b/Management-Utilities/fsx-ontap-aws-cli-scripts/delete_fsxn_filesystem index 0409dd7..1a16fb2 100755 --- a/Management-Utilities/fsx-ontap-aws-cli-scripts/delete_fsxn_filesystem +++ b/Management-Utilities/fsx-ontap-aws-cli-scripts/delete_fsxn_filesystem @@ -27,13 +27,14 @@ ################################################################################ usage () { cat 1>&2 < $tmpout | jq -r '.FileSystems[] | if((.Tags[] | select(.Key == "Name") .Value) == "'"${fileSystemName}"'") then .FileSystemId else empty end' 2> /dev/null)) + fsid=($(aws fsx describe-file-systems $endpoint_url --region=$region --output=json 2> $tmpout | jq -r '.FileSystems[] | if((.Tags[] | select(.Key == "Name") .Value) == "'"${fileSystemName}"'") then .FileSystemId else empty end' 2> /dev/null)) if [ ${#fsid[*]} -gt 1 ]; then echo "Error, more than one file system matched the file system name '$fileSystemName'." 1>&2 @@ -140,7 +144,7 @@ if [ -z "$fsid" ]; then else # # Get the file system name based on the fsid. - aws fsx describe-file-systems --file-system-ids $fsid --region=$region --output=json > $tmpout 2>&1 + aws fsx describe-file-systems $endpoint_url --file-system-ids $fsid --region=$region --output=json > $tmpout 2>&1 if [ $? -ne 0 ]; then echo "Error, failed to get the file system name based on the ID ($fsid)." 1>&2 cat $tmpout 1>&2 @@ -155,7 +159,7 @@ else fi # # Create a JSON file with all the SVMs associated with the file system. -aws fsx describe-storage-virtual-machines --region=$region --output=json --filters Name=file-system-id,Values=$fsid > $svmsFile 2>&1 +aws fsx describe-storage-virtual-machines $endpoint_url --region=$region --output=json --filters Name=file-system-id,Values=$fsid > $svmsFile 2>&1 if [ $? -ne 0 ]; then echo "Error, failed to get the list of SVMs." 1>&2 cat $svmsFile 1>&2 @@ -163,7 +167,7 @@ if [ $? -ne 0 ]; then fi # # Create a JSON file with all the FSXN volumes associated with the file system. -aws fsx describe-volumes --region=$region --output=json --filters Name=file-system-id,Values=$fsid > $volumesFile 2>&1 +aws fsx describe-volumes --region=$region $endpoint_url --output=json --filters Name=file-system-id,Values=$fsid > $volumesFile 2>&1 if [ $? -ne 0 ]; then echo "Error, failed to get the list of volumes." 1>&2 cat $volumesFile 1>&2 @@ -188,7 +192,7 @@ svms=($(jq -r '.StorageVirtualMachines[] | select(.FileSystemId == "'$fsId'") | # # First delete all the SVMs. The 'delete_fsxn_svm' script will delete all the volumes associated with the SVM. for svmId in ${svms[*]}; do - delete_fsxn_svm -n -w $enableBackup -i $svmId -r $region + delete_fsxn_svm -n -w $enableBackup -i $svmId -r $region $endpoint_arg if [ $? -ne 0 ]; then echo "Error, failed to delete the SVM with SVM ID '$svmId'." 1>&2 exit 1 @@ -196,7 +200,7 @@ for svmId in ${svms[*]}; do done # # Now that all the volumes and all the SVMs have been deleted, we can delete the filesystem. -aws fsx delete-file-system --file-system-id $fsid --output=json --region=$region > $tmpout 2>&1 +aws fsx delete-file-system $endpoint_url --file-system-id $fsid --output=json --region=$region > $tmpout 2>&1 if [ $? != "0" ]; then printf "\nError, failed to delete file system.\n" 1>&2 cat $tmpout 1>&2 @@ -208,7 +212,7 @@ else if [ $waitForCompletion == "true" ]; then i=0 while [ $i -lt $MaxIterations ]; do - aws fsx describe-file-systems --file-system-ids $fsid --output=json --region=$region > $tmpout 2>&1 + aws fsx describe-file-systems $endpoint_url --file-system-ids $fsid --output=json --region=$region > $tmpout 2>&1 if [ $? -eq 0 ]; then status=$(jq -r '.FileSystems[0].Lifecycle' $tmpout 2> /dev/null) if [ "$status" != "DELETING" -a "$status" != "PENDING" ]; then diff --git a/Management-Utilities/fsx-ontap-aws-cli-scripts/delete_fsxn_svm b/Management-Utilities/fsx-ontap-aws-cli-scripts/delete_fsxn_svm index ed00a64..bc591ce 100755 --- a/Management-Utilities/fsx-ontap-aws-cli-scripts/delete_fsxn_svm +++ b/Management-Utilities/fsx-ontap-aws-cli-scripts/delete_fsxn_svm @@ -23,13 +23,14 @@ ################################################################################ usage () { cat 1>&2 < $volumesFile 2>&1 +aws fsx describe-volumes $endpoint_url --region=$region --output=json --filters Name=storage-virtual-machine-id,Values=$svmID > $volumesFile 2>&1 if [ $? -ne 0 ]; then echo "Error, failed to get the list of volumes for SVM: $svmID." 1>&2 cat $volumesFile 1>&2 @@ -144,7 +148,7 @@ if [ ! -z "${volumes[*]}" ]; then maxNumRunning=1 # Only do one initially, if it completes successfully, then do the rest concurrently. printf "\nDeleting all the volumes associated with ${svmID}.\n" while [ $i -lt $numVolumes ]; do - delete_fsxn_volume -r $region -w -q -i ${volumes[$i]} $enableBackup & + delete_fsxn_volume -r $region -w -q -i ${volumes[$i]} $enableBackup $endpoint_arg & let i+=1 let numRunning+=1 printf "\rTotal number of volumes to delete: ${numVolumes}. Number of deletes currently running: ${numRunning}. Number waiting to be started: $((numVolumes-i)). " @@ -189,7 +193,7 @@ if [ ! -z "${volumes[*]}" ]; then fi # # Now that all the volumes have been deleted, delete the storage virtual machine. -aws fsx delete-storage-virtual-machine --region=$region --storage-virtual-machine-id $svmID > $tmpout 2>&1 +aws fsx delete-storage-virtual-machine $endpoint_url --region=$region --storage-virtual-machine-id $svmID > $tmpout 2>&1 if [ $? != "0" ]; then echo "Failed to delete storage virtual machine." 1>&2 @@ -204,7 +208,7 @@ else if [ $waitForDelete == "true" ]; then i=0 while [ $i -lt $MaxIterations ]; do - aws fsx describe-storage-virtual-machines --storage-virtual-machine-ids $svmID --output=json --region=$region > $tmpout 2>&1 + aws fsx describe-storage-virtual-machines $endpoint_url --storage-virtual-machine-ids $svmID --output=json --region=$region > $tmpout 2>&1 if [ $? -eq 0 ]; then status=$(jq -r '.StorageVirtualMachines[0].Lifecycle' $tmpout 2> /dev/null) if [ "$status" != "DELETING" -a "$status" != "PENDING" ]; then diff --git a/Management-Utilities/fsx-ontap-aws-cli-scripts/delete_fsxn_volume b/Management-Utilities/fsx-ontap-aws-cli-scripts/delete_fsxn_volume index 685dc08..af72be6 100755 --- a/Management-Utilities/fsx-ontap-aws-cli-scripts/delete_fsxn_volume +++ b/Management-Utilities/fsx-ontap-aws-cli-scripts/delete_fsxn_volume @@ -20,12 +20,13 @@ ################################################################################ usage () { cat 1>&2 < $tmpout 2>&1 + aws fsx describe-s3-access-point-attachments $endpoint_url --names $s3ApName --output=json --region=$region > $tmpout 2>&1 if [ $? -eq 0 ]; then status=$(jq -r .S3AccessPointAttachments[0].Lifecycle $tmpout 2> /dev/null) if [ "$status" != "DELETING" -a "$status" != "PENDING" ]; then @@ -84,7 +85,7 @@ waitForVolumeDelete () { # Wait for the volume to be deleted. i=0 while [ $i -lt $MaxIterations ]; do - aws fsx describe-volumes --volume-ids $volumeId --output=json --region=$region > $tmpout 2>&1 + aws fsx describe-volumes $endpoint_url --volume-ids $volumeId --output=json --region=$region > $tmpout 2>&1 if [ $? -eq 0 ]; then status=$(jq -r .Volumes[0].Lifecycle $tmpout 2> /dev/null) if [ "$status" != "DELETING" -a "$status" != "PENDING" ]; then @@ -125,7 +126,7 @@ waitForCompletion=false quiet=false # # Process command line arguments. -while getopts "qhwbi:r:" option; do +while getopts "qhwbi:r:e:" option; do case $option in r) region="$OPTARG" ;; @@ -137,6 +138,8 @@ while getopts "qhwbi:r:" option; do ;; q) quiet=true ;; + e) endpoint_url="--endpoint-url $OPTARG" + ;; *) usage ;; esac @@ -155,11 +158,11 @@ if [ -z "$volumeId" ]; then usage fi -aws fsx describe-s3-access-point-attachments --filter "Name=volume-id,Values=$volumeId" --region=$region --output=json > $tmpout 2>&1 +aws fsx describe-s3-access-point-attachments $endpoint_url --filter "Name=volume-id,Values=$volumeId" --region=$region --output=json > $tmpout 2>&1 if [ "$(jq -r '.S3AccessPointAttachments | length' $tmpout 2>&1)" != "0" ]; then while read s3apName; do [ $quiet != "true" ] && printf "S3 Access Point '$s3apName' is being deleted." 1>&2 - aws fsx detach-and-delete-s3-access-point --name $s3apName --region=$region --output=json > $tmpout 2>&1 + aws fsx detach-and-delete-s3-access-point $endpoint_url --name $s3apName --region=$region --output=json > $tmpout 2>&1 if waitForS3ApDelete $s3apName $volumeId; then : else @@ -169,7 +172,7 @@ if [ "$(jq -r '.S3AccessPointAttachments | length' $tmpout 2>&1)" != "0" ]; then done < <(jq -r '.S3AccessPointAttachments[] | .S3AccessPoint.ResourceARN | split("/")[1]' $tmpout 2>/dev/null) fi -aws fsx delete-volume --volume-id $volumeId --region=$region --output=json --ontap-configuration '{"SkipFinalBackup": '$skipBackup'}' --output=json > $tmpout 2>&1 +aws fsx delete-volume $endpoint_url --volume-id $volumeId --region=$region --output=json --ontap-configuration '{"SkipFinalBackup": '$skipBackup'}' --output=json > $tmpout 2>&1 if [ $? != "0" ]; then echo "Failed to delete volume." 1>&2 diff --git a/Management-Utilities/fsx-ontap-aws-cli-scripts/list_fsxn_filesystems b/Management-Utilities/fsx-ontap-aws-cli-scripts/list_fsxn_filesystems index 422f141..684a149 100755 --- a/Management-Utilities/fsx-ontap-aws-cli-scripts/list_fsxn_filesystems +++ b/Management-Utilities/fsx-ontap-aws-cli-scripts/list_fsxn_filesystems @@ -42,7 +42,7 @@ ################################################################################ usage () { cat 1>&2 < /dev/null | jq -r '.FileSystems[] | if((.Tags[] | select(.Key == "Name") .Value) == "'"${fileSystemName}"'") then .FileSystemId else empty end' 2> /dev/null) + fsid=$(aws fsx describe-file-systems $endpoint_url --region=$region --output=json 2> /dev/null | jq -r '.FileSystems[] | if((.Tags[] | select(.Key == "Name") .Value) == "'"${fileSystemName}"'") then .FileSystemId else empty end' 2> /dev/null) if [ ! -z "$fsid" ]; then - aws fsx describe-file-systems --file-system-ids $fsid --region=$region --query "$queryString" --output=json > $fileSystemsFile 2>&1 + aws fsx describe-file-systems $endpoint_url --file-system-ids $fsid --region=$region --query "$queryString" --output=json > $fileSystemsFile 2>&1 else echo "Error, failed to get the file system ID based on a file system name of '$fileSystemName'." 1>&2 exit 1 fi else if [ -z "$fsid" ]; then - aws fsx describe-file-systems --region=$region --query "$queryString" --output=json > $fileSystemsFile 2>&1 + aws fsx describe-file-systems $endpoint_url --region=$region --query "$queryString" --output=json > $fileSystemsFile 2>&1 else - aws fsx describe-file-systems --file-system-ids $fsid --region=$region --query "$queryString" --output=json > $fileSystemsFile 2>&1 + aws fsx describe-file-systems $endpoint_url --file-system-ids $fsid --region=$region --query "$queryString" --output=json > $fileSystemsFile 2>&1 fi fi @@ -205,14 +208,14 @@ for region in ${regions[*]}; do fi if [ $contents == "true" ]; then - aws fsx describe-storage-virtual-machines --region=$region --output=json > $svmsFile 2>&1 + aws fsx describe-storage-virtual-machines $endpoint_url --region=$region --output=json > $svmsFile 2>&1 if [ $? -ne 0 ]; then echo "Error, failed to get the list of SVMs." 1>&2 cat $svmsFile 1>&2 exit 1 fi - aws fsx describe-volumes --region=$region --output=json > $volumesFile 2>&1 + aws fsx describe-volumes $endpoint_url --region=$region --output=json > $volumesFile 2>&1 if [ $? -ne 0 ]; then echo "Error, failed to get the list of volumes." 1>&2 cat $volumesFile 1>&2 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 0b0ff91..e5097e5 100755 --- a/Management-Utilities/fsx-ontap-aws-cli-scripts/list_fsxn_svms +++ b/Management-Utilities/fsx-ontap-aws-cli-scripts/list_fsxn_svms @@ -28,12 +28,13 @@ ################################################################################ usage () { cat 1>&2 < /dev/null | jq -r '.FileSystems[] | if((.Tags[] | select(.Key == "Name") .Value) == "'"${fileSystemName}"'") then .FileSystemId else empty end' 2> /dev/null) + fileSystemID=$(aws fsx describe-file-systems $endpoint_url --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) if [ -z "$fileSystemID" ]; then if [ "$allRegions" != "true" ]; then echo "Error, failed to find a file system with the name '$fileSystemName'. Maybe in a different region?" 1>&2 @@ -126,7 +129,7 @@ for region in ${regions[*]}; do else filter="--filter Name=file-system-id,Values=$fileSystemID" fi - aws fsx describe-storage-virtual-machines --output=json --region=$region $filter | jq -r '.StorageVirtualMachines[] | "\(.FileSystemId),\(.StorageVirtualMachineId),\(.Endpoints.Nfs.IpAddresses[0]),\(.Name),\(.Lifecycle)"' | sort > $tmpout + aws fsx describe-storage-virtual-machines $endpoint_url --region=$region $filter | jq -r '.StorageVirtualMachines[] | "\(.FileSystemId),\(.StorageVirtualMachineId),\(.Endpoints.Nfs.IpAddresses[0]),\(.Name),\(.Lifecycle)"' | sort > $tmpout if [ $includeIp == "true" ]; then ipFmt="%16s" ipHeader="IP" @@ -136,7 +139,7 @@ for region in ${regions[*]}; do fi if [ $includeFsName == "true" ]; then - aws fsx describe-file-systems --output=json --region=$region | jq -r '.FileSystems[] | .FileSystemId + "," + (.Tags[] | select(.Key == "Name") .Value)' > $tmpout2 + aws fsx describe-file-systems $endpoint_url --region=$region | jq -r '.FileSystems[] | .FileSystemId + "," + (.Tags[] | select(.Key == "Name") .Value)' > $tmpout2 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" %13s %s\n"}; {if(first) {printf "\n"; printf formatStr, "Region", "FileSystem ID", "(Name)", "SVM ID", ipHeader, "State", "SVM Name"; first=0}; if(ipHeader != "IP") {ip=""} else {ip=$3}; name="("fss[$1]")"; printf formatStr, region, $1, name, $2, ip, $5, $4}' < $tmpout else awk -F, -v region=$region -v ipFmt=$ipFmt -v ipHeader=$ipHeader 'BEGIN {first=1; formatStr="%12s %23s %23s "ipFmt" %13s %s\n"}; {if(first) {printf "\n"; printf formatStr, "Region", "FileSystem ID", "SVM ID", ipHeader, "State", "SVM Name"; first=0}; if(ipHeader != "IP") {ip=""} else {ip=$3}; printf formatStr, region, $1, $2, ip, $5, $4}' < $tmpout 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 2ddf394..d3ee81e 100755 --- a/Management-Utilities/fsx-ontap-aws-cli-scripts/list_fsxn_volumes +++ b/Management-Utilities/fsx-ontap-aws-cli-scripts/list_fsxn_volumes @@ -33,7 +33,7 @@ ################################################################################ usage () { cat 1>&2 < /dev/null | jq -r ".FileSystems[] | if((.Tags[] | select(.Key == \"Name\") .Value) == \"${fileSystemName}\") then .FileSystemId else empty end" 2> /dev/null) + fsid=$(aws fsx describe-file-systems $endpoint_url --region $region --output=json 2> /dev/null | jq -r ".FileSystems[] | if((.Tags[] | select(.Key == \"Name\") .Value) == \"${fileSystemName}\") then .FileSystemId else empty end" 2> /dev/null) if [ -z "$fsid" ]; then echo "Error, failed to find the file system with the file system name of '$fileSystemName'." 1>&2 exit 1 @@ -125,7 +128,7 @@ if [ ! -z "$fileSystemName" ]; then fi if [ ! -z "$fsid" -a -z "$fileSystemName" ]; then - fileSystemName=$(aws fsx describe-file-systems --region $region --output=json 2> /dev/null | jq -r ".FileSystems[] | if(.FileSystemId == \"$fsid\") then (.Tags[] | select(.Key == \"Name\") .Value) else empty end" 2> /dev/null) + fileSystemName=$(aws fsx describe-file-systems $endpoint_url --region $region --output=json 2> /dev/null | jq -r ".FileSystems[] | if(.FileSystemId == \"$fsid\") then (.Tags[] | select(.Key == \"Name\") .Value) else empty end" 2> /dev/null) filter='--filters [{"Name":"file-system-id","Values":["'$fsid'"]}]' fi @@ -160,67 +163,71 @@ for region in ${regions[*]}; do if [ ! -z "$(getent hosts fsx.$region.amazonaws.com)" ]; then if [ -z "$svmID" ]; then if [ "$excludeRoot" != "true" ]; then - aws fsx describe-volumes $filter --region=$region --output=json | jq -r '.Volumes[] | "'$jqFields'"' | egrep ",$volumePattern," | sort > $volumeList + aws fsx describe-volumes $filter $endpoint_url --region=$region --output=json | jq -r '.Volumes[] | "'$jqFields'"' | egrep ",$volumePattern," | sort > $volumeList else - aws fsx describe-volumes $filter --region=$region --output=json | jq -r '.Volumes[] | if(.OntapConfiguration.StorageVirtualMachineRoot | not) then "'$jqFields'" else empty end' | egrep ",$volumePattern," | sort > $volumeList + aws fsx describe-volumes $filter $endpoint_url --region=$region --output=json | jq -r '.Volumes[] | if(.OntapConfiguration.StorageVirtualMachineRoot | not) then "'$jqFields'" else empty end' | egrep ",$volumePattern," | sort > $volumeList fi else if [ "$excludeRoot" != "true" ]; then - aws fsx describe-volumes $filter --region=$region --output=json | jq -r '.Volumes[] | if(.OntapConfiguration.StorageVirtualMachineId == "'$svmID'") then "'$jqFields'" else empty end' | egrep ",$volumePattern," | sort > $volumeList + aws fsx describe-volumes $filter $endpoint_url --region=$region --output=json | jq -r '.Volumes[] | if(.OntapConfiguration.StorageVirtualMachineId == "'$svmID'") then "'$jqFields'" else empty end' | egrep ",$volumePattern," | sort > $volumeList else - aws fsx describe-volumes $filter --region=$region --output=json | jq -r '.Volumes[] | if(.OntapConfiguration.StorageVirtualMachineId == "'$svmID'" and (.OntapConfiguration.StorageVirtualMachineRoot | not)) then "'$jqFields'" else empty end' | egrep ",$volumePattern," | sort > $volumeList + aws fsx describe-volumes $filter $endpoint_url --region=$region --output=json | jq -r '.Volumes[] | if(.OntapConfiguration.StorageVirtualMachineId == "'$svmID'" and (.OntapConfiguration.StorageVirtualMachineRoot | not)) then "'$jqFields'" else empty end' | egrep ",$volumePattern," | sort > $volumeList fi fi if [ $includeFsName == "true" ]; then - aws fsx describe-file-systems --region=$region --output=json | jq -r '.FileSystems[] | .FileSystemId + "," + (.Tags[] | select(.Key == "Name") .Value)' > $fsNames - aws fsx describe-storage-virtual-machines --region=$region --output=json | jq -r '.StorageVirtualMachines[] | "\(.StorageVirtualMachineId),\(.Name)"' > $svmNames + aws fsx describe-file-systems $endpoint_url --region=$region --output=json | jq -r '.FileSystems[] | .FileSystemId + "," + (.Tags[] | select(.Key == "Name") .Value)' > $fsNames + aws fsx describe-storage-virtual-machines $endpoint_url --region=$region --output=json | jq -r '.StorageVirtualMachines[] | "\(.StorageVirtualMachineId),\(.Name)"' > $svmNames awk -F, -v region=$region 'BEGIN {first=1; maxFsNameLen=0; maxSvmNameLen=0; while(getline < "'$fsNames'") {fss[$1]=$2; if(length($2) > maxFsNameLen) {maxFsNameLen=length($2)}}; maxFsNameLen +=2; while(getline < "'$svmNames'") {svm[$1]=$2; if(length($2) > maxSvmNameLen) {maxSvmNameLen=length($2)}}; maxSvmNameLen +=2; formatStr="%12s %21s%-"maxFsNameLen"s %21s-%-"maxSvmNameLen"s %24s %10s %s\n"}; {if(first) {printf "\n"; printf formatStr, "Region", "FileSystem ID", "(Name)", "SVM", "(Name)", "Volume ID", "State", "Volume Name"; first=0}; fsName="("fss[$1]")"; svmName="("svm[$6]")"; printf formatStr, region, $1, fsName, $6, svmName, $3, $4, $2}' < $volumeList else if [ $extraInfo == "true" ]; then - volIds=$(awk -F, '{print $3}' < $volumeList) - if [ ! -z "$volIds" ]; then - echo "[" > $cloudwatchQueryFile - first=true - for volId in $volIds; do - volId2=$(echo $volId | sed -e 's/-/_/g') - if [ "$first" = "true" ]; then - first=false - else - echo "," >> $cloudwatchQueryFile - fi - cat <> $cloudwatchQueryFile - { - "Id": "m$volId2", - "MetricStat": { - "Metric": { - "Namespace": "AWS/FSx", - "MetricName": "StorageUsed", - "Dimensions": [ - { - "Name": "VolumeId", - "Value": "$volId" + if [ $(wc -l $volumeList | awk '{print $1}') -gt 500 ]; then + echo "Sorry, too many volumes to get CloudWatch statics for." + else + volIds=$(awk -F, '{print $3}' < $volumeList) + if [ ! -z "$volIds" ]; then + echo "[" > $cloudwatchQueryFile + first=true + for volId in $volIds; do + volId2=$(echo $volId | sed -e 's/-/_/g') + if [ "$first" = "true" ]; then + first=false + else + echo "," >> $cloudwatchQueryFile + fi + cat <> $cloudwatchQueryFile + { + "Id": "m$volId2", + "MetricStat": { + "Metric": { + "Namespace": "AWS/FSx", + "MetricName": "StorageUsed", + "Dimensions": [ + { + "Name": "VolumeId", + "Value": "$volId" + }, + { + "Name": "FileSystemId", + "Value": "$(awk -F, -v volId=$volId '$3 == volId {print $1}' < $volumeList)" + }] }, - { - "Name": "FileSystemId", - "Value": "$(awk -F, -v volId=$volId '$3 == volId {print $1}' < $volumeList)" - }] - }, - "Period": 300, - "Stat": "Average" + "Period": 300, + "Stat": "Average" + } } - } EOF - done - echo "]" >> $cloudwatchQueryFile - aws cloudwatch get-metric-data --region $region --metric-data-queries file://$cloudwatchQueryFile --start-time=$(date -u -d '5 minutes ago' +"%Y-%m-%dT%H:%M:%SZ") --end-time=$(date -u +"%Y-%m-%dT%H:%M:%SZ") --output=json > $cloudwatchOutputFile 2>&1 - for volId in $volIds; do - volId2=$(echo $volId | sed -e 's/-/_/g') - capacity=$(jq -r '.MetricDataResults[] | select(.Id == "m'$volId2'") | .Values[0] // 0' < $cloudwatchOutputFile) - echo "$volId,$capacity" >> $volCapacityFile - done - awk -F, -v region=$region -v volCapacityFile=$volCapacityFile 'BEGIN {first=1; formatStr="%12s %21s %21s %24s %10s %16s %15s %s\n"; while (getline < volCapacityFile) {volidCapacities[$1]=sprintf("%10.0f",$2/1024/1024)}}; {if(first) {printf "\n"; printf formatStr, "Region", "FileSystem ID", "SVM", "Volume ID", "State", "Volume Size (MB)", "Used (MB)", "Volume Name"; first=0}; printf formatStr, region, $1, $6, $3, $4, $5, volidCapacities[$3], $2}' < $volumeList - fi + done + echo "]" >> $cloudwatchQueryFile + aws cloudwatch get-metric-data --region $region --metric-data-queries file://$cloudwatchQueryFile --start-time=$(date -u -d '5 minutes ago' +"%Y-%m-%dT%H:%M:%SZ") --end-time=$(date -u +"%Y-%m-%dT%H:%M:%SZ") --output=json > $cloudwatchOutputFile + for volId in $volIds; do + volId2=$(echo $volId | sed -e 's/-/_/g') + capacity=$(jq -r '.MetricDataResults[] | select(.Id == "m'$volId2'") | .Values[0] // 0' < $cloudwatchOutputFile) + echo "$volId,$capacity" >> $volCapacityFile + done + awk -F, -v region=$region -v volCapacityFile=$volCapacityFile 'BEGIN {first=1; formatStr="%12s %21s %21s %24s %10s %16s %15s %s\n"; while (getline < volCapacityFile) {volidCapacities[$1]=sprintf("%10.0f",$2/1024/1024)}}; {if(first) {printf "\n"; printf formatStr, "Region", "FileSystem ID", "SVM", "Volume ID", "State", "Volume Size (MB)", "Used (MB)", "Volume Name"; first=0}; printf formatStr, region, $1, $6, $3, $4, $5, volidCapacities[$3], $2}' < $volumeList + fi + fi else awk -F, -v region=$region 'BEGIN {first=1; formatStr="%12s %21s %21s %24s %10s %s\n"}; {if(first) {printf "\n"; printf formatStr, "Region", "FileSystem ID", "SVM", "Volume ID", "State", "Volume Name"; first=0}; printf formatStr, region, $1, $6, $3, $4, $2}' < $volumeList fi