Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
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 Facotry credentials ID used to list resources is required to run this script.
Comment thread
kcantrel marked this conversation as resolved.
Outdated
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
127 changes: 127 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,127 @@
#!/bin/bash
#
################################################################################
# This script is used to delete a EDA CI/CD clone.
#
Comment thread
kcantrel marked this conversation as resolved.
Outdated
# 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 delete a EDA CI/CD clone.

Usage: $(basename $0) -t refresh_token -a blueXP_account_ID -c credentials_id -p project_id -n clone_name -v volume_id [-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.
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.
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.
volume_id - is the ID of the volume you want to clone. Run 'list_volumes' to get a
list of volumes for a specific file system.
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.

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>
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:c:p:v:n:s:" opt; do
case $opt in
t) REFRESH_TOKEN="$OPTARG" ;;
a) BLUEXP_ACCOUNT_ID="$OPTARG" ;;
c) CREDENTIALS_ID="$OPTARG" ;;
p) PROJECT_ID="$OPTARG" ;;
n) CLONE_NAME="$OPTARG" ;;
v) VOLUME_ID="$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["CREDENTIALS_ID"]='Error: The Workload Facotry credentials ID used to manage resources is required to run this script.
Comment thread
kcantrel marked this conversation as resolved.
Outdated
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'
Comment thread
kcantrel marked this conversation as resolved.
Outdated
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'
required_options["VOLUME_ID"]='Error: The ID of the volume to clone is required to run this script.
You can get a list of volumes for a specific file system by running the "list_volumes" 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' 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='{
"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)."
115 changes: 115 additions & 0 deletions Management-Utilities/Workload-Factory-API-Samples/cicd_clones_delete
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#!/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 <<EOF
This script is used to delete a EDA CI/CD clone.

Usage: $(basename $0) -t refresh_token -a blueXP_account_ID -c credentials_id -p project_id -v clone_volume_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 Workload Factory
credentials 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_volume_id - is the ID of the volume that was created when the clone was provided that you want to delete.
Run 'list_cicd_clones' to get the ID of the clone volumes.

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>
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.
while getopts "ht:a:c:p:v:" opt; do
case $opt in
t) REFRESH_TOKEN="$OPTARG" ;;
a) BLUEXP_ACCOUNT_ID="$OPTARG" ;;
c) CREDENTIALS_ID="$OPTARG" ;;
p) PROJECT_ID="$OPTARG" ;;
v) CLONE_VOLUME_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 Workload Facotry credentials ID used to manage resources is required to run this script.
Comment thread
kcantrel marked this conversation as resolved.
Outdated
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'
Comment thread
kcantrel marked this conversation as resolved.
Outdated
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_VOLUME_ID"]='Error: The ID of the clone volume to delete is required to run this script.
You can get a list of clone volumes by running the "list_cicd_clones" 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' 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."
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#!/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 <<EOF
This script is used to create a EDA CI/CD project.

Usage: $(basename $0) -t refresh_token -a blueXP_account_ID -c credentials_id -n project_name -r region -f filesystem_id -v volume_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 Workload Factory
credentials you have access to.
project_name - is the name you want to give the EDA CI/CD project.
region - is the AWS region where the file system is located.
filesystem_id - is the ID of the FSx for ONTAP file system to where the volume is located.
volume_id - is the ID of the volume to be included in the project.

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>
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.
raw=false
while getopts "ht:a:c:n:f:r:v:" opt; do
case $opt in
t) REFRESH_TOKEN="$OPTARG" ;;
a) BLUEXP_ACCOUNT_ID="$OPTARG" ;;
c) CREDENTIALS_ID="$OPTARG" ;;
n) PROJECT_NAME="$OPTARG" ;;
r) REGION="$OPTARG" ;;
f) FILESYSTEM_ID="$OPTARG" ;;
v) VOLUME_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 token 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 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["PROJECT_NAME"]='Error: The name to assign to the project is required.\n\n'
required_options["REGION"]='Error: The AWS region where the file system is located is required.\n\n'
required_options["FILESYSTEM_ID"]='Error: The ID of the FSx for ONTAP file system where the volume is located is required.\n\n'
required_options["VOLUME_ID"]='Error: The ID of the volume to be included in the project is required.\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

body='{
"name": "'$PROJECT_NAME'",
"credentials_id": "'$CREDENTIALS_ID'",
"volumes": [
{
"id": "'$VOLUME_ID'",
"region": "'$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."
Comment thread
kcantrel marked this conversation as resolved.
Outdated
Loading
Loading