Skip to content

Commit daacb22

Browse files
committed
Added Workload Factory Link management API samples.
1 parent d5feb68 commit daacb22

File tree

4 files changed

+574
-0
lines changed

4 files changed

+574
-0
lines changed
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
#!/bin/bash
2+
#
3+
################################################################################
4+
# This script is used to associate a link to an FSx for ONTAP file system.
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+
# This function just prints the usage of this script and exits the program.
14+
################################################################################
15+
usage() {
16+
cat >&2 <<EOF
17+
This script is used to associate a link to an FSx for ONTAP file system.
18+
19+
Usage: $(basename $0) -t refresh_token -a blueXP_account_ID -c credentials_id -r aws_region -f filesystem_ID -l link_id
20+
21+
Where: refresh_token - Is a refresh token used to obtain an access token needed
22+
to run the Workload Factory APIs. You can obtain a refresh
23+
token by going to https://services.cloud.netapp.com/refresh-token
24+
blueXP_account_ID - is the BlueXP account ID. Run 'list_bluexp_accts' to get a
25+
list of accounts you have access to
26+
credentials_ID - is the Workload Factory credentials ID for the AWS account. Run
27+
'list_credentials' to get a list of credentials you have access to
28+
aws_region - is the AWS region where the FSx file systems are located
29+
filesystem_id - is the AWS file system ID of the FSx file system where the volume resides
30+
link_id - Is the id of the link you want to disassociate
31+
32+
Instead of passing parameters on the command line, you can set the
33+
following environment variables:
34+
35+
export REFRESH_TOKEN=<refresh_token>
36+
export BLUEXP_ACCOUNT_ID=<blueXP_account_ID>
37+
export CREDENTIALS_ID=<credentials_ID>
38+
export AWS_REGION=<aws_region>
39+
EOF
40+
exit 1
41+
}
42+
43+
################################################################################
44+
# Main logic starts here.
45+
################################################################################
46+
tmpout=$(mktemp /tmp/clone_volume-out.XXXXXX)
47+
tmperr=$(mktemp /tmp/clone_volume-err.XXXXXX)
48+
trap 'rm -f $tmpout $tmperr' exit
49+
50+
while getopts "ht:a:c:r:f:l:" opt; do
51+
case $opt in
52+
t) REFRESH_TOKEN="$OPTARG" ;;
53+
a) BLUEXP_ACCOUNT_ID="$OPTARG" ;;
54+
c) CREDENTIALS_ID="$OPTARG" ;;
55+
r) AWS_REGION="$OPTARG" ;;
56+
f) FILESYSTEM_ID="$OPTARG" ;;
57+
l) LINK_ID="$OPTARG" ;;
58+
*) usage ;;
59+
esac
60+
done
61+
#
62+
# Check fi the required parameters are set.
63+
missing_args=false
64+
if [ -z "$REFRESH_TOKEN" ]; then
65+
cat >&2 <<EOF
66+
Error: A BlueXP refresh tokon is required to run this script.
67+
Can you be obtain from this web page:
68+
69+
https://services.cloud.netapp.com/refresh-token
70+
71+
EOF
72+
missing_args=true
73+
fi
74+
75+
if [ -z "$BLUEXP_ACCOUNT_ID" ]; then
76+
cat >&2 <<EOF
77+
Error: A BlueXP account is required to run this script.
78+
You can get the list of accounts you have access to by running the "list_bluexp_accts" script
79+
found in this GitHub repository: https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples
80+
81+
EOF
82+
missing_args=true
83+
fi
84+
85+
if [ -z "$CREDENTIALS_ID" ]; then
86+
cat >&2 <<EOF
87+
Error: A Workload Factory credentials ID is required to run this script.
88+
You can get the list of credentials you have access to by running the "list_credentials" script
89+
found in this GitHub repository: https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples
90+
91+
EOF
92+
missing_args=true
93+
fi
94+
95+
if [ -z "$AWS_REGION" ]; then
96+
cat >&2 <<EOF
97+
Error: The AWS region where the file system is located is required to run this script.
98+
99+
EOF
100+
missing_args=true
101+
fi
102+
103+
if [ -z "$FILESYSTEM_ID" ]; then
104+
cat >&2 <<EOF
105+
Error: An FSx file system ID is required to run this script.
106+
You can get the list of file systems you have access to by running the "list_filesystems" script
107+
found in this GitHub repository: https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples
108+
109+
EOF
110+
missing_args=true
111+
fi
112+
113+
if [ -z "$LINK_ID" ]; then
114+
cat >&2 <<EOF
115+
Error: The link ID is required to run this script.
116+
You can get the list of links associated with a file systems by running the "list_links" script
117+
found in this GitHub repository: https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples
118+
119+
EOF
120+
missing_args=true
121+
fi
122+
123+
if [ "$missing_args" != "false" ]; then
124+
usage
125+
fi
126+
#
127+
# Source the wf_utils file.
128+
wf_utils=$(command -v wf_utils)
129+
if [ -z "$wf_utils" ]; then
130+
if [ ! -x "./wf_utils" ]; then
131+
cat >&2 <<EOF
132+
Error: The 'wf_utils' script was not found in the current directory or in the command search path.
133+
It is required to run this script. You can download it from:
134+
https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples
135+
EOF
136+
exit 1
137+
else
138+
wf_utils=./wf_utils
139+
fi
140+
fi
141+
. "$wf_utils"
142+
#
143+
# Check that the required commands are available.
144+
for cmd in jq curl; do
145+
if ! command -v $cmd &> /dev/null; then
146+
echo "Error: The required command '$cmd' was not found. Please install it." >&2
147+
exit 1
148+
fi
149+
done
150+
151+
token=$(get_token)
152+
if [ -z "$token" ]; then
153+
echo "Error: Failed to obtain an access token. Exiting." >&2
154+
exit 1
155+
fi
156+
157+
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'"}'
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#!/bin/bash
2+
#
3+
################################################################################
4+
# This script is used to delete a Workload Factory link.
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+
# This function displays the usage of this script and exits.
14+
################################################################################
15+
usage() {
16+
cat >&2 <<EOF
17+
This script is used to delete a Workload Factory link.
18+
you have access to.
19+
20+
usage: $(basename $0) -t refresh_token -a blueXP_account_ID -l link_ID
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_ID - is the BlueXP account ID. Run 'list_bluexp_accts' to get a
26+
list of accounts you have access to.
27+
link_ID - is the ID of the link to delete. You can get a list of links by
28+
running the 'list_links' script.
29+
30+
Instead of passing parameters on the command line, you can set the
31+
following environment variables:
32+
33+
export REFRESH_TOKEN=<refresh_token>
34+
export BLUEXP_ACCOUNT_ID=<blueXP_account_ID>
35+
EOF
36+
exit 1
37+
}
38+
39+
################################################################################
40+
# Main logic starts here.
41+
################################################################################
42+
43+
tmpout=$(mktemp /tmp/list_filesystems-out.XXXXXX)
44+
tmpout2=$(mktemp /tmp/list_filesystems-out2.XXXXXX)
45+
tmperr=$(mktemp /tmp/list_filesystems-err.XXXXXX)
46+
trap 'rm -f $tmpout $tmpout2 $tmperr' exit
47+
48+
while getopts "ht:a:l:" opt; do
49+
case $opt in
50+
t) REFRESH_TOKEN="$OPTARG" ;;
51+
a) BLUEXP_ACCOUNT_ID="$OPTARG" ;;
52+
l) LINK_ID="$OPTARG" ;;
53+
*) usage ;;
54+
esac
55+
done
56+
#
57+
# Check that all the required parameters are set.
58+
missingParmeter="false"
59+
if [ -z "$REFRESH_TOKEN" ]; then
60+
cat >&2 <<EOF
61+
Error: A BlueXP refresh tokon is required to run this script. It can be obtain from this web page:
62+
63+
https://services.cloud.netapp.com/refresh-token
64+
EOF
65+
missingParmeter=true
66+
fi
67+
68+
if [ -z "$BLUEXP_ACCOUNT_ID" ]; then
69+
cat >&2 <<EOF
70+
Erorr: A BlueXP account ID is required to run this script.
71+
You can get the list of accounts you have access to by running the "list_bluexp_accts" script
72+
found in this GitHub repository: https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples
73+
74+
EOF
75+
missingParmeter=true
76+
fi
77+
78+
if [ -z "$LINK_ID" ]; then
79+
cat >&2 <<EOF
80+
Error: A link ID is required to run this script.
81+
You can get the list of links you have access to by running the "list_links" script
82+
found in this GitHub repository: https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples
83+
EOF
84+
missingParmeter=true
85+
fi
86+
87+
if [ "$missingParmeter" != "false" ]; then
88+
usage
89+
fi
90+
#
91+
# Source the wf_utils file.
92+
wf_utils=$(command -v wf_utils)
93+
if [ -z "$wf_utils" ]; then
94+
if [ ! -x "./wf_utils" ]; then
95+
cat >&2 <<EOF
96+
Error: The 'wf_utils' script was not found in the current directory or in the command search path.
97+
It is required to run this script. You can download it from:
98+
https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples
99+
EOF
100+
exit 1
101+
else
102+
wf_utils=./wf_utils
103+
fi
104+
fi
105+
. "$wf_utils"
106+
#
107+
# Check that the required commands are available.
108+
for cmd in jq curl; do
109+
if ! command -v $cmd &> /dev/null; then
110+
echo "Error: The required command '$cmd' was not found. Please install it." >&2
111+
exit 1
112+
fi
113+
done
114+
#
115+
# Get the token to use for the API call.
116+
token=$(get_token)
117+
if [ -z "$token" ]; then
118+
echo "Error: Failed to obtain an access token. Exiting." >&2
119+
exit 1
120+
fi
121+
122+
run_curl DELETE "$token" "https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/links/v1/links/${LINK_ID}" $tmpout $tmperr

0 commit comments

Comments
 (0)