Skip to content

Commit ff25342

Browse files
committed
Added some credentials and link scripts.
1 parent 5fdd5d1 commit ff25342

File tree

4 files changed

+384
-0
lines changed

4 files changed

+384
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ If you do create a new script, please consider contributing it back to this repo
3030
## Available Scripts
3131
| Script | Description |
3232
| --- | --- |
33+
| [credentials_delete](credentials_delete) | This deletes a Workload Factory credential. |
3334
| [link_associate](link_associate) | This associates a Workload Factory Link with a specified FSx for ONTAP file system. |
3435
| [link_delete](link_delete) | This deletes a Workload Factory Link. |
3536
| [link_disassociate](link_disassociate) | This disassociates a Workload Factory Link with a specified FSx for ONTAP file system. |
37+
| [link_register](link_register) | This registers a Lambda function as a Workload Factory Link. |
3638
| [list_bluexp_accts](list_bluexp_accts) | This list all the BlueXP accounts (a.k.a. organizations) that you have access to. |
3739
| [list_bluexp_members](list_bluexp_members) | This list all members of a provided BlueXP account. |
3840
| [list_credentials](list_credentials) | This lists all the Workload Factory credentials that you have access to. |
@@ -41,6 +43,7 @@ If you do create a new script, please consider contributing it back to this repo
4143
| [list_snapmirrors](list_snapmirrors) | This lists all the SnapMirror relationships that are associated with the specified file system. |
4244
| [list_svms](list_svms) | This lists all the SVMs that are associated with the specified file system. |
4345
| [list_volumes](list_volumes) | This lists all the volumes that are associated with the specified file system. |
46+
| [show_fsxn_credentials](show_fsxn_credentials) | This shows the credentials that Workload Factory has stored for the specified FSx for ONTAP file system. |
4447
| [snapmirror_break](snapmirror_break) | This breaks the SnapMirror relationship for the specified relationship. |
4548
| [snapmirror_create](snapmirror_create) | This creates a SnapMirror relationship between the specified source volume and destination SVM. |
4649
| [snapmirror_delete](snapmirror_delete) | This deletes the SnapMirror relationship for the specified relationship. |
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#!/bin/bash
2+
#
3+
################################################################################
4+
# This script is used to delete credentials stored in Workload Factory.
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 credentials stored in Workload Factory.
18+
19+
usage: $(basename $0) -t refresh_token -a blueXP_account_ID -c delete_credentials_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+
delete_credentials_ID - Is the ID of the credentials you want to delete.
27+
28+
Instead of passing parameters on the command line, you can set the
29+
following environment variables:
30+
31+
export REFRESH_TOKEN=<refresh_token>
32+
export BLUEXP_ACCOUNT_ID=<blueXP_account_ID>
33+
EOF
34+
exit 1
35+
}
36+
37+
################################################################################
38+
# Main logic starts here.
39+
################################################################################
40+
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
88+
#
89+
# Source the wf_utils file.
90+
wf_utils=$(command -v wf_utils)
91+
if [ -z "$wf_utils" ]; then
92+
if [ ! -x "./wf_utils" ]; then
93+
cat >&2 <<EOF
94+
Error: The 'wf_utils' script was not found in the current directory or in the command search path.
95+
It is required to run this script. You can download it from:
96+
https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples
97+
EOF
98+
exit 1
99+
else
100+
wf_utils=./wf_utils
101+
fi
102+
fi
103+
. "$wf_utils"
104+
#
105+
# Check that the required commands are available.
106+
for cmd in jq curl; do
107+
if ! command -v $cmd &> /dev/null; then
108+
echo "Error: The required command '$cmd' was not found. Please install it." >&2
109+
exit 1
110+
fi
111+
done
112+
#
113+
# Get the token to use for the API call.
114+
token=$(get_token)
115+
if [ -z "$token" ]; then
116+
echo "Error: Failed to obtain an access token. Exiting." >&2
117+
exit 1
118+
fi
119+
run_curl DELETE "$token" "https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/credentials/v1/${DELETE_CREDENTIALS_ID}" $tmpout $tmperr
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
#!/bin/bash
2+
#
3+
################################################################################
4+
# This script is used to register a Lambda function as an 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 register a Lambda function as an Workload Factory link.
18+
19+
usage: $(basename $0) -t refresh_token -a blueXP_account_ID -n Name -l Lambda_ARN
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+
Name - Is the name you want associated with the Link within the Workload Factory UI.
27+
Lambda_ARN - Is the ARN of the AWS Lambda function.
28+
29+
Instead of passing parameters on the command line, you can set the
30+
following environment variables:
31+
32+
export REFRESH_TOKEN=<refresh_token>
33+
export BLUEXP_ACCOUNT_ID=<blueXP_account_ID>
34+
EOF
35+
exit 1
36+
}
37+
38+
################################################################################
39+
# Main logic starts here.
40+
################################################################################
41+
42+
tmpout=$(mktemp /tmp/list_filesystems-out.XXXXXX)
43+
tmpout2=$(mktemp /tmp/list_filesystems-out2.XXXXXX)
44+
tmperr=$(mktemp /tmp/list_filesystems-err.XXXXXX)
45+
trap 'rm -f $tmpout $tmpout2 $tmperr' exit
46+
47+
while getopts "ht:a:l:n:" opt; do
48+
case $opt in
49+
t) REFRESH_TOKEN="$OPTARG" ;;
50+
a) BLUEXP_ACCOUNT_ID="$OPTARG" ;;
51+
l) LAMBDA_ARN="$OPTARG" ;;
52+
n) NAME="$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 "$NAME" ]; then
79+
cat >&2 <<EOF
80+
Error: You must provide a name for the link to register.
81+
EOF
82+
missingParmeter=true
83+
fi
84+
85+
if [ -z "$LAMBDA_ARN" ]; then
86+
cat >&2 <<EOF
87+
Error: The ARN of the AWS Lambda function is required to run this script.
88+
You can get the ARN from the AWS console.
89+
EOF
90+
missingParmeter=true
91+
fi
92+
93+
if [ "$missingParmeter" != "false" ]; then
94+
usage
95+
fi
96+
#
97+
# Source the wf_utils file.
98+
wf_utils=$(command -v wf_utils)
99+
if [ -z "$wf_utils" ]; then
100+
if [ ! -x "./wf_utils" ]; then
101+
cat >&2 <<EOF
102+
Error: The 'wf_utils' script was not found in the current directory or in the command search path.
103+
It is required to run this script. You can download it from:
104+
https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples
105+
EOF
106+
exit 1
107+
else
108+
wf_utils=./wf_utils
109+
fi
110+
fi
111+
. "$wf_utils"
112+
#
113+
# Check that the required commands are available.
114+
for cmd in jq curl; do
115+
if ! command -v $cmd &> /dev/null; then
116+
echo "Error: The required command '$cmd' was not found. Please install it." >&2
117+
exit 1
118+
fi
119+
done
120+
#
121+
# Get the token to use for the API call.
122+
token=$(get_token)
123+
if [ -z "$token" ]; then
124+
echo "Error: Failed to obtain an access token. Exiting." >&2
125+
exit 1
126+
fi
127+
run_curl POST "$token" "https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/links/v1/links" $tmpout $tmperr '{"type": "lambda", "name": "'${NAME}'", "arn": "'${LAMBDA_ARN}'"}'

0 commit comments

Comments
 (0)