Skip to content

Commit b62a96c

Browse files
committed
Added credentials_delete, fsxn_creates_set, link_associate, link_delete, link_disassociate and link_register; Also, changed the way all the scripts check for required parameters to be more uniformed.
1 parent 1f02791 commit b62a96c

26 files changed

+875
-1459
lines changed

Management-Utilities/Workload-Factory-API-Samples/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ If you do create a new script, please consider contributing it back to this repo
3131
| Script | Description |
3232
| --- | --- |
3333
| [credentials_delete](credentials_delete) | This deletes a Workload Factory credential. |
34+
| [fsxn_credentials_set](fsxn_credentials_set) | This sets the credentials for a specified FSx for ONTAP file system. |
3435
| [link_associate](link_associate) | This associates a Workload Factory Link with a specified FSx for ONTAP file system. |
3536
| [link_delete](link_delete) | This deletes a Workload Factory Link. |
3637
| [link_disassociate](link_disassociate) | This disassociates a Workload Factory Link with a specified FSx for ONTAP file system. |

Management-Utilities/Workload-Factory-API-Samples/credentials_delete

Lines changed: 26 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -38,53 +38,9 @@ EOF
3838
# Main logic starts here.
3939
################################################################################
4040

41-
tmpout=$(mktemp /tmp/list_filesystems-out.XXXXXX)
42-
tmpout2=$(mktemp /tmp/list_filesystems-out2.XXXXXX)
43-
tmperr=$(mktemp /tmp/list_filesystems-err.XXXXXX)
44-
trap 'rm -f $tmpout $tmpout2 $tmperr' exit
45-
46-
while getopts "ht:a:c:" opt; do
47-
case $opt in
48-
t) REFRESH_TOKEN="$OPTARG" ;;
49-
a) BLUEXP_ACCOUNT_ID="$OPTARG" ;;
50-
c) DELETE_CREDENTIALS_ID="$OPTARG" ;;
51-
*) usage ;;
52-
esac
53-
done
54-
#
55-
# Check that all the required parameters are set.
56-
missingParmeter="false"
57-
if [ -z "$REFRESH_TOKEN" ]; then
58-
cat >&2 <<EOF
59-
Error: A BlueXP refresh tokon is required to run this script. It can be obtain from this web page:
60-
61-
https://services.cloud.netapp.com/refresh-token
62-
EOF
63-
missingParmeter=true
64-
fi
65-
66-
if [ -z "$BLUEXP_ACCOUNT_ID" ]; then
67-
cat >&2 <<EOF
68-
Erorr: A BlueXP account ID is required to run this script.
69-
You can get the list of accounts you have access to by running the "list_bluexp_accts" script
70-
found in this GitHub repository: https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples
71-
72-
EOF
73-
missingParmeter=true
74-
fi
75-
76-
if [ -z "$DELETE_CREDENTIALS_ID" ]; then
77-
cat >&2 <<EOF
78-
Error: The ID of the credentials to delete is required.
79-
You can get a list of credentials by running the "list_credentials" script
80-
found in this GitHub repository: https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples
81-
EOF
82-
missingParmeter=true
83-
fi
84-
85-
if [ "$missingParmeter" != "false" ]; then
86-
usage
87-
fi
41+
tmpout=$(mktemp /tmp/credentials_delete-out.XXXXXX)
42+
tmperr=$(mktemp /tmp/credentials_delete-err.XXXXXX)
43+
trap 'rm -f $tmpout $tmperr' exit
8844
#
8945
# Source the wf_utils file.
9046
wf_utils=$(command -v wf_utils)
@@ -102,6 +58,29 @@ EOF
10258
fi
10359
. "$wf_utils"
10460
#
61+
# Process comamnd line options.
62+
while getopts "ht:a:c:" opt; do
63+
case $opt in
64+
t) REFRESH_TOKEN="$OPTARG" ;;
65+
a) BLUEXP_ACCOUNT_ID="$OPTARG" ;;
66+
c) DELETE_CREDENTIALS_ID="$OPTARG" ;;
67+
*) usage ;;
68+
esac
69+
done
70+
#
71+
# Declare an array of required options and the error message to display if they are not set.
72+
declare -A required_options
73+
required_options["REFRESH_TOKEN"]='Error: A BlueXP refresh tokon is required to run this script. It can be obtain from this web page:
74+
https://services.cloud.netapp.com/refresh-token\n\n'
75+
required_options["BLUEXP_ACCOUNT_ID"]='Error: A BlueXP account ID is required to run this script.
76+
You can get the list of accounts you have access to by running the "list_bluexp_accts" script
77+
found in this GitHub repository: https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples\n\n'
78+
required_options["DELETE_CREDENTIALS_ID"]='Error: The ID of the credentials to delete is required.
79+
You can get a list of credentials by running the "list_credentials" script
80+
found in this GitHub repository: https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples\n\n'
81+
82+
check_required_options
83+
#
10584
# Check that the required commands are available.
10685
for cmd in jq curl; do
10786
if ! command -v $cmd &> /dev/null; then
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#!/bin/bash
2+
#
3+
################################################################################
4+
# This script is used to set the credentials for an FSxN 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 displays the usage of this script and exits.
14+
################################################################################
15+
usage() {
16+
cat >&2 <<EOF
17+
18+
This script is used to set the credentials for an FSxN file system.
19+
20+
usage: $(basename $0) -t refresh_token -a blueXP_account_ID -c credentials_ID -r aws_region -f filesystem_ID -u user_ID -p password
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+
credentials_ID - Is the Workload Factory credentials ID for the AWS account.
28+
Run 'list_credentials' to get a list of Workload Factory
29+
credentials you have access to.
30+
aws_region - Is the AWS region where the file system is located.
31+
filesystem_ID - Is the ID of the FSxN file system.
32+
user_ID - Is the user ID to set for the FSxN file system.
33+
password - Is the password to set for the FSxN file system.
34+
35+
Instead of passing parameters on the command line, you can set the
36+
following environment variables:
37+
38+
export REFRESH_TOKEN=<refresh_token>
39+
export BLUEXP_ACCOUNT_ID=<blueXP_account_ID>
40+
export CREDENTIALS_ID=<credentials_ID>
41+
export AWS_REGION=<aws_region>
42+
export FILESYSTEM_ID=<filesystem_ID>
43+
export USER_ID=<user_ID>
44+
export PASSWORD=<password>
45+
EOF
46+
exit 1
47+
}
48+
49+
################################################################################
50+
# Main logic starts here.
51+
################################################################################
52+
53+
tmpout=$(mktemp /tmp/fsxn_credentials_set-out.XXXXXX)
54+
tmperr=$(mktemp /tmp/fsxn_credentials_set-err.XXXXXX)
55+
trap 'rm -f $tmpout $tmperr' exit
56+
#
57+
# Source the wf_utils file.
58+
wf_utils=$(command -v wf_utils)
59+
if [ -z "$wf_utils" ]; then
60+
if [ ! -x "./wf_utils" ]; then
61+
cat >&2 <<EOF
62+
Error: The 'wf_utils' script was not found in the current directory or in the command search path.
63+
It is required to run this script. You can download it from:
64+
https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples
65+
EOF
66+
exit 1
67+
else
68+
wf_utils=./wf_utils
69+
fi
70+
fi
71+
. "$wf_utils"
72+
#
73+
# Process command line options.
74+
while getopts "ht:a:c:r:f:u:p:" opt; do
75+
case $opt in
76+
t) REFRESH_TOKEN="$OPTARG" ;;
77+
a) BLUEXP_ACCOUNT_ID="$OPTARG" ;;
78+
c) CREDENTIALS_ID="$OPTARG" ;;
79+
r) AWS_REGION="$OPTARG" ;;
80+
f) FILESYSTEM_ID="$OPTARG" ;;
81+
u) USER_ID="$OPTARG" ;;
82+
p) PASSWORD="$OPTARG" ;;
83+
*) usage ;;
84+
esac
85+
done
86+
#
87+
# Declare an array of required options and the error message to display if they are not set.
88+
declare -A required_options
89+
required_options["REFRESH_TOKEN"]='Error: A BlueXP refresh tokon is required to run this script. It can be obtain from this web page:
90+
https://services.cloud.netapp.com/refresh-token\n\n'
91+
required_options["BLUEXP_ACCOUNT_ID"]='Error: A BlueXP account ID is required to run this script.
92+
You can get the list of accounts you have access to by running the "list_bluexp_accts" script
93+
found in this GitHub repository: https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples\n\n'
94+
required_options["CREDENTIALS_ID"]='Error: The ID of the credentials to delete is required.
95+
You can get a list of credentials by running the "list_credentials" script
96+
found in this GitHub repository: https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples\n\n'
97+
required_options["AWS_REGION"]='Error: The AWS region where the file system is located is required.\n\n'
98+
required_options["FILESYSTEM_ID"]='Error: The ID of the FSxN file system is required.\n\n'
99+
required_options["USER_ID"]='Error: The user ID to set for the FSxN file system is required.\n\n'
100+
required_options["PASSWORD"]='Error: The password to set for the FSxN file system is required.\n\n'
101+
102+
check_required_options
103+
#
104+
# Check that the required commands are available.
105+
for cmd in jq curl; do
106+
if ! command -v $cmd &> /dev/null; then
107+
echo "Error: The required command '$cmd' was not found. Please install it." >&2
108+
exit 1
109+
fi
110+
done
111+
#
112+
# Get the token to use for the API call.
113+
token=$(get_token)
114+
if [ -z "$token" ]; then
115+
echo "Error: Failed to obtain an access token. Exiting." >&2
116+
exit 1
117+
fi
118+
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}'

