Skip to content

Commit e654638

Browse files
authored
Merge branch 'main' into feature/WLMAI-1970---External-app---update-libraries
2 parents 9af0cec + 518ec03 commit e654638

File tree

63 files changed

+5965
-1027
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+5965
-1027
lines changed

AI/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# AI Overview
22
This subfolder contains samples that can help you create AI solutions.
33

4-
| Tool | Description |
5-
| --- | --- |
4+
| Tool | Description |
5+
|-------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
66
| [GenAI ChatBot Application](/AI/GenAI-ChatBot-application-sample) | This sample shows up to create a web-based chatbot application using the GenAI ChatBot application found in [Workload Factory](https://console.workloads.netapp.com). |
77

88
## Author Information

Management-Utilities/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ This subfolder contains tools that can help you manage your FSx ONTAP file syste
99
| [fsxn-rotate-secret](/Management-Utilities/fsxn-rotate-secret) | This is a Lambda function that can be used with an AWS Secrets Manager secret to rotate the FSx for ONTAP admin password. |
1010
| [iscsi-vol-create-and-mount](/Management-Utilities/iscsi-vol-create-and-mount) | This tool will create an iSCSI volume on an FSx ONTAP file system and mount it to an EC2 instance running Windows. |
1111
| [warm_performance_tier](/Management-Utilities/warm_performance_tier) | This tool to warm up the performance tier of an FSx ONTAP file system volume. |
12+
| [Workload-Factory-API-Samples](/Management-Utilities/Workload-Factory-API-Samples) | This folder contains a collection of bash scripts that demonstrate how to use the Workload Factory APIs. |
1213

1314
## Author Information
1415

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Workload Factory API Samples
2+
3+
The idea behind this folder is to show examples of how to use the [BlueXP Workload Factory APIs](https://console.workloads.netapp.com/api-doc).
4+
Not every API is covered, but the ones required to get you started (get a refresh token, get the BlueXP accountID,
5+
get BlueXP credentials ID) are included. Once you have the informaiton provided from these APIs are ready to start
6+
calling the others. While these examples are implemented as bash shell scripts you should be able to translate them
7+
to the programming language that you prefer, such as Python, Go, or JavaScript.
8+
9+
Note that all these scripts depend on the [wf_utils](wf_utils) file that contains common functions used by all the
10+
scripts. One function in particular, `get_token()`, is used to get an authentication token from the BlueXP Workload
11+
Factory API. So, if you copy just some of the files from this repository, make sure to copy the `wf_utils` file as well.
12+
13+
## Prerequisites
14+
To run these scripts, you need to have the following prerequisites:
15+
- A bash shell.
16+
- The `curl` command-line tool installed.
17+
- The `jq` command-line JSON processor installed. You can install it using your package manager, e.g., `apt-get install jq` on Debian/Ubuntu or `brew install jq` on macOS.
18+
19+
## Notes:
20+
- All scripts allow you to set environment variables to pass options instead of having to use the
21+
command line options. For example, instead of using the `-t` option to pass the
22+
[BlueXP Refresh Token](https://docs.netapp.com/us-en/bluexp-automation/platform/create_user_token.html#1-generate-a-netapp-refresh-token),
23+
you can set the `REFRESH_TOKEN` environment variable.
24+
25+
- All scripts accept the `-h` option to display the help message, which includes the available options and their descriptions.
26+
27+
Hopefully with these samples you'll be able to create your own scripts that use any the Workload Factory APIs.
28+
If you do create a new script, please consider contributing it back to this repository so that others can benefit from it.
29+
30+
## Available Scripts
31+
| Script | Description |
32+
| --- | --- |
33+
| [list_bluexp_accts](list_bluexp_accts) | This list all the BlueXP accounts (a.k.a. organizations) that you have access to. |
34+
| [list_bluexp_members](list_bluexp_members) | This list all members of a provided BlueXP account. |
35+
| [list_credentials](list_credentials) | This lists all the Workload Factory credentials that you have access to. |
36+
| [list_filesystems](list_filesystems) | This lists all the FSx for ONTAP file systems that you have access to in the specified AWS region. |
37+
| [list_snapmirrors](list_snapmirrors) | This lists all the SnapMirror relationships that are associated with the specified file system. |
38+
| [list_svms](list_svms) | This lists all the SVMs that are associated with the specified file system. |
39+
| [list_volumes](list_volumes) | This lists all the volumes that are associated with the specified file system. |
40+
| [snapmirror_break](snapmirror_break) | This breaks the SnapMirror relationship for the specified relationship. |
41+
| [snapmirror_create](snapmirror_create) | This creates a SnapMirror relationship between the specified source volume and destination SVM. |
42+
| [snapmirror_delete](snapmirror_delete) | This deletes the SnapMirror relationship for the specified relationship. |
43+
| [snapmirror_resync](snapmirror_resync) | This resyncs the SnapMirror relationship for the specified relationship. |
44+
| [snapmirror_reverse](snapmirror_reverse) | This reverses the SnapMirror relationship for the specified relationship. |
45+
| [snapmirror_update](snapmirror_update) | This updates the SnapMirror relationship for the specified relationship. |
46+
| [snapshot_create](snapshot_create) | This creates a snapshot of the specified volume. |
47+
| [volume_clone](volume_clone) | This clones the specified volume. |
48+
| [volume_delete](volume_delete) | This deletes the specified volume. |
49+
| [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. |
50+
51+
## Author Information
52+
53+
This repository is maintained by the contributors listed on [GitHub](https://github.com/NetApp/FSx-ONTAP-samples-scripts/graphs/contributors).
54+
55+
## License
56+
57+
Licensed under the Apache License, Version 2.0 (the "License").
58+
59+
You may obtain a copy of the License at [apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0).
60+
61+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an _"AS IS"_ basis, without WARRANTIES or conditions of any kind, either express or implied.
62+
63+
See the License for the specific language governing permissions and limitations under the License.
64+
65+
© 2025 NetApp, Inc. All Rights Reserved.
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/bin/bash
2+
#
3+
# This script is used to list all the BlueXP accounts that a user has
4+
# access to.
5+
#
6+
# It is dependent on the 'wf_utils' file that is included in this repo. That
7+
# file contains the 'get_token' function that is used to obtain a valid
8+
# access token that is needed to run the Workload Factory APIs. The file needs
9+
# to either be in the command search path or in the current directory.
10+
################################################################################
11+
12+
################################################################################
13+
# Display usage information then exits the script.
14+
################################################################################
15+
usage () {
16+
cat >&2 <<EOF
17+
This script is used to list all the BlueXP accounts (a.k.a. organizations)
18+
that you have access to.
19+
20+
Usage is: $(basename $0) -t refresh_token
21+
22+
Where: refresh_token - Is a refresh token used to obtain an access token needed
23+
to run the Workload Factory APIs. You can obtain a refresh
24+
token by going to https://services.cloud.netapp.com/refresh-token
25+
26+
Note, instead of passing parameters on the command line, you can set the
27+
following environment variables instead:
28+
29+
export REFRESH_TOKEN=<refresh_token>
30+
EOF
31+
exit 1
32+
}
33+
34+
tmpout=/tmp/list_accounts-out.$$
35+
tmperr=/tmp/list_accounts-err.$$
36+
trap 'rm -f $tmpout $tmperr' exit
37+
38+
while getopts ht: opt; do
39+
case $opt in
40+
t) REFRESH_TOKEN="$OPTARG" ;;
41+
*) usage ;;
42+
esac
43+
done
44+
#
45+
# Source the wf_utils file.
46+
wf_utils=$(command -v wf_utils)
47+
if [ -z "$wf_utils" ]; then
48+
if [ ! -x "./wf_utils" ]; then
49+
cat <<EOF >&2
50+
Error: The 'wf_utils' script was not found in the current directory or in the command search path.
51+
It is required to run this script. You can download it from:
52+
https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples
53+
EOF
54+
exit 1
55+
else
56+
wf_utils=./wf_utils
57+
fi
58+
fi
59+
. "$wf_utils"
60+
#
61+
# Check that the required commands are available.
62+
for cmd in jq curl; do
63+
if ! command -v $cmd &> /dev/null; then
64+
echo "Error: The required command '$cmd' was not found. Please install it." >&2
65+
exit 1
66+
fi
67+
done
68+
69+
token=$(get_token)
70+
if [ -z "$token" ]; then
71+
echo "Error: Failed to obtain an access token. Exiting." >&2
72+
exit 1
73+
fi
74+
75+
run_curl GET "$token" https://api.bluexp.netapp.com/v1/management/organizations $tmpout $tmperr
76+
if jq -r '.items[] | "\(.name) \(.legacyId) \(.id)"' $tmpout > $tmperr; then
77+
cat $tmperr | column -t -N Name,ID,UUID
78+
else
79+
echo "Error: Failed to parse the response from the API." >&2
80+
exit 1
81+
fi
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
#!/bin/bash
2+
#
3+
# This script is used to list all the BlueXP members that are
4+
# associated with the BlueXP account.
5+
#
6+
# It is dependent on the 'wf_utils' file that is included in this repo. That
7+
# file contains the 'get_token' function that is used to obtain a valid
8+
# access token that is needed to run the Workload Factory APIs. The file needs
9+
# to either be in the command search path or in the current directory.
10+
################################################################################
11+
12+
################################################################################
13+
# Display usage information then exits the script.
14+
################################################################################
15+
usage () {
16+
cat >&2 <<EOF
17+
This script is used to list all the BlueXP members that are
18+
associated with the BlueXP account.
19+
20+
Usage is: $(basename $0) -t refresh_token -u bluexp_account_uuid
21+
22+
Where: refresh_token - Is a refresh token used to obtain an access token needed
23+
to run the Workload Factory APIs. You can obtain a refresh
24+
token by going to https://services.cloud.netapp.com/refresh-token
25+
bluexp_account_uuid - The BlueXP account UUID to list the members for. You can
26+
find all the accounts you have access to by running the
27+
"list_bluexp_accts" script.
28+
-h - Displays this help message.
29+
30+
Note, instead of passing parameters on the command line, you can set the
31+
following environment variables instead:
32+
33+
export REFRESH_TOKEN=<refresh_token>
34+
export BLUEXP_ACCOUNT_UUID=<bluexp_account_uuid>
35+
EOF
36+
exit 1
37+
}
38+
39+
tmpout=/tmp/list_accounts-out.$$
40+
tmperr=/tmp/list_accounts-err.$$
41+
trap 'rm -f $tmpout $tmperr' exit
42+
43+
while getopts ht:u: opt; do
44+
case $opt in
45+
t) REFRESH_TOKEN="$OPTARG" ;;
46+
u) BLUEXP_ACCOUNT_UUID="$OPTARG" ;;
47+
*) usage ;;
48+
esac
49+
done
50+
#
51+
# Source the wf_utils file.
52+
wf_utils=$(command -v wf_utils)
53+
if [ -z "$wf_utils" ]; then
54+
if [ ! -x "./wf_utils" ]; then
55+
cat <<EOF >&2
56+
Error: The 'wf_utils' script was not found in the current directory or in the command search path.
57+
It is required to run this script. You can download it from:
58+
https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples
59+
EOF
60+
exit 1
61+
else
62+
wf_utils=./wf_utils
63+
fi
64+
fi
65+
. "$wf_utils"
66+
#
67+
# Check that all the parameters are set.
68+
if [ -z "$REFRESH_TOKEN" ]; then
69+
cat >&2 <<EOF
70+
Error: A BlueXP refresh tokon is required to run this script.
71+
Can you be obtain from this web page:
72+
73+
https://services.cloud.netapp.com/refresh-token
74+
75+
EOF
76+
usage
77+
fi
78+
79+
if [ -z "$BLUEXP_ACCOUNT_UUID" ]; then
80+
cat >&2 <<EOF
81+
Error: A BlueXP account UUID is required to run this script.
82+
You can see the list of accounts you have access to by running the "list_bluexp_accts" script
83+
found in this GitHub repository: https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples
84+
85+
EOF
86+
usage
87+
fi
88+
#
89+
# Check that the required commands are available.
90+
for cmd in jq curl; do
91+
if ! command -v $cmd &> /dev/null; then
92+
echo "Error: The required command '$cmd' was not found. Please install it." >&2
93+
exit 1
94+
fi
95+
done
96+
97+
token=$(get_token)
98+
if [ -z "$token" ]; then
99+
echo "Error: Failed to obtain an access token. Exiting." >&2
100+
exit 1
101+
fi
102+
103+
run_curl GET "$token" "https://api.bluexp.netapp.com/v1/management/organizations/$BLUEXP_ACCOUNT_UUID/users?limit=1000&filter=userType%20ne%20%27agent%27" $tmpout $tmperr "" "application/vnd.netapp.bxp.users.extended+json"
104+
count=$(jq -r '.count' $tmpout 2> /dev/null)
105+
if [[ "$count" == 0 ]]; then
106+
echo "No members found for the specified BlueXP account UUID: $BLUEXP_ACCOUNT_UUID." >&2
107+
echo "Did you provide the UUID or the iD? This script needs the UUID." >&2
108+
exit 0
109+
fi
110+
111+
if jq -r '.items[] | .name + "," + if(.userType == "user") then .userType + "," + .id else .userType + "," + .auth0Id end + "," + .email' $tmpout > $tmperr; then
112+
cat $tmperr | sort -f | column -s, -t -N Name,Type,ID,Email
113+
else
114+
echo "Error: Failed to parse the response from the API." >&2
115+
exit 1
116+
fi

0 commit comments

Comments
 (0)