Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
#
# This script adds an organization to a BlueXP account.
# This script deletes an organization from a BlueXP account.
#
################################################################################
# Display usage information then exists the script.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ required_options["REFRESH_TOKEN"]='Error: A BlueXP refresh tokon is required to
required_options["BLUEXP_ACCOUNT_ID"]='Error: A BlueXP account ID is required to run this script.
You can get the list of accounts you have access to by running the "list_bluexp_accts" script
found in this GitHub repository: https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples\n\n'
required_options["CREDENTIALS_ID"]='Error: The ID of the credentials to delete is required.
required_options["CREDENTIALS_ID"]='Error: The ID of the credentials to use to list the file systems is required.
You can get a list of credentials by running the "list_credentials" script
found in this GitHub repository: https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples\n\n'
required_options["AWS_REGION"]='Error: The AWS region where the file system is located is required.\n\n'
Expand Down Expand Up @@ -129,4 +129,28 @@ while [ "$nextToken" != "null" ]; do
fi
nextToken=$(jq -r '.nextToken' $tmpout)
done

jq_query='.items[] | .clusterUuid + "," + .name + ",N/A,On-Prem," + if(.connected) then "AVAILABLE" else "UNKNOWN" end'
run_curl GET "$token" "https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/onprem/v1/onprems" $tmpout $tmperr
if jq -r "$jq_query" $tmpout >> $tmpout2 2> $tmperr; then
:
else
echo "Error: Failed to parse the output from the API." >&2
cat $tmperr >&2
exit 1
fi
#
# Check to see if there are more.
nextToken=$(jq -r '.nextToken' $tmpout)
while [ "$nextToken" != "null" ]; do
run_curl GET "$token" "https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/onprem/v1/onprems?${nextToken}" $tmpout $tmperr
if jq -r "$jq_query" $tmpout >> $tmpout2 2> $tmperr; then
:
else
echo "Error: Failed to parse the output from the API." >&2
cat $tmperr >&2
exit 1
fi
nextToken=$(jq -r '.nextToken' $tmpout)
done
sort -t, -f -k 2,2 $tmpout2 | column -t -s, -N ID,Name,Region,Deployment_Type,Status
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,11 @@ if [ -z "$token" ]; then
exit 1
fi

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'
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'

filter=$(urlencode "type eq 'lambda'")
run_curl GET "$token" "https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/links/v1/links?filter=${filter}&include=associatedTargets,state,features" $tmpout $tmperr
#filter=$(urlencode "type eq 'lambda'")
#run_curl GET "$token" "https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/links/v1/links?filter=${filter}&include=associatedTargets,state,features" $tmpout $tmperr
run_curl GET "$token" "https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/links/v1/links?include=associatedTargets,state,features" $tmpout $tmperr
if jq -r "$jq_query" $tmpout > $tmpout2 2> $tmperr; then
:
else
Expand All @@ -124,4 +125,4 @@ done
if [ ! -z "$COLUMNS" ]; then
colsOpt="-c $COLUMNS -W Associations"
fi
column -t -s\; -N "Name,Link ID,Status,Region,VPC,Lambda Name,Associations" $colsOpt $tmpout2
column -t -s\; -N "Name,Link ID,Type,Status,Region,VPC,Lambda Name,Associations" $colsOpt $tmpout2
33 changes: 18 additions & 15 deletions Management-Utilities/Workload-Factory-API-Samples/wf_utils
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
get_token() {

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

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

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

if [ -z "$token" ]; then
echo "Error: Unable to obtain a bearer token. Error message:" >&2
Expand Down Expand Up @@ -97,7 +94,13 @@ run_curl () {
errorOutput="$5"
data="$6"
accept="$7"
shift 7

if [ -z "$accept" ]; then
accept="application/json, text/plain, */*"
shift 6
else
shift 7
fi

declare -a extraHeaders
while [ $# -gt 0 ]; do
Expand All @@ -112,27 +115,27 @@ run_curl () {
echo "Error: Missing required parameters for run_curl function." >&2
exit 1
fi
if [ -z "$accept" ]; then
accept="application/json, text/plain, */*"
fi
#
# Since older versions of curl don't support the %{stderr} variable, using the -o option
# to redirect output to the $output file and getting the http_code from standard out.
case "$method" in
GET)
curl -sw "%{stderr}%{http_code},%{errormsg}" "$url" \
curl -sw "%{http_code},%{errormsg}" "$url" \
-H "Accept: $accept" "${extraHeaders[@]}" \
-H "Authorization: Bearer $token" > $output 2> $errorOutput
-H "Authorization: Bearer $token" -o $output > $errorOutput
exitCode=$?
;;
POST|PUT)
curl -X "$method" -sw "%{stderr}%{http_code},%{errormsg}" "$url" \
curl -X "$method" -sw "%{http_code},%{errormsg}" "$url" \
-H "Accept: $accept" "${extraHeaders[@]}" \
-H "Content-Type:application/json" \
-H "Authorization: Bearer $token" --data "$data" > $output 2> $errorOutput
-H "Authorization: Bearer $token" --data "$data" -o $output > $errorOutput
exitCode=$?
;;
DELETE)
curl -X DELETE -sw "%{stderr}%{http_code},%{errormsg}" "$url" \
curl -X DELETE -sw "%{http_code},%{errormsg}" "$url" \
-H "Accept: $accept" "${extraHeaders[@]}" \
-H "Authorization: Bearer $token" > $output 2> $errorOutput
-H "Authorization: Bearer $token" -o $output > $errorOutput
exitCode=$?
;;
*)
Expand Down