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
6 changes: 6 additions & 0 deletions Management-Utilities/Workload-Factory-API-Samples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ If you do create a new script, please consider contributing it back to this repo
| [bluexp_fsxn_discovery](bluexp_fsxn_discovery) | This discovers FSx for ONTAP file systems for the giving bluexp account and workspace. |
| [bluexp_organization_add](bluexp_organization_add) | This adds a new BlueXP organization (a.k.a. account). |
| [bluexp_organization_delete](bluexp_organization_delete) | This deletes a BlueXP organization (a.k.a. account). |
| [bluexp_organization_rename](bluexp_organization_rename) | This renames a BlueXP organization (a.k.a. account). |
| [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. |
| [get_latency_details](get_latency_details) | Get the specific details of a latency event. |
| [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. |
Expand All @@ -54,10 +56,12 @@ If you do create a new script, please consider contributing it back to this repo
| [list_bluexp_workspaces](list_bluexp_workspaces) | This list all the BlueXP workspaces that you have access to. |
| [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_latency_events](list_latency_events) | This lists all the latnecy events associated with the BlueXP account. |
| [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. |
| [list_volume_cifs_shares](list_volume_cifs_shares) | This lists cifs shares associated with a volume in 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. |
Expand All @@ -67,6 +71,8 @@ If you do create a new script, please consider contributing it back to this repo
| [snapmirror_update](snapmirror_update) | This updates the SnapMirror relationship for the specified relationship. |
| [snapshot_create](snapshot_create) | This creates a snapshot of the specified volume. |
| [volume_clone](volume_clone) | This clones the specified volume. |
| [volume_cifs_share_create](volume_cifs_share_create) | This will create a CIFS share in a volume. |
| [volume_cifs_share_delete](volume_cifs_share_delete) | This will delete a CIFS share from a 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 access token from the Workload Factory API. |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# The username field is optional and defaults to fsxadmin if not present.
#
################################################################################
# Display usage information then exists the script.
# Display usage information then exits the script.
################################################################################
usage () {
cat 1>&2 <<EOF
Expand Down Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# This script adds an organization to a BlueXP account.
#
################################################################################
# Display usage information then exists the script.
# Display usage information then exits the script.
################################################################################
usage () {
cat 1>&2 <<EOF
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# This script deletes an organization from a BlueXP account.
#
################################################################################
# Display usage information then exists the script.
# Display usage information then exits the script.
################################################################################
usage () {
cat 1>&2 <<EOF
Expand Down Expand Up @@ -79,7 +79,6 @@ if [ -z "$token" ]; then
exit 1
fi
#
# Add the organization to the BlueXP workspace.
echo -n "Deleting organization ${ORGANIZATION_ID}..."
run_curl "DELETE" "$token" "https://api.bluexp.netapp.com/v1/management/organizations/$ORGANIZATION_ID" $tmpout $tmperr
echo "Done."
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/bin/bash
#
# This script renamees a BlueXP organization.
#
################################################################################
# Display usage information then exits the script.
################################################################################
usage () {
cat 1>&2 <<EOF
Usage: $(basename $0) -t REFRESH_TOKEN -o ORGANIZATION_ID -n NEW_NAME

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
ORGANIZATION_ID - Is the Id of the organization to delete.
NEW_NAME - The new name of the organization.

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

export REFRESH_TOKEN=<REFRESH_TOKEN>
EOF
exit 1
}

################################################################################
# Main logic starts here.
################################################################################
tmpout=$(mktemp /tmp/delete_organization_to_bluexp-out.XXXXXX)
tmperr=$(mktemp /tmp/delete_organization_to_bluexp-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"
#
# Parse the command line options.
while getopts "ht:o:n:" opt; do
case ${opt} in
t) REFRESH_TOKEN=$OPTARG ;;
o) ORGANIZATION_ID=$OPTARG ;;
n) NEW_NAME=$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 token is required to run this script. It can be obtained from this web page:
https://services.cloud.netapp.com/refresh-token\n\n'
required_options["ORGANIZATION_ID"]='Error: You must provide the name of the organization you want to delete.
You can get the list of organization 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["NEW_NAME"]='Error: You must provide the new name of the organization.\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 an access token.
token=$(get_token)
if [ -z "$token" ]; then
echo "Failed to get a token."
exit 1
fi
#
# Get the type and version.
run_curl "GET" "$token" "https://api.bluexp.netapp.com/v1/management/organizations/$ORGANIZATION_ID" $tmpout $tmperr
org_type=$(jq -r '.type' $tmpout)
org_version=$(jq -r '.version' $tmpout)
#
# Set the new name of the organization.
run_curl "PATCH" "$token" "https://api.bluexp.netapp.com/v1/management/organizations/$ORGANIZATION_ID" $tmpout $tmperr '{"name":"'$NEW_NAME'","type":"'$org_type'","version":"'$org_version'"}'
124 changes: 124 additions & 0 deletions Management-Utilities/Workload-Factory-API-Samples/cicd_clones_create
Original file line number Diff line number Diff line change
@@ -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 <<EOF
This script is used to create a EDA CI/CD clone.

Usage: $(basename $0) -t refresh_token -a blueXP_account_ID -p project_id -n clone_name [-s snapshot_name]

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.
project_id - is the ID of the EDA CI/CD project to list clones for. Run 'list_cicd_projects' to get a
list of projects you have access to.
clone_name - is the the name you want to assign to the clone.
snapshot_name - is the name of the snapshot to use as the source for the clone.
If not specified, the clone will be created from the volume's current state.
You can get a list of snapshots for the volume by running the 'list_snapshotst' script.

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 PROJECT_ID=<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 <<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 arguments.
SNAPSHOT_NAME=""
while getopts "ht:a:p:v:n:s:" opt; do
case $opt in
t) REFRESH_TOKEN="$OPTARG" ;;
a) BLUEXP_ACCOUNT_ID="$OPTARG" ;;
p) PROJECT_ID="$OPTARG" ;;
n) CLONE_NAME="$OPTARG" ;;
s) SNAPSHOT_NAME='"snapshotName": "'$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["PROJECT_ID"]='Error: The EDA CI/CD project ID is required to run this script.
You can get a list of projects you have access to by running the "list_cicd_projects" 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["CLONE_NAME"]='Error: The name of the clone to create is required to run this script.\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' 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)."
Loading
Loading