Skip to content

Commit 3f6ebc5

Browse files
committed
Added more scripts; updated the volume_cifs_create_share to allow you to specify a path.
1 parent ebe2f57 commit 3f6ebc5

8 files changed

Lines changed: 399 additions & 23 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ If you do create a new script, please consider contributing it back to this repo
4242
| [bluexp_fsxn_discovery](bluexp_fsxn_discovery) | This discovers FSx for ONTAP file systems for the giving bluexp account and workspace. |
4343
| [bluexp_organization_add](bluexp_organization_add) | This adds a new BlueXP organization (a.k.a. account). |
4444
| [bluexp_organization_delete](bluexp_organization_delete) | This deletes a BlueXP organization (a.k.a. account). |
45+
| [bluexp_organization_rename](bluexp_organization_rename) | This renames a BlueXP organization (a.k.a. account). |
4546
| [credentials_delete](credentials_delete) | This deletes a Workload Factory credential. |
4647
| [fsxn_credentials_set](fsxn_credentials_set) | This sets the credentials for a specified FSx for ONTAP file system. |
4748
| [link_associate](link_associate) | This associates a Workload Factory Link with a specified FSx for ONTAP file system. |
@@ -58,6 +59,7 @@ If you do create a new script, please consider contributing it back to this repo
5859
| [list_snapmirrors](list_snapmirrors) | This lists all the SnapMirror relationships that are associated with the specified file system. |
5960
| [list_svms](list_svms) | This lists all the SVMs that are associated with the specified file system. |
6061
| [list_volumes](list_volumes) | This lists all the volumes that are associated with the specified file system. |
62+
| [list_volume_cifs_shares](list_volume_cifs_shares) | This lists cifs shares associated with a volume in the specified file system. |
6163
| [show_fsxn_credentials](show_fsxn_credentials) | This shows the credentials that Workload Factory has stored for the specified FSx for ONTAP file system. |
6264
| [snapmirror_break](snapmirror_break) | This breaks the SnapMirror relationship for the specified relationship. |
6365
| [snapmirror_create](snapmirror_create) | This creates a SnapMirror relationship between the specified source volume and destination SVM. |
@@ -67,6 +69,8 @@ If you do create a new script, please consider contributing it back to this repo
6769
| [snapmirror_update](snapmirror_update) | This updates the SnapMirror relationship for the specified relationship. |
6870
| [snapshot_create](snapshot_create) | This creates a snapshot of the specified volume. |
6971
| [volume_clone](volume_clone) | This clones the specified volume. |
72+
| [volume_cifs_share_create](volume_cifs_share_create) | This will create a CIFS share in a volume. |
73+
| [volume_cifs_share_delete](volume_cifs_share_delete) | This will delete a CIFS share from a volume. |
7074
| [volume_delete](volume_delete) | This deletes the specified volume. |
7175
| [wf_utils](wf_utils) | This file contains common functions used by all the scripts. It includes the `get_token()` function that retrieves an access token from the Workload Factory API. |
7276

