Skip to content

Commit e1cc042

Browse files
committed
Added new commands
1 parent 65f6676 commit e1cc042

File tree

2 files changed

+189
-0
lines changed

2 files changed

+189
-0
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/bin/bash
2+
#
3+
# This script is used to delete a BlueXP resource.
4+
#
5+
# It is dependent on the 'wf_utils' file that is included in this repo. That
6+
# file contains the 'get_token' function that is used to obtain a valid
7+
# access token that is needed to run the Workload Factory APIs. The file needs
8+
# to either be in the command search path or in the current directory.
9+
################################################################################
10+
11+
################################################################################
12+
# Display usage information then exits the script.
13+
################################################################################
14+
usage () {
15+
cat >&2 <<EOF
16+
This script is used to delete BlueXP resource.
17+
18+
Usage is: $(basename $0) -t refresh_token -a blueXP_account_ID -r resource_ID
19+
token by going to https://services.cloud.netapp.com/refresh-token
20+
blueXP_account_ID - is the BlueXP account ID. Run 'list_bluexp_accts' to get a
21+
list of accounts you have access to.
22+
resource_id - is the BlueXP resource ID of the resource you want to delete.
23+
24+
Note, instead of passing parameters on the command line, you can set the
25+
following environment variables instead:
26+
27+
export REFRESH_TOKEN=<refresh_token>
28+
export BLUEXP_ACCOUNT_ID=<bluexp_acct_id>
29+
EOF
30+
exit 1
31+
}
32+
33+
tmpout=/tmp/list_bluexp_resources-out.$$
34+
tmperr=/tmp/list_bluexp_resources-err.$$
35+
trap 'rm -f $tmpout $tmperr' exit
36+
#
37+
# Source the wf_utils file.
38+
wf_utils=$(command -v wf_utils)
39+
if [ -z "$wf_utils" ]; then
40+
if [ ! -x "./wf_utils" ]; then
41+
cat <<EOF >&2
42+
Error: The 'wf_utils' script was not found in the current directory or in the command search path.
43+
It is required to run this script. You can download it from:
44+
https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples
45+
EOF
46+
exit 1
47+
else
48+
wf_utils=./wf_utils
49+
fi
50+
fi
51+
. "$wf_utils"
52+
#
53+
# Parse the command line options.
54+
while getopts ht:a:r: opt; do
55+
case $opt in
56+
t) REFRESH_TOKEN="$OPTARG" ;;
57+
a) BLUEXP_ACCOUNT_ID="$OPTARG" ;;
58+
r) RESOURCE_ID="$OPTARG" ;;
59+
*) usage ;;
60+
esac
61+
done
62+
#
63+
# Declare an array of required options and the error message to display if they are not set.
64+
declare -A required_options
65+
required_options["REFRESH_TOKEN"]='Error: A BlueXP refresh tokon is required to run this script. It can be obtain from this web page:
66+
https://services.cloud.netapp.com/refresh-token\n\n'
67+
68+
required_options["BLUEXP_ACCOUNT_ID"]='Error: 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\n\n'
71+
72+
required_options["RESOURCE_ID"]='Error: A BlueXP resources ID is required to run this script.
73+
You can get the list of all the resources under a BlueXP account by running the "list_bluexp_resources" script
74+
found in this GitHub repository: https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples\n\n'
75+
76+
check_required_options
77+
#
78+
# Check that the required commands are available.
79+
for cmd in jq curl; do
80+
if ! command -v $cmd &> /dev/null; then
81+
echo "Error: The required command '$cmd' was not found. Please install it." >&2
82+
exit 1
83+
fi
84+
done
85+
86+
token=$(get_token)
87+
if [ -z "$token" ]; then
88+
echo "Error: Failed to obtain an access token. Exiting." >&2
89+
exit 1
90+
fi
91+
92+
run_curl DELETE "$token" "https://api.bluexp.netapp.com/tenancy/resource/$RESOURCE_ID" $tmpout $tmperr "" "" "X-Tenancy-Account-Id:$BLUEXP_ACCOUNT_ID"
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/bin/bash
2+
#
3+
# This script is used to list all the BlueXP resources that a user has
4+
# access to.
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+
# Display usage information then exits the script.
14+
################################################################################
15+
usage () {
16+
cat >&2 <<EOF
17+
This script is used to list all the BlueXP resources that you have access to.
18+
19+
Usage is: $(basename $0) -t refresh_token -a BlueXP_account_ID
20+
Where: refresh_token - Is a refresh token used to obtain an access token needed
21+
to run the Workload Factory APIs. You can obtain a refresh
22+
token by going to https://services.cloud.netapp.com/refresh-token
23+
blueXP_account_ID - is the BlueXP account ID. Run 'list_bluexp_accts' to get a
24+
list of accounts you have access to.
25+
26+
Note, instead of passing parameters on the command line, you can set the
27+
following environment variables instead:
28+
29+
export REFRESH_TOKEN=<refresh_token>
30+
export BLUEXP_ACCOUNT_ID=<blueXP_account_ID>
31+
EOF
32+
exit 1
33+
}
34+
35+
tmpout=/tmp/list_bluexp_resources-out.$$
36+
tmpout2=/tmp/list_bluexp_resources-out2.$$
37+
tmperr=/tmp/list_bluexp_resources-err.$$
38+
trap 'rm -f $tmpout $tmpout2 $tmperr' exit
39+
#
40+
# Source the wf_utils file.
41+
wf_utils=$(command -v wf_utils)
42+
if [ -z "$wf_utils" ]; then
43+
if [ ! -x "./wf_utils" ]; then
44+
cat <<EOF >&2
45+
Error: The 'wf_utils' script was not found in the current directory or in the command search path.
46+
It is required to run this script. You can download it from:
47+
https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples
48+
EOF
49+
exit 1
50+
else
51+
wf_utils=./wf_utils
52+
fi
53+
fi
54+
. "$wf_utils"
55+
#
56+
# Parse the command line options.
57+
while getopts ht:a: opt; do
58+
case $opt in
59+
t) REFRESH_TOKEN="$OPTARG" ;;
60+
a) BLUEXP_ACCOUNT_ID="$OPTARG" ;;
61+
*) usage ;;
62+
esac
63+
done
64+
#
65+
# Declare an array of required options and the error message to display if they are not set.
66+
declare -A required_options
67+
required_options["REFRESH_TOKEN"]='Error: A BlueXP refresh tokon is required to run this script. It can be obtain from this web page:
68+
https://services.cloud.netapp.com/refresh-token\n\n'
69+
70+
required_options["BLUEXP_ACCOUNT_ID"]='Error: 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\n\n'
73+
74+
check_required_options
75+
#
76+
# Check that the required commands are available.
77+
for cmd in jq curl; do
78+
if ! command -v $cmd &> /dev/null; then
79+
echo "Error: The required command '$cmd' was not found. Please install it." >&2
80+
exit 1
81+
fi
82+
done
83+
84+
token=$(get_token)
85+
if [ -z "$token" ]; then
86+
echo "Error: Failed to obtain an access token. Exiting." >&2
87+
exit 1
88+
fi
89+
90+
run_curl GET "$token" "https://api.bluexp.netapp.com/tenancy/resource?account=$BLUEXP_ACCOUNT_ID" $tmpout $tmperr
91+
if jq -r '.[] | "\(.resourceIdentifier);\(.resourceType);\(.resourceClass);\(.name);\(.metadata);\(.workspaceIds[0])"' $tmpout > $tmpout2 2> $tmperr; then
92+
cat $tmpout2 | column -s\; -t -N ID,Type,Class,name,metadata,workspaceId
93+
else
94+
echo "Error: Failed to parse the response from the API." >&2
95+
cat $tmperr >&2
96+
exit 1
97+
fi

0 commit comments

Comments
 (0)