Skip to content

Commit 9f9d3dc

Browse files
authored
Merge branch 'main' into cloud-formation-script
2 parents c87bdda + 999fc13 commit 9f9d3dc

File tree

6 files changed

+54
-31
lines changed

6 files changed

+54
-31
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
#
3-
# This script adds an organization to a BlueXP account.
3+
# This script deletes an organization from a BlueXP account.
44
#
55
################################################################################
66
# Display usage information then exists the script.

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,15 @@
1414
################################################################################
1515
usage () {
1616
cat >&2 <<EOF
17-
This script is used to list all the BlueXP connectors that you have access to.
17+
This script is used to list all the BlueXP workspaces that you have access to.
1818
19-
Usage is: $(basename $0) -t refresh_token -a blueXP_account_ID [-x]
19+
Usage is: $(basename $0) -t refresh_token -a blueXP_account_ID
2020
2121
Where: refresh_token - Is a refresh token used to obtain an access token needed
2222
to run the Workload Factory APIs. You can obtain a refresh
2323
token by going to https://services.cloud.netapp.com/refresh-token
2424
blueXP_account_ID - is the BlueXP account ID. Run 'list_bluexp_accts' to get a
2525
list of accounts you have access to.
26-
-x - Means to show all the inactive connectors as well.
2726
2827
Note, instead of passing parameters on the command line, you can set the
2928
following environment variables instead:
@@ -55,12 +54,10 @@ fi
5554
. "$wf_utils"
5655
#
5756
# Parse the command line options.
58-
showAll=false
59-
while getopts ht:a:x opt; do
57+
while getopts ht:a: opt; do
6058
case $opt in
6159
t) REFRESH_TOKEN="$OPTARG" ;;
6260
a) BLUEXP_ACCOUNT_ID="$OPTARG" ;;
63-
x) showAll=true ;;
6461
*) usage ;;
6562
esac
6663
done

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ required_options["REFRESH_TOKEN"]='Error: A BlueXP refresh tokon is required to
8484
required_options["BLUEXP_ACCOUNT_ID"]='Error: A BlueXP account ID is required to run this script.
8585
You can get the list of accounts you have access to by running the "list_bluexp_accts" script
8686
found in this GitHub repository: https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples\n\n'
87-
required_options["CREDENTIALS_ID"]='Error: The ID of the credentials to delete is required.
87+
required_options["CREDENTIALS_ID"]='Error: The ID of the credentials to use to list the file systems is required.
8888
You can get a list of credentials by running the "list_credentials" script
8989
found in this GitHub repository: https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples\n\n'
9090
required_options["AWS_REGION"]='Error: The AWS region where the file system is located is required.\n\n'
@@ -129,4 +129,28 @@ while [ "$nextToken" != "null" ]; do
129129
fi
130130
nextToken=$(jq -r '.nextToken' $tmpout)
131131
done
132+
133+
jq_query='.items[] | .clusterUuid + "," + .name + ",N/A,On-Prem," + if(.connected) then "AVAILABLE" else "UNKNOWN" end'
134+
run_curl GET "$token" "https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/onprem/v1/onprems" $tmpout $tmperr
135+
if jq -r "$jq_query" $tmpout >> $tmpout2 2> $tmperr; then
136+
:
137+
else
138+
echo "Error: Failed to parse the output from the API." >&2
139+
cat $tmperr >&2
140+
exit 1
141+
fi
142+
#
143+
# Check to see if there are more.
144+
nextToken=$(jq -r '.nextToken' $tmpout)
145+
while [ "$nextToken" != "null" ]; do
146+
run_curl GET "$token" "https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/onprem/v1/onprems?${nextToken}" $tmpout $tmperr
147+
if jq -r "$jq_query" $tmpout >> $tmpout2 2> $tmperr; then
148+
:
149+
else
150+
echo "Error: Failed to parse the output from the API." >&2
151+
cat $tmperr >&2
152+
exit 1
153+
fi
154+
nextToken=$(jq -r '.nextToken' $tmpout)
155+
done
132156
sort -t, -f -k 2,2 $tmpout2 | column -t -s, -N ID,Name,Region,Deployment_Type,Status

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,9 @@ if [ -z "$token" ]; then
9494
exit 1
9595
fi
9696

97-
jq_query='.items[] | if(.cloudResourceId == null) then "\(.name);\(.id);\(.state.status);\(.region);\(.vpcId);N/A;\(.associatedTargets.items)" else "\(.name);\(.id);\(.state.status);\(.region);\(.vpcId);\(.cloudResourceId | split(":") | .[6]);\(.associatedTargets.items)" end'
97+
jq_query='.items[] | if(.type == "connector") then "\(.name);\(.id);\(.type);\(.state.status);N/A;N/A;N/A;\(.associatedTargets.items)" else "\(.name);\(.id);\(.type);\(.state.status);\(.region);\(.vpcId);\(.cloudResourceId | split(":") | .[6]);\(.associatedTargets.items)" end'
9898

99-
filter=$(urlencode "type eq 'lambda'")
100-
run_curl GET "$token" "https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/links/v1/links?filter=${filter}&include=associatedTargets,state,features" $tmpout $tmperr
99+
run_curl GET "$token" "https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/links/v1/links?include=associatedTargets,state,features" $tmpout $tmperr
101100
if jq -r "$jq_query" $tmpout > $tmpout2 2> $tmperr; then
102101
:
103102
else
@@ -124,4 +123,4 @@ done
124123
if [ ! -z "$COLUMNS" ]; then
125124
colsOpt="-c $COLUMNS -W Associations"
126125
fi
127-
column -t -s\; -N "Name,Link ID,Status,Region,VPC,Lambda Name,Associations" $colsOpt $tmpout2
126+
column -t -s\; -N "Name,Link ID,Type,Status,Region,VPC,Lambda Name,Associations" $colsOpt $tmpout2

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ Where: refresh_token - Is a refresh token used to obtain an access token needed
2626
token by going to https://services.cloud.netapp.com/refresh-token
2727
blueXP_account_ID - is the BlueXP account ID. Run 'list_bluexp_accts' to get a
2828
list of accounts you have access to
29-
aws_region - is the AWS region where you want the list of FSx file system from.
3029
throttle - is the network throughput limit during transfers (optional, defaults to 100 MiB/s. 0 means unlimited)
3130
schedule - is the schedule to use for the SnapMirror relationship (optional, defaults to "hourly")
3231
3332
source_credentials_ID - is the Workload Factory credentials ID for the AWS account. Run
34-
'list_credentials' to get a list of credentials you have access to
35-
source_aws_region - is the AWS region of the source file system
36-
source_fs_ID - is the file system ID of the FSx file system that is the source of the SnapMirror relationship
33+
'list_credentials' to get a list of credentials you have access to.
34+
source_aws_region - is the AWS region of the source file system. Not required if the source is on-prem.
35+
source_fs_ID - is the file system ID of the file system that is the source of the SnapMirror relationship. Run
36+
'list_filesystems' to get a list of file systems you have access to.
3737
source_svm_ID - is the SVM ID on the source file system where you want the volume replicated from
3838
source_svm_name - is the name of the SVM on the source file system where you want the volume replicated from
3939
source_type - is the file system type of the source cluster. Either 'FSx' or 'on-prem' (optional, defaults to "FSx")

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

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
get_token() {
2525

2626
tokenFile="$HOME/.blueXP_token"
27-
tmpfile=$(mktemp -t get_token.XXXXXX)
28-
trap 'rm -f "$tmpfile"' RETURN
2927

3028
if [ -z "$REFRESH_TOKEN" ]; then
3129
echo "Error: The REFRESH_TOKEN environment variable has not been set." >&2
@@ -55,14 +53,13 @@ get_token() {
5553
fi
5654

5755
if [ $createToken == "true" ]; then
58-
curl -s -X POST 'https://netapp-cloud-account.auth0.com/oauth/token' \
56+
token=$(curl -s -X POST 'https://netapp-cloud-account.auth0.com/oauth/token' \
5957
-H 'Content-Type: application/json' \
6058
--data-raw '{
6159
"grant_type": "refresh_token",
6260
"refresh_token": "'$REFRESH_TOKEN'",
6361
"client_id": "Mu0V1ywgYteI6w1MbD15fKfVIUrNXGWC"
64-
}' > $tmpfile 2>&1
65-
token=$(sed -ne 's/."access_token":"\([^"]*\).*/\1/p' < $tmpfile)
62+
}' | sed -ne 's/."access_token":"\([^"]*\).*/\1/p')
6663

6764
if [ -z "$token" ]; then
6865
echo "Error: Unable to obtain a bearer token. Error message:" >&2
@@ -97,7 +94,13 @@ run_curl () {
9794
errorOutput="$5"
9895
data="$6"
9996
accept="$7"
100-
shift 7
97+
98+
if [ -z "$accept" ]; then
99+
accept="application/json, text/plain, */*"
100+
shift 6
101+
else
102+
shift 7
103+
fi
101104

102105
declare -a extraHeaders
103106
while [ $# -gt 0 ]; do
@@ -112,27 +115,27 @@ run_curl () {
112115
echo "Error: Missing required parameters for run_curl function." >&2
113116
exit 1
114117
fi
115-
if [ -z "$accept" ]; then
116-
accept="application/json, text/plain, */*"
117-
fi
118+
#
119+
# Since older versions of curl don't support the %{stderr} variable, using the -o option
120+
# to redirect output to the $output file and getting the http_code from standard out.
118121
case "$method" in
119122
GET)
120-
curl -sw "%{stderr}%{http_code},%{errormsg}" "$url" \
123+
curl -sw "%{http_code},%{errormsg}" "$url" \
121124
-H "Accept: $accept" "${extraHeaders[@]}" \
122-
-H "Authorization: Bearer $token" > $output 2> $errorOutput
125+
-H "Authorization: Bearer $token" -o $output > $errorOutput
123126
exitCode=$?
124127
;;
125128
POST|PUT)
126-
curl -X "$method" -sw "%{stderr}%{http_code},%{errormsg}" "$url" \
129+
curl -X "$method" -sw "%{http_code},%{errormsg}" "$url" \
127130
-H "Accept: $accept" "${extraHeaders[@]}" \
128131
-H "Content-Type:application/json" \
129-
-H "Authorization: Bearer $token" --data "$data" > $output 2> $errorOutput
132+
-H "Authorization: Bearer $token" --data "$data" -o $output > $errorOutput
130133
exitCode=$?
131134
;;
132135
DELETE)
133-
curl -X DELETE -sw "%{stderr}%{http_code},%{errormsg}" "$url" \
136+
curl -X DELETE -sw "%{http_code},%{errormsg}" "$url" \
134137
-H "Accept: $accept" "${extraHeaders[@]}" \
135-
-H "Authorization: Bearer $token" > $output 2> $errorOutput
138+
-H "Authorization: Bearer $token" -o $output > $errorOutput
136139
exitCode=$?
137140
;;
138141
*)

0 commit comments

Comments
 (0)