Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Management-Utilities/Workload-Factory-API-Samples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,21 @@ If you do create a new script, please consider contributing it back to this repo
## Available Scripts
| Script | Description |
| --- | --- |
| [credentials_delete](credentials_delete) | This deletes a Workload Factory credential. |
| [fsxn_credentials_set](fsxn_credentials_set) | This sets the credentials for a specified FSx for ONTAP file system. |
| [link_associate](link_associate) | This associates a Workload Factory Link with a specified FSx for ONTAP file system. |
| [link_delete](link_delete) | This deletes a Workload Factory Link. |
| [link_disassociate](link_disassociate) | This disassociates a Workload Factory Link with a specified FSx for ONTAP file system. |
| [link_register](link_register) | This registers a Lambda function as a Workload Factory Link. |
| [list_bluexp_accts](list_bluexp_accts) | This list all the BlueXP accounts (a.k.a. organizations) that you have access to. |
| [list_bluexp_members](list_bluexp_members) | This list all members of a provided BlueXP account. |
| [list_credentials](list_credentials) | This lists all the Workload Factory credentials that you have access to. |
| [list_filesystems](list_filesystems) | This lists all the FSx for ONTAP file systems that you have access to in the specified AWS region. |
| [list_links](list_links) | This lists all the Workload Factory Links that you have access to. |
| [list_snapmirrors](list_snapmirrors) | This lists all the SnapMirror relationships that are associated with the specified file system. |
| [list_svms](list_svms) | This lists all the SVMs that are associated with the specified file system. |
| [list_volumes](list_volumes) | This lists all the volumes that are associated with the specified file system. |
| [show_fsxn_credentials](show_fsxn_credentials) | This shows the credentials that Workload Factory has stored for the specified FSx for ONTAP file system. |
| [snapmirror_break](snapmirror_break) | This breaks the SnapMirror relationship for the specified relationship. |
| [snapmirror_create](snapmirror_create) | This creates a SnapMirror relationship between the specified source volume and destination SVM. |
| [snapmirror_delete](snapmirror_delete) | This deletes the SnapMirror relationship for the specified relationship. |
Expand All @@ -46,7 +54,7 @@ If you do create a new script, please consider contributing it back to this repo
| [snapshot_create](snapshot_create) | This creates a snapshot of the specified volume. |
| [volume_clone](volume_clone) | This clones the specified volume. |
| [volume_delete](volume_delete) | This deletes the specified volume. |
| [wf_utils](wf_utils) | This file contains common functions used by all the scripts. It includes the `get_token()` function that retrieves an authentication token from the Workload Factory API. |
| [wf_utils](wf_utils) | This file contains common functions used by all the scripts. It includes the `get_token()` function that retrieves an access token from the Workload Factory API. |

## Author Information

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/bin/bash
#
################################################################################
# This script is used to delete credentials stored in Workload Factory.
#
# 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 displays the usage of this script and exits.
################################################################################
usage() {
cat >&2 <<EOF
This script is used to delete credentials stored in Workload Factory.

usage: $(basename $0) -t refresh_token -a blueXP_account_ID -c delete_credentials_ID

Where: refresh_token - Is a refresh token used to obtain an access token needed
to run the Workload Factory APIs. You can obtain a refresh
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.
delete_credentials_ID - Is the ID of the credentials you want to delete.

Instead of passing parameters on the command line, you can set the
following environment variables:

export REFRESH_TOKEN=<refresh_token>
export BLUEXP_ACCOUNT_ID=<blueXP_account_ID>
EOF
exit 1
}

################################################################################
# Main logic starts here.
################################################################################

