-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathlist_bluexp_connectors
More file actions
executable file
·104 lines (93 loc) · 4.13 KB
/
list_bluexp_connectors
File metadata and controls
executable file
·104 lines (93 loc) · 4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/bin/bash
#
# This script is used to list all the BlueXP connectors that a user has
# access to.
#
# It is dependent on the 'wf_utils' file that is included in this repo. That
# file contains the 'get_token' function that is used to obtain a valid
# access token that is needed to run the Workload Factory APIs. The file needs
# to either be in the command search path or in the current directory.
################################################################################
################################################################################
# Display usage information then exits the script.
################################################################################
usage () {
cat >&2 <<EOF
This script is used to list all the BlueXP connectors that you have access to.
Usage is: $(basename $0) -t refresh_token -a blueXP_account_ID [-x]
Where: refresh_token - Is a refresh token used to obtain an access token needed
to run the Workload Factory APIs. You can obtain a refresh
token by going to https://services.cloud.netapp.com/refresh-token
blueXP_account_ID - is the BlueXP account ID. Run 'list_bluexp_accts' to get a
list of accounts you have access to.
-x - Means to show all the inactive connectors as well.
Note, instead of passing parameters on the command line, you can set the
following environment variables instead:
export REFRESH_TOKEN=<refresh_token>
export BLUEXP_ACCOUNT_ID=<blueXP_account_ID>
EOF
exit 1
}
tmpout=/tmp/list_connectors-out.$$
tmperr=/tmp/list_connectors-err.$$
trap 'rm -f $tmpout $tmperr' exit
#
# Source the wf_utils file.
wf_utils=$(command -v wf_utils)
if [ -z "$wf_utils" ]; then
if [ ! -x "./wf_utils" ]; then
cat <<EOF >&2
Error: The 'wf_utils' script was not found in the current directory or in the command search path.
It is required to run this script. You can download it from:
https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples
EOF
exit 1
else
wf_utils=./wf_utils
fi
fi
. "$wf_utils"
#
# Parse the command line options.
showAll=false
while getopts ht:a:x opt; do
case $opt in
t) REFRESH_TOKEN="$OPTARG" ;;
a) BLUEXP_ACCOUNT_ID="$OPTARG" ;;
x) showAll=true ;;
*) usage ;;
esac
done
#
# Declare an array of required options and the error message to display if they are not set.
declare -A required_options
required_options["REFRESH_TOKEN"]='Error: A BlueXP refresh token is required to run this script. It can be obtained from this web page:
https://services.cloud.netapp.com/refresh-token\n\n'
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'
check_required_options
#
# Check that the required commands are available.
for cmd in jq curl; do
if ! command -v $cmd &> /dev/null; then
echo "Error: The required command '$cmd' was not found. Please install it." >&2
exit 1
fi
done
token=$(get_token)
if [ -z "$token" ]; then
echo "Error: Failed to obtain an access token. Exiting." >&2
exit 1
fi
run_curl GET "$token" "https://api.bluexp.netapp.com/agents-mgmt/list-connectors/$BLUEXP_ACCOUNT_ID" $tmpout $tmperr
if [ $showAll == true ]; then
jq -r '.occms[] | .agent.name + " " + .agent.status + " " + .agent.provider + " " + (if(.agent.provider == "onprem") then "N/A" else .agent.region end) + " " + .agent.agentId + " " + .agent.systemId' $tmpout > $tmperr
else
jq -r '.occms[] | if(.agent.status == "active") then .agent.name + " " + .agent.status + " " + .agent.provider + " " + (if(.agent.provider == "onprem") then "N/A" else .agent.region end) + " " + .agent.agentId else empty end + " " + .agent.systemId' $tmpout > $tmperr
if [ ! -s $tmperr ]; then
echo "No active connectors found. Use the -x option to see all the inactive connectors."
exit 0
fi
fi
column -t -N "Name,Status,Provider,Region,ID,System ID" $tmperr