Skip to content

Commit 3bdef61

Browse files
committed
Added several native bluexp samples.
1 parent 0084e85 commit 3bdef61

File tree

7 files changed

+558
-13
lines changed

7 files changed

+558
-13
lines changed

Management-Utilities/Workload-Factory-API-Samples/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,19 @@ If you do create a new script, please consider contributing it back to this repo
3030
## Available Scripts
3131
| Script | Description |
3232
| --- | --- |
33+
| [bluexp_fsxn_discovery](bluexp_fsxn_discovery) | This discovers FSx for ONTAP file systems for the giving bluexp account and workspace. |
34+
| [bluexp_organization_add](bluexp_organization_add) | This adds a new BlueXP organization (a.k.a. account). |
35+
| [bluexp_organization_delete](bluexp_organization_delete) | This deletes a BlueXP organization (a.k.a. account). |
3336
| [credentials_delete](credentials_delete) | This deletes a Workload Factory credential. |
3437
| [fsxn_credentials_set](fsxn_credentials_set) | This sets the credentials for a specified FSx for ONTAP file system. |
3538
| [link_associate](link_associate) | This associates a Workload Factory Link with a specified FSx for ONTAP file system. |
3639
| [link_delete](link_delete) | This deletes a Workload Factory Link. |
3740
| [link_disassociate](link_disassociate) | This disassociates a Workload Factory Link with a specified FSx for ONTAP file system. |
3841
| [link_register](link_register) | This registers a Lambda function as a Workload Factory Link. |
3942
| [list_bluexp_accts](list_bluexp_accts) | This list all the BlueXP accounts (a.k.a. organizations) that you have access to. |
43+
| [list_bluexp_connectors](list_bluexp_connectors) | This list all the BlueXP connectors that you have access to. |
4044
| [list_bluexp_members](list_bluexp_members) | This list all members of a provided BlueXP account. |
45+
| [list_bluexp_workspaces](list_bluexp_workspaces) | This list all the BlueXP workspaces that you have access to. |
4146
| [list_credentials](list_credentials) | This lists all the Workload Factory credentials that you have access to. |
4247
| [list_filesystems](list_filesystems) | This lists all the FSx for ONTAP file systems that you have access to in the specified AWS region. |
4348
| [list_links](list_links) | This lists all the Workload Factory Links that you have access to. |
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
#!/bin/bash
2+
#
3+
# This script adds a filesystem to a BlueXP workspace and sets the filesystem
4+
# password based on the secret stored in AWS Secrets Manager. The secret must
5+
# be of "other" type with two fields (case sensitive): username and password.
6+
# The username field is optional and defaults to fsxadmin if not present.
7+
#
8+
################################################################################
9+
# Display usage information then exists the script.
10+
################################################################################
11+
usage () {
12+
cat 1>&2 <<EOF
13+
Usage: $(basename $0) -t REFRESH_TOKEN -a blueXP_BLUE_ACCOUNT_ID -c CREDENTIALS_ID -r aws_AWS_REGION -f FILESYSTEM_ID -C CONNECTOR_ID -w WORKSPACE_ID -s SECRET_NAME -u USERNAME -p PASSWORD [-P]
14+
15+
Where: REFRESH_TOKEN - Is a refresh token used to obtain an access token needed
16+
to run the Workload Factory APIs. You can obtain a refresh
17+
token by going to https://services.cloud.netapp.com/refresh-token
18+
blueXP_BLUE_ACCOUNT_ID - is the BlueXP account ID. Run 'list_bluexp_accts' to get a
19+
list of accounts you have access to
20+
CREDENTIALS_ID - is the Workload Factory credentials ID for the AWS account. Run
21+
'list_credentials' to get a list of credentials you have access to
22+
aws_AWS_REGION - is the AWS AWS_REGION where the FSx file systems are located
23+
FILESYSTEM_ID - is the AWS file system ID of the FSx file system where the volume resides
24+
CONNECTOR_ID - The BlueXP connector ID. Run 'list_bluexp_connectors' to get a list
25+
of connectors you have access to
26+
WORKSPACE_ID - The BlueXP workspace ID. Run 'list_bluexp_workspaces' to get a list of workspaces
27+
you have access to.
28+
SECRET_NAME - The name of the secret that holds the credentials to assoicate with the FSxN.
29+
USERNAME - The username to set the password for (defaults to fsxadmin if not specified).
30+
PASSWORD - The password to set for the username.
31+
-P - Means to just try to set the password.
32+
33+
Instead of passing parameters on the command line, you can set the following
34+
environment variables:
35+
36+
export REFRESH_TOKEN=<REFRESH_TOKEN>
37+
export BLUEXP_BLUE_ACCOUNT_ID=<blueXP_BLUE_ACCOUNT_ID>
38+
export CREDENTIALS_ID=<CREDENTIALS_ID>
39+
export AWS_AWS_REGION=<aws_AWS_REGION>
40+
export USERNAME=<username>
41+
export PASSWORD=<password>
42+
43+
NOTES:
44+
o You must provide either a SECRET_NAME or a passowrd.
45+
o If you don't provide a username, it will default to fsxadmin unless
46+
you use a secret and the secret has a username field.
47+
o If you provide a username and a secret, the username provided
48+
will be used and the username field in the secret will be ignored.
49+
o The secret must be of "other" type with two fields: username and password.
50+
EOF
51+
exit 1
52+
}
53+
54+
################################################################################
55+
# Main logic starts here.
56+
################################################################################
57+
tmpout=$(mktemp /tmp/add_fsxn_to_bluexp-out.XXXXXX)
58+
tmperr=$(mktemp /tmp/add_fsxn_to_bluexp-err.XXXXXX)
59+
trap 'rm -f $tmpout $tmperr' exit
60+
#
61+
# Source the wf_utils file.
62+
wf_utils=$(command -v wf_utils)
63+
if [ -z "$wf_utils" ]; then
64+
if [ ! -x "./wf_utils" ]; then
65+
cat >&2 <<EOF
66+
Error: The 'wf_utils' script was not found in the current directory or in the command search path.
67+
It is required to run this script. You can download it from:
68+
https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples
69+
EOF
70+
exit 1
71+
else
72+
wf_utils=./wf_utils
73+
fi
74+
fi
75+
. "$wf_utils"
76+
#
77+
# Parse the command line options.
78+
skip_add=false
79+
while getopts "ht:a:c:r:f:C:s:w:u:p:P" opt; do
80+
case ${opt} in
81+
t) REFRESH_TOKEN=$OPTARG ;;
82+
a) BLUEXP_ACCOUNT_ID=$OPTARG ;;
83+
c) CREDENTIALS_ID=$OPTARG ;;
84+
r) AWS_REGION=$OPTARG ;;
85+
f) FILESYSTEM_ID=$OPTARG ;;
86+
C) CONNECTOR_ID=$OPTARG ;;
87+
s) SECRET_NAME=$OPTARG ;;
88+
w) WORKSPACE_ID=$OPTARG ;;
89+
u) USERNAME=$OPTARG ;;
90+
p) PASSWORD=$OPTARG ;;
91+
P) skip_add=true ;;
92+
*) usage ;;
93+
esac
94+
done
95+
#
96+
# Declare an array of required options and the error message to display if they are not set.
97+
declare -A required_options
98+
required_options["REFRESH_TOKEN"]='Error: A BlueXP refresh tokon is required to run this script. It can be obtain from this web page:
99+
https://services.cloud.netapp.com/refresh-token\n\n'
100+
required_options["BLUEXP_ACCOUNT_ID"]='Error: A BlueXP account ID is required to run this script.
101+
You can get the list of accounts you have access to by running the "list_bluexp_accts" script
102+
found in this GitHub repository: https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples\n\n'
103+
required_options["CREDENTIALS_ID"]='Error: The ID of the credentials to delete is required.
104+
You can get a list of credentials by running the "list_credentials" script
105+
found in this GitHub repository: https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples\n\n'
106+
required_options["AWS_REGION"]='Error: The AWS region where the file system is located is required.\n\n'
107+
required_options["FILESYSTEM_ID"]='Error: The ID of the FSxN file system is required.\n\n'
108+
required_options["CONNECTOR_ID"]='Error: A BlueXP connector ID is required to run this script.
109+
You can get the list of connectors you have access to by running the "list_bluexp_connectors" script
110+
found in this GitHub repository: https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples\n\n'
111+
required_options["WORKSPACE_ID"]='Error: A BlueXP workspace ID is required to run this script.
112+
You can get the list of workspaces you have access to by running the "list_bluexp_workspaces" script
113+
found in this GitHub repository: https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples\n\n'
114+
115+
check_required_options
116+
117+
if [ -z "$SECRET_NAME" -a -z "$PASSWORD" ]; then
118+
echo "Error: You must provide either a secret name or password." >&2
119+
usage
120+
fi
121+
#
122+
# If the username and/or password were not provide, get them from the secret.
123+
if [ -z "$USERNAME" -a ! -z "$SECRET_NAME" ]; then
124+
USERNAME=$(aws secretsmanager --region $AWS_REGION get-secret-value --secret-id $SECRET_NAME --query SecretString --output text | sed -ne 's/.*"username":"\([^"]*\).*/\1/p')
125+
fi
126+
if [ -z "$USERNAME" ]; then
127+
USERNAME="fsxadmin"
128+
fi
129+
if [ -z "$PASSWORD" ]; then
130+
PASSWORD=$(aws secretsmanager --region $AWS_REGION get-secret-value --secret-id $SECRET_NAME --query SecretString --output text | sed -ne 's/.*"password":"\([^"]*\).*/\1/p')
131+
fi
132+
if [ -z "$PASSWORD" ]; then
133+
echo "Failed to get the password from the secret." >&2
134+
exit 1
135+
fi
136+
#
137+
# Check that the required commands are available.
138+
for cmd in jq curl; do
139+
if ! command -v $cmd &> /dev/null; then
140+
echo "Error: The required command '$cmd' was not found. Please install it." >&2
141+
exit 1
142+
fi
143+
done
144+
#
145+
# Get an access token.
146+
token=$(get_token)
147+
if [ -z "$token" ]; then
148+
echo "Failed to get a token."
149+
exit 1
150+
fi
151+
#
152+
# Add the filesystem to the BlueXP workspace.
153+
if [ "$skip_add" == false ]; then
154+
echo -n "Adding $FILESYSTEM_ID to BlueXP workspace $WORKSPACE_ID..."
155+
run_curl "POST" "$token" "https://api.workloads.netapp.com/accounts/$BLUEXP_ACCOUNT_ID/fsx/v2/credentials/$CREDENTIALS_ID/regions/$AWS_REGION/bluexp/register-file-systems?workspaceId=$WORKSPACE_ID" $tmpout $tmperr '["'$FILESYSTEM_ID'"]' 'application/json' 'x-bluexp-source: true' "x-agent-id: $CONNECTOR_ID"
156+
echo "Done."
157+
fi
158+
#
159+
# Set the filesystem password.
160+
echo -n "Setting password for $USERNAME on $FILESYSTEM_ID..."
161+
run_curl "POST" "$token" "https://api.workloads.netapp.com/accounts/$BLUEXP_ACCOUNT_ID/fsx/v2/credentials/$CREDENTIALS_ID/regions/$AWS_REGION/file-systems/$FILESYSTEM_ID/ontap-credentials" $tmpout $tmperr '{"user": "'$USERNAME'", "password":"'$PASSWORD'","resetFsxAdminPassword":false}' 'application/json' 'x-bluexp-source: true' "x-agent-id: $CONNECTOR_ID"
162+
echo "Done."
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/bin/bash
2+
#
3+
# This script adds an organization to a BlueXP account.
4+
#
5+
################################################################################
6+
# Display usage information then exists the script.
7+
################################################################################
8+
usage () {
9+
cat 1>&2 <<EOF
10+
Usage: $(basename $0) -t REFRESH_TOKEN -o ORAGANIZATION_NAME
11+
12+
Where: REFRESH_TOKEN - Is a refresh token used to obtain an access token needed
13+
to run the Workload Factory APIs. You can obtain a refresh
14+
token by going to https://services.cloud.netapp.com/refresh-token
15+
ORGANIZATION_NAME - Is the name of the organization to create.
16+
17+
Instead of passing parameters on the command line, you can set the following
18+
environment variables:
19+
20+
export REFRESH_TOKEN=<REFRESH_TOKEN>
21+
EOF
22+
exit 1
23+
}
24+
25+
################################################################################
26+
# Main logic starts here.
27+
################################################################################
28+
tmpout=$(mktemp /tmp/add_organization_to_bluexp-out.XXXXXX)
29+
tmperr=$(mktemp /tmp/add_organization_to_bluexp-err.XXXXXX)
30+
trap 'rm -f $tmpout $tmperr' exit
31+
#
32+
# Source the wf_utils file.
33+
wf_utils=$(command -v wf_utils)
34+
if [ -z "$wf_utils" ]; then
35+
if [ ! -x "./wf_utils" ]; then
36+
cat >&2 <<EOF
37+
Error: The 'wf_utils' script was not found in the current directory or in the command search path.
38+
It is required to run this script. You can download it from:
39+
https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples
40+
EOF
41+
exit 1
42+
else
43+
wf_utils=./wf_utils
44+
fi
45+
fi
46+
. "$wf_utils"
47+
#
48+
# Parse the command line options.
49+
while getopts "ht:o:" opt; do
50+
case ${opt} in
51+
t) REFRESH_TOKEN=$OPTARG ;;
52+
o) ORGANIZATION_NAME=$OPTARG ;;
53+
*) usage ;;
54+
esac
55+
done
56+
#
57+
# Declare an array of required options and the error message to display if they are not set.
58+
declare -A required_options
59+
required_options["REFRESH_TOKEN"]='Error: A BlueXP refresh tokon is required to run this script. It can be obtain from this web page:
60+
https://services.cloud.netapp.com/refresh-token\n\n'
61+
required_options["ORGANIZATION_NAME"]='Error: You must provide the name of the organization you want to create.\n\n'
62+
63+
check_required_options
64+
#
65+
# Check that the required commands are available.
66+
for cmd in jq curl; do
67+
if ! command -v $cmd &> /dev/null; then
68+
echo "Error: The required command '$cmd' was not found. Please install it." >&2
69+
exit 1
70+
fi
71+
done
72+
#
73+
# Get an access token.
74+
token=$(get_token)
75+
if [ -z "$token" ]; then
76+
echo "Failed to get a token."
77+
exit 1
78+
fi
79+
#
80+
# Add the organization to the BlueXP workspace.
81+
echo -n "Creating organization ${ORGANIZATION_NAME}..."
82+
run_curl "POST" "$token" "https://api.bluexp.netapp.com/tenancy/account/$ORGANIZATION_NAME" $tmpout $tmperr '{"name": "'$ORGANIZATION_NAME'", "resourceType": "organization", "type": "application/vnd.netapp.bxp.resource", "version": "1.0"}' 'application/json'
83+
echo "Done."
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/bin/bash
2+
#
3+
# This script adds an organization to a BlueXP account.
4+
#
5+
################################################################################
6+
# Display usage information then exists the script.
7+
################################################################################
8+
usage () {
9+
cat 1>&2 <<EOF
10+
Usage: $(basename $0) -t REFRESH_TOKEN -o ORAGANIZATION_ID
11+
12+
Where: REFRESH_TOKEN - Is a refresh token used to obtain an access token needed
13+
to run the Workload Factory APIs. You can obtain a refresh
14+
token by going to https://services.cloud.netapp.com/refresh-token
15+
ORGANIZATION_ID - Is the Id of the organization to delete.
16+
17+
Instead of passing parameters on the command line, you can set the following
18+
environment variables:
19+
20+
export REFRESH_TOKEN=<REFRESH_TOKEN>
21+
EOF
22+
exit 1
23+
}
24+
25+
################################################################################
26+
# Main logic starts here.
27+
################################################################################
28+
tmpout=$(mktemp /tmp/delete_organization_to_bluexp-out.XXXXXX)
29+
tmperr=$(mktemp /tmp/delete_organization_to_bluexp-err.XXXXXX)
30+
trap 'rm -f $tmpout $tmperr' exit
31+
#
32+
# Source the wf_utils file.
33+
wf_utils=$(command -v wf_utils)
34+
if [ -z "$wf_utils" ]; then
35+
if [ ! -x "./wf_utils" ]; then
36+
cat >&2 <<EOF
37+
Error: The 'wf_utils' script was not found in the current directory or in the command search path.
38+
It is required to run this script. You can download it from:
39+
https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples
40+
EOF
41+
exit 1
42+
else
43+
wf_utils=./wf_utils
44+
fi
45+
fi
46+
. "$wf_utils"
47+
#
48+
# Parse the command line options.
49+
while getopts "ht:o:" opt; do
50+
case ${opt} in
51+
t) REFRESH_TOKEN=$OPTARG ;;
52+
o) ORGANIZATION_ID=$OPTARG ;;
53+
*) usage ;;
54+
esac
55+
done
56+
#
57+
# Declare an array of required options and the error message to display if they are not set.
58+
declare -A required_options
59+
required_options["REFRESH_TOKEN"]='Error: A BlueXP refresh tokon is required to run this script. It can be obtain from this web page:
60+
https://services.cloud.netapp.com/refresh-token\n\n'
61+
required_options["ORGANIZATION_ID"]='Error: You must provide the name of the organization you want to delete.
62+
You can get the list of organization you have access to by running the "list_bluexp_accts" script
63+
found in this GitHub repository: https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples\n\n'
64+
65+
check_required_options
66+
#
67+
# Check that the required commands are available.
68+
for cmd in jq curl; do
69+
if ! command -v $cmd &> /dev/null; then
70+
echo "Error: The required command '$cmd' was not found. Please install it." >&2
71+
exit 1
72+
fi
73+
done
74+
#
75+
# Get an access token.
76+
token=$(get_token)
77+
if [ -z "$token" ]; then
78+
echo "Failed to get a token."
79+
exit 1
80+
fi
81+
#
82+
# Add the organization to the BlueXP workspace.
83+
echo -n "Deleting organization ${ORGANIZATION_ID}..."
84+
run_curl "DELETE" "$token" "https://api.bluexp.netapp.com/v1/management/organizations/$ORGANIZATION_ID" $tmpout $tmperr
85+
echo "Done."

0 commit comments

Comments
 (0)