tmpout=$(mktemp /tmp/credentials_delete-out.XXXXXX)
tmperr=$(mktemp /tmp/credentials_delete-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 <<EOF
Error: The 'wf_utils' script was not found in the current directory or in the command search path.
It is required to run this script. You can download it from:
https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples
EOF
exit 1
else
wf_utils=./wf_utils
fi
fi
. "$wf_utils"
#
# Process comamnd line options.
while getopts "ht:a:c:" opt; do
case $opt in
t) REFRESH_TOKEN="$OPTARG" ;;
a) BLUEXP_ACCOUNT_ID="$OPTARG" ;;
c) DELETE_CREDENTIALS_ID="$OPTARG" ;;
*) usage ;;
esac
done
#
# Declare an array of required options and the error message to display if they are not set.
declare -A required_options
required_options["REFRESH_TOKEN"]='Error: A BlueXP refresh tokon is required to run this script. It can be obtain from this web page:
https://services.cloud.netapp.com/refresh-token\n\n'
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["DELETE_CREDENTIALS_ID"]='Error: The ID of the credentials to delete is required.
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'

check_required_options
#
# 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' was not found. Please install it." >&2
exit 1
fi
done
#
# Get the token to use for the API call.
token=$(get_token)
if [ -z "$token" ]; then
echo "Error: Failed to obtain an access token. Exiting." >&2
exit 1
fi
run_curl DELETE "$token" "https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/credentials/v1/${DELETE_CREDENTIALS_ID}" $tmpout $tmperr
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
#!/bin/bash
#
################################################################################
# This script is used to set the credentials for an FSxN file system.
#
# 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 displays the usage of this script and exits.
################################################################################
usage() {
cat >&2 <<EOF

This script is used to set the credentials for an FSxN file system.

usage: $(basename $0) -t refresh_token -a blueXP_account_ID -c credentials_ID -r aws_region -f filesystem_ID -u user_ID -p password -s secret_arn

Where: refresh_token - Is a refresh token used to obtain an access token needed
to run the Workload Factory APIs. You can obtain a refresh
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.
Run 'list_credentials' to get a list of Workload Factory
credentials you have access to.
aws_region - Is the AWS region where the file system is located.
filesystem_ID - Is the ID of the FSxN file system.
user_ID* - Is the user ID to set for the FSxN file system.
password* - Is the password to set for the FSxN file system.
secret_arn* - Is the ARN of the Secrets Manager secret that contains the
credentials for the FSxN file system.

*NOTE: Only user_id and password OR secret_arn can be be provided at the same time.

Instead of passing parameters on the command line, you can set the
following environment variables:

export REFRESH_TOKEN=<refresh_token>
export BLUEXP_ACCOUNT_ID=<blueXP_account_ID>
export CREDENTIALS_ID=<credentials_ID>
export AWS_REGION=<aws_region>
export FILESYSTEM_ID=<filesystem_ID>
export USER_ID=<user_ID>
export PASSWORD=<password>
EOF
exit 1
}

################################################################################
# Main logic starts here.
################################################################################

tmpout=$(mktemp /tmp/fsxn_credentials_set-out.XXXXXX)
tmperr=$(mktemp /tmp/fsxn_credentials_set-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 <<EOF
Error: The 'wf_utils' script was not found in the current directory or in the command search path.
It is required to run this script. You can download it from:
https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples
EOF
exit 1
else
wf_utils=./wf_utils
fi
fi
. "$wf_utils"
#
# Process command line options.
while getopts "ht:a:c:r:f:u:p:s:" opt; do
case $opt in
t) REFRESH_TOKEN="$OPTARG" ;;
a) BLUEXP_ACCOUNT_ID="$OPTARG" ;;
c) CREDENTIALS_ID="$OPTARG" ;;
r) AWS_REGION="$OPTARG" ;;
f) FILESYSTEM_ID="$OPTARG" ;;
u) USER_ID="$OPTARG" ;;
p) PASSWORD="$OPTARG" ;;
s) SECRET_ARN="$OPTARG" ;;
*) usage ;;
esac
done
#
# Declare an array of required options and the error message to display if they are not set.
declare -A required_options
required_options["REFRESH_TOKEN"]='Error: A BlueXP refresh tokon is required to run this script. It can be obtain from this web page:
https://services.cloud.netapp.com/refresh-token\n\n'
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.
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'
required_options["FILESYSTEM_ID"]='Error: The ID of the FSxN file system is required.\n\n'

check_required_options

if [ -n "$USER_ID" -a -n "$PASSWORD" -a -n "$SECRET_ARN" ]; then
echo "Error: You can only provide either user_id and password OR secret_arn at the same time." >&2
usage
elif [ -z "$USER_ID" -a -z "$PASSWORD" -a -z "$SECRET_ARN" ]; then
echo "Error: You must provide either user_id and password OR secret_arn." >&2
usage
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' was not found. Please install it." >&2
exit 1
fi
done
#
# Get the token to use for the API call.
token=$(get_token)
if [ -z "$token" ]; then
echo "Error: Failed to obtain an access token. Exiting." >&2
exit 1
fi

if [ -n "$SECRET_ARN" ]; then
run_curl POST "$token" "https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/fsx/v2/credentials/${CREDENTIALS_ID}/regions/${AWS_REGION}/file-systems/${FILESYSTEM_ID}/ontap-credentials" "$tmpout" "$tmperr" '{"secret":"'${SECRET_ARN}'"}'
else
run_curl POST "$token" "https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/fsx/v2/credentials/${CREDENTIALS_ID}/regions/${AWS_REGION}/file-systems/${FILESYSTEM_ID}/ontap-credentials" "$tmpout" "$tmperr" '{"user":"'${USER_ID}'","password":"'${PASSWORD}'","resetFsxAdminPassword":false}'
fi
111 changes: 111 additions & 0 deletions Management-Utilities/Workload-Factory-API-Samples/link_associate
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#!/bin/bash
#
################################################################################
# This script is used to associate a link to an FSx for ONTAP file system.
#
# 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 <<EOF
This script is used to associate a link to an FSx for ONTAP file system.

Usage: $(basename $0) -t refresh_token -a blueXP_account_ID -c credentials_ID -r aws_region -f filesystem_ID -l link_ID

Where: refresh_token - Is a refresh token used to obtain an access token needed
to run the Workload Factory APIs. You can obtain a refresh
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. Run
'list_credentials' to get a list of credentials you have access to
aws_region - is the AWS region where the FSx file systems are located
filesystem_ID - is the AWS file system ID of the FSx file system where the volume resides
link_ID - Is the id of the link you want to disassociate

Instead of passing parameters on the command line, you can set the
following environment variables:

export REFRESH_TOKEN=<refresh_token>
export BLUEXP_ACCOUNT_ID=<blueXP_account_ID>
export CREDENTIALS_ID=<credentials_ID>
export AWS_REGION=<aws_region>
EOF
exit 1
}

################################################################################
# Main logic starts here.
################################################################################
tmpout=$(mktemp /tmp/link_assoicate-out.XXXXXX)
tmperr=$(mktemp /tmp/link_assoicate-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 <<EOF
Error: The 'wf_utils' script was not found in the current directory or in the command search path.
It is required to run this script. You can download it from:
https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples
EOF
exit 1
else
wf_utils=./wf_utils
fi
fi
. "$wf_utils"
#
# Process command line options.
while getopts "ht:a:c:r:f:l:" opt; do
case $opt in
t) REFRESH_TOKEN="$OPTARG" ;;
a) BLUEXP_ACCOUNT_ID="$OPTARG" ;;
c) CREDENTIALS_ID="$OPTARG" ;;
r) AWS_REGION="$OPTARG" ;;
f) FILESYSTEM_ID="$OPTARG" ;;
l) LINK_ID="$OPTARG" ;;
*) usage ;;
esac
done
#
# Declare an array of required options and the error message to display if they are not set.
declare -A required_options
required_options["REFRESH_TOKEN"]='Error: A BlueXP refresh tokon is required to run this script. It can be obtain from this web page:
https://services.cloud.netapp.com/refresh-token\n\n'
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.
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'
required_options["FILESYSTEM_ID"]='Error: The ID of the FSxN file system is required.\n\n'
required_options["LINK_ID"]='Error: The link ID is required to run this script.
You can get the list of links associated with a file systems by running the "list_links" script
found in this GitHub repository: https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples\n\n'

check_required_options
#
# 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' was 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

run_curl "POST" "$token" "https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/fsx/v2/credentials/${CREDENTIALS_ID}/regions/${AWS_REGION}/file-systems/${FILESYSTEM_ID}/links" $tmpout $tmperr '{"linkId":"'$LINK_ID'"}'
Loading