Management-Utilities/Workload-Factory-API-Samples/link_associate

Lines changed: 33 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -43,86 +43,9 @@ EOF
4343
################################################################################
4444
# Main logic starts here.
4545
################################################################################
46-
tmpout=$(mktemp /tmp/clone_volume-out.XXXXXX)
47-
tmperr=$(mktemp /tmp/clone_volume-err.XXXXXX)
46+
tmpout=$(mktemp /tmp/link_assoicate-out.XXXXXX)
47+
tmperr=$(mktemp /tmp/link_assoicate-err.XXXXXX)
4848
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
12649
#
12750
# Source the wf_utils file.
12851
wf_utils=$(command -v wf_utils)
@@ -140,6 +63,37 @@ EOF
14063
fi
14164
. "$wf_utils"
14265
#
66+
# Process command line options.
67+
while getopts "ht:a:c:r:f:l:" opt; do
68+
case $opt in
69+
t) REFRESH_TOKEN="$OPTARG" ;;
70+
a) BLUEXP_ACCOUNT_ID="$OPTARG" ;;
71+
c) CREDENTIALS_ID="$OPTARG" ;;
72+
r) AWS_REGION="$OPTARG" ;;
73+
f) FILESYSTEM_ID="$OPTARG" ;;
74+
l) LINK_ID="$OPTARG" ;;
75+
*) usage ;;
76+
esac
77+
done
78+
#
79+
# Declare an array of required options and the error message to display if they are not set.
80+
declare -A required_options
81+
required_options["REFRESH_TOKEN"]='Error: A BlueXP refresh tokon is required to run this script. It can be obtain from this web page:
82+
https://services.cloud.netapp.com/refresh-token\n\n'
83+
required_options["BLUEXP_ACCOUNT_ID"]='Error: A BlueXP account ID is required to run this script.
84+
You can get the list of accounts you have access to by running the "list_bluexp_accts" script
85+
found in this GitHub repository: https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples\n\n'
86+
required_options["CREDENTIALS_ID"]='Error: The ID of the credentials to delete is required.
87+
You can get a list of credentials by running the "list_credentials" script
88+
found in this GitHub repository: https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples\n\n'
89+
required_options["AWS_REGION"]='Error: The AWS region where the file system is located is required.\n\n'
90+
required_options["FILESYSTEM_ID"]='Error: The ID of the FSxN file system is required.\n\n'
91+
required_options["LINK_ID"]='Error: The link ID is required to run this script.
92+
You can get the list of links associated with a file systems by running the "list_links" script
93+
found in this GitHub repository: https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples\n\n'
94+
95+
check_required_options
96+
#
14397
# Check that the required commands are available.
14498
for cmd in jq curl; do
14599
if ! command -v $cmd &> /dev/null; then

0 commit comments

Comments
 (0)