Management-Utilities/Workload-Factory-API-Samples/bluexp_organization_delete

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ if [ -z "$token" ]; then
7979
exit 1
8080
fi
8181
#
82-
# Add the organization to the BlueXP workspace.
8382
echo -n "Deleting organization ${ORGANIZATION_ID}..."
8483
run_curl "DELETE" "$token" "https://api.bluexp.netapp.com/v1/management/organizations/$ORGANIZATION_ID" $tmpout $tmperr
8584
echo "Done."
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/bin/bash
2+
#
3+
# This script renamees an BlueXP organization.
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 ORGANIZATION_ID -n NEW_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_ID - Is the Id of the organization to delete.
16+
NEW_NAME - The new name of the organization.
17+
18+
Instead of passing parameters on the command line, you can set the following
19+
environment variables:
20+
21+
export REFRESH_TOKEN=<REFRESH_TOKEN>
22+
EOF
23+
exit 1
24+
}
25+
26+
################################################################################
27+
# Main logic starts here.
28+
################################################################################
29+
tmpout=$(mktemp /tmp/delete_organization_to_bluexp-out.XXXXXX)
30+
tmperr=$(mktemp /tmp/delete_organization_to_bluexp-err.XXXXXX)
31+
trap 'rm -f $tmpout $tmperr' exit
32+
#
33+
# Source the wf_utils file.
34+
wf_utils=$(command -v wf_utils)
35+
if [ -z "$wf_utils" ]; then
36+
if [ ! -x "./wf_utils" ]; then
37+
cat >&2 <<EOF
38+
Error: The 'wf_utils' script was not found in the current directory or in the command search path.
39+
It is required to run this script. You can download it from:
40+
https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples
41+
EOF
42+
exit 1
43+
else
44+
wf_utils=./wf_utils
45+
fi
46+
fi
47+
. "$wf_utils"
48+
#
49+
# Parse the command line options.
50+
while getopts "ht:o:n:" opt; do
51+
case ${opt} in
52+
t) REFRESH_TOKEN=$OPTARG ;;
53+
o) ORGANIZATION_ID=$OPTARG ;;
54+
n) NEW_NAME=$OPTARG ;;
55+
*) usage ;;
56+
esac
57+
done
58+
#
59+
# Declare an array of required options and the error message to display if they are not set.
60+
declare -A required_options
61+
required_options["REFRESH_TOKEN"]='Error: A BlueXP refresh token is required to run this script. It can be obtained from this web page:
62+
https://services.cloud.netapp.com/refresh-token\n\n'
63+
required_options["ORGANIZATION_ID"]='Error: You must provide the name of the organization you want to delete.
64+
You can get the list of organization you have access to by running the "list_bluexp_accts" script
65+
found in this GitHub repository: https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples\n\n'
66+
requiredd_options["NEW_NAME"]='Error: You must provide the new name of the organization.\n\n'
67+
68+
check_required_options
69+
#
70+
# Check that the required commands are available.
71+
for cmd in jq curl; do
72+
if ! command -v $cmd &> /dev/null; then
73+
echo "Error: The required command '$cmd' was not found. Please install it." >&2
74+
exit 1
75+
fi
76+
done
77+
#
78+
# Get an access token.
79+
token=$(get_token)
80+
if [ -z "$token" ]; then
81+
echo "Failed to get a token."
82+
exit 1
83+
fi
84+
#
85+
# Get the type and version.
86+
run_curl "GET" "$token" "https://api.bluexp.netapp.com/v1/management/organizations/$ORGANIZATION_ID" $tmpout $tmperr
87+
org_type=$(jq -r '.type' $tmpout)
88+
org_version=$(jq -r '.version' $tmpout)
89+
#
90+
# Set the new name of the organization.
91+
run_curl "PATCH" "$token" "https://api.bluexp.netapp.com/v1/management/organizations/$ORGANIZATION_ID" $tmpout $tmperr '{"name":"'$NEW_NAME'","type":"'$org_type'","version":"'$org_version'"}'

Management-Utilities/Workload-Factory-API-Samples/eda_project_config_create

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ if [ -z "$token" ]; then
108108
exit 1
109109
fi
110110

111-
body='{ "filters": [ { "tags": [ '
111+
body='{ "filters": {"tags": ['
112112
i=0
113113
while [ $i -lt ${#tags[@]} ]; do
114114
filter_type="multiselect"
@@ -134,7 +134,7 @@ body+='], "resourceProps": [ {
134134
"propName": "OntapVolumeType",
135135
"label": "Volume Type",
136136
"type": "single" }
137-
] } ],
137+
] },
138138
"status": "active" }'
139139

140140
URL="https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/builders/v1/configure"
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
#!/bin/bash
2+
#
3+
################################################################################
4+
# This script is used to list all the cifs shares associated with a volume on
5+
# an ONTAP file system.
6+
#
7+
# It is dependent on the 'wf_utils' file that is included in this repo. That
8+
# file contains the 'get_token' function that is used to obtain a valid
9+
# access token that is needed to run the Workload Factory APIs. The file needs
10+
# to either be in the command search path or in the current directory.
11+
################################################################################
12+
13+
################################################################################
14+
# This function just prints the usage of this script and exits the program.
15+
################################################################################
16+
usage() {
17+
cat >&2 <<EOF
18+
This script is used to list all the cifs shares associated with a volume on
19+
an ONTAP file system.
20+
21+
Usage: $(basename $0) -t refresh_token -a blueXP_account_ID -c credentials_ID -r aws_region -f filesystem_ID -v volume_ID
22+
23+
Where: refresh_token - Is a refresh token used to obtain an access token needed
24+
to run the Workload Factory APIs. You can obtain a refresh
25+
token by going to https://services.cloud.netapp.com/refresh-token
26+
blueXP_account_ID - is the BlueXP account ID. Run 'list_bluexp_accts' to get a
27+
list of accounts you have access to
28+
credentials_ID - is the Workload Factory credentials ID for the AWS account. Run
29+
'list_credentials' to get a list of credentials you have access to
30+
aws_region - is the AWS region where the FSx file systems are located
31+
filesystem_id - is the AWS file system ID of the FSx file system where the volume resides
32+
volume_ID - is the AWS volume ID of the volume where you want to create the cifs share.
33+
34+
Instead of passing parameters on the command line, you can set the
35+
following environment variables:
36+
37+
export REFRESH_TOKEN=<refresh_token>
38+
export BLUEXP_ACCOUNT_ID=<blueXP_account_ID>
39+
export CREDENTIALS_ID=<credentials_ID>
40+
export AWS_REGION=<aws_region>
41+
EOF
42+
exit 1
43+
}
44+
45+
################################################################################
46+
# Main logic starts here.
47+
################################################################################
48+
tmpout=$(mktemp /tmp/create_share-out.XXXXXX)
49+
tmperr=$(mktemp /tmp/create_share-err.XXXXXX)
50+
trap 'rm -f $tmpout $tmperr' exit
51+
#
52+
# Source the wf_utils file.
53+
wf_utils=$(command -v wf_utils)
54+
if [ -z "$wf_utils" ]; then
55+
if [ ! -x "./wf_utils" ]; then
56+
cat >&2 <<EOF
57+
Error: The 'wf_utils' script was not found in the current directory or in the command search path.
58+
It is required to run this script. You can download it from:
59+
https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples
60+
EOF
61+
exit 1
62+
else
63+
wf_utils=./wf_utils
64+
fi
65+
fi
66+
. "$wf_utils"
67+
#
68+
# Process command line options.
69+
while getopts "ht:a:c:r:f:v:" opt; do
70+
case $opt in
71+
t) REFRESH_TOKEN="$OPTARG" ;;
72+
a) BLUEXP_ACCOUNT_ID="$OPTARG" ;;
73+
c) CREDENTIALS_ID="$OPTARG" ;;
74+
r) AWS_REGION="$OPTARG" ;;
75+
f) FILESYSTEM_ID="$OPTARG" ;;
76+
v) VOLUME_ID="$OPTARG" ;;
77+
*) usage ;;
78+
esac
79+
done
80+
#
81+
# Declare an array of required options and the error message to display if they are not set.
82+
declare -A required_options
83+
required_options["REFRESH_TOKEN"]='Error: A BlueXP refresh token is required to run this script. It can be obtain from this web page:
84+
https://services.cloud.netapp.com/refresh-token\n\n'
85+
required_options["BLUEXP_ACCOUNT_ID"]='Error: A BlueXP account ID is required to run this script.
86+
You can get the list of accounts you have access to by running the "list_bluexp_accts" script
87+
found in this GitHub repository: https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples\n\n'
88+
required_options["CREDENTIALS_ID"]='Error: A Worload Factory Credential ID is required to run this script.
89+
You can get a list of credentials by running the "list_credentials" script
90+
found in this GitHub repository: https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples\n\n'
91+
required_options["AWS_REGION"]='Error: The AWS region where the file system is located is required.\n\n'
92+
required_options["FILESYSTEM_ID"]='Error: The ID of the FSxN file system is required.\n\n'
93+
required_options["VOLUME_ID"]='Error: An AWS Volume ID is required to run this script.
94+
You can get the list of file systems you have access to by running the "list_volumes" script
95+
found in this GitHub repository: https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples\n\n'
96+
97+
check_required_options
98+
#
99+
# Check if the required commands are available.
100+
for cmd in jq curl; do
101+
if ! command -v $cmd &> /dev/null; then
102+
echo "Error: The required command '$cmd' was not found. Please install it." >&2
103+
exit 1
104+
fi
105+
done
106+
107+
token=$(get_token)
108+
if [ -z "$token" ]; then
109+
echo "Error: Failed to obtain an access token. Exiting." >&2
110+
exit 1
111+
fi
112+
#
113+
# Get the existing shares and the junction path
114+
run_curl GET "$token" "https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/fsx/v2/credentials/${CREDENTIALS_ID}/regions/${AWS_REGION}/file-systems/${FILESYSTEM_ID}/volumes/${VOLUME_ID}?include=cifsShares" $tmpout $tmperr
115+
jq -r '.cifsShares[] | "\(.name),\(.path)"' $tmpout | column -t -s, -N "Share Name,Path"
116+

Management-Utilities/Workload-Factory-API-Samples/list_volumes

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ usage() {
1818
This script will list all volumes assoicated with the specified FSx for ONTAP
1919
file system.
2020
21-
Usage: $(basename $0) -t refresh_token -a blueXP_account_ID -c credentials_id -r aws_region -f filesystem_id
21+
Usage: $(basename $0) -t refresh_token -a blueXP_account_ID -c credentials_id -r aws_region -f filesystem_id [-j]
2222
2323
Where: refresh_token - Is a refresh token used to obtain an access token needed
2424
to run the Workload Factory APIs. You can obtain a refresh
@@ -30,6 +30,7 @@ Where: refresh_token - Is a refresh token used to obtain an access token needed
3030
credentials you have access to.
3131
aws_region - is the AWS region where the file system resides.
3232
filesystem_id - is the ID of the FSx file system to list SVMs for
33+
j - If specified, the output will be in JSON format instead of a table.
3334
3435
Instead of passing parameters on the command line, you can set the
3536
following environment variables:
@@ -67,13 +68,15 @@ fi
6768
. "$wf_utils"
6869
#
6970
# Process command line arguments.
70-
while getopts "ht:a:c:r:f:" opt; do
71+
JSON_OUTPUT=false
72+
while getopts "ht:a:c:r:f:j" opt; do
7173
case $opt in
7274
t) REFRESH_TOKEN="$OPTARG" ;;
7375
a) BLUEXP_ACCOUNT_ID="$OPTARG" ;;
7476
c) CREDENTIALS_ID="$OPTARG" ;;
7577
r) AWS_REGION="$OPTARG" ;;
7678
f) FILESYSTEM_ID="$OPTARG" ;;
79+
j) JSON_OUTPUT=true ;;
7780
*) usage ;;
7881
esac
7982
done
@@ -107,7 +110,11 @@ if [ -z "$token" ]; then
107110
exit 1
108111
fi
109112

110-
jq_query='.items[] | "\(.name) \(.id) \(.svmId) \(.lifecycle)"'
113+
if [ "$JSON_OUTPUT" == true ]; then
114+
jq_query='.'
115+
else
116+
jq_query='.items[] | "\(.name) \(.id) \(.svmId) \(.lifecycle)"'
117+
fi
111118

112119
run_curl GET "$token" "https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/fsx/v2/credentials/${CREDENTIALS_ID}/regions/${AWS_REGION}/file-systems/${FILESYSTEM_ID}/volumes" $tmpout $tmperr
113120
if jq -r "$jq_query" $tmpout > $tmpout2 2> $tmperr; then
@@ -131,4 +138,9 @@ while [ "$nextToken" != "null" ]; do
131138
fi
132139
nextToken=$(jq -r '.nextToken' $tmpout)
133140
done
134-
sort -f $tmpout2 | column -t -N "Name,Volume ID,SVM ID,Status"
141+
142+
if [ "$JSON_OUTPUT" == true ]; then
143+
cat $tmpout2
144+
else
145+
sort -f $tmpout2 | column -t -N "Name,Volume ID,SVM ID,Status"
146+
fi

0 commit comments

Comments
 (0)