Skip to content

Commit 653b66a

Browse files
authored
Merge pull request #259 from NetApp/update_to_handle_on_prem
Update to handle on prem
2 parents 1f0e946 + 9760b5f commit 653b66a

File tree

4 files changed

+49
-21
lines changed

4 files changed

+49
-21
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_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: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,11 @@ 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+
#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
101+
run_curl GET "$token" "https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/links/v1/links?include=associatedTargets,state,features" $tmpout $tmperr
101102
if jq -r "$jq_query" $tmpout > $tmpout2 2> $tmperr; then
102103
:
103104
else
@@ -124,4 +125,4 @@ done
124125
if [ ! -z "$COLUMNS" ]; then
125126
colsOpt="-c $COLUMNS -W Associations"
126127
fi
127-
column -t -s\; -N "Name,Link ID,Status,Region,VPC,Lambda Name,Associations" $colsOpt $tmpout2
128+
column -t -s\; -N "Name,Link ID,Type,Status,Region,VPC,Lambda Name,Associations" $colsOpt $tmpout2

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)