Skip to content
9 changes: 5 additions & 4 deletions Management-Utilities/fsx-ontap-aws-cli-scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Windows Subsystem for Linux (WSL) based Linux distribution installed.
Before running the UNIX based scripts, make sure the following package is installed:

* jq - lightweight and flexible command-line JSON processor
* aws-cli - Command Line Interface for AWS
* aws - Command Line Interface for AWS

## Summary of the convenience scripts

Expand All @@ -17,15 +17,16 @@ Before running the UNIX based scripts, make sure the following package is instal
|create_fsxn_filesystem | Creates a new FSx for NetApp ONTAP file system. |
|create_fsxn_svm | Creates a new Storage Virtual Server (SVM) in a specified FSx for ONTAP file system. |
|create_fsxn_volume | Creates a new volume under a specified SVM. |
|delete_fsxn_filesystem | Deletes a specified FSx for ONTAP file system. Including all the SVMs and volumes on it. |
|delete_fsxn_svm | Deletes a specified SVM. Including all the volumes assigned to it. |
|delete_fsxn_volume | Deletes a specified volume. |
|list_fsx_filesystems | List all the FSx for NetApp ONTAP file systems that the user has access to. |
|list_fsx_filesystems.ps1 | List all the FSx for NetApp ONTAP file systems that the user has access to, written in PowerShell. |
|list_fsxn_volumes | List all the FSx for NetApp ONTAP volumes that the user has access to. |
|list_fsxn_svms | List all the storage virtual machines that the user access to. |
|list_aws_subnets | List all the AWS subnets. |
|list_aws_vpcs | List all the AWS VPCs. |
|delete_fsxn_filesystem | Deletes a specified FSx for ONTAP file system. Including all the SVMs and volumes on it. |
|delete_fsxn_svm | Deletes a specified SVM. Including all the volumes assigned to it. |
|delete_fsxn_volume | Deletes a specified volume. |
|set_fsxn_password | Sets the password for the fsxadmin user of a specified FSxN file system. |


## Author Information
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ usage () {
cat 1>&2 <<EOF
Usage $(basename $0) [-r region] [-a] [-X excludeRegions] [-n] [-c] [-s] [-b] [-i fileSystemId] [-f fileSystemName] [-x] [-t seconds] [-e endpoint_url] [pattern]
Where: pattern - means to only show file systems whos name match the pattern.
-r region allows you to specify the region you want the list from.
-r means to only search the specified region(s) (comma separated list).
-a means all regions.
-X excludeRegions allows you to specify a comma separated list of regions to exclude from the -a option.
-c means to display a hierarchical view of each filesystem including svms and volumes.
Expand All @@ -71,8 +71,16 @@ start_watchdog () {
maxTime=$2
region=$3

sleep $maxTime
if ps -p $pid > /dev/null; then
i=1
while [ $i -le $((maxTime * 2)) ]; do
if ! ps -p $pid > /dev/null 2>&1; then
return 0
fi
sleep .5
let i+=1
done

if ps -p $pid > /dev/null 2>&1; then
printf "\nWarning, timed out while getting the list of FSxNs from the $region region.\nConsider excluding it with the -X option or raising the timeout with the -t option.\n" 1>&2
pkill -P $pid
kill $pid
Expand Down Expand Up @@ -265,7 +273,7 @@ maxTime=20
# Process command line arguments.
while getopts "bhcxsaX:nr:i:f:e:t:" option; do
case "$option" in
r) region="$OPTARG"
r) region="$(echo $OPTARG | sed -e 's/,/ /g')"
;;
a) allRegions=true
;;
Expand Down Expand Up @@ -322,7 +330,6 @@ if [ "$allRegions" == "true" ]; then
# support FSxN
allEndabledRegions=$(aws ec2 describe-regions --query "Regions[].RegionName" --output=json | jq -r '.[]')
allFsxnRegions=$(curl -s https://api.regional-table.region-services.aws.a2z.com/index.json | jq -r '.prices[] | select(.attributes."aws:serviceName" == "Amazon FSx for NetApp ONTAP") .attributes."aws:region"' | egrep -v "$excludeRegions")
# allFsxnRegions=$(curl -s https://api.regional-table.region-services.aws.a2z.com/index.json | jq -r '.prices[] | select(.attributes."aws:serviceName" == "Amazon FSx for NetApp ONTAP") .attributes."aws:region"')
for reg in $allEndabledRegions; do
for fsxnReg in $allFsxnRegions; do
if [ $reg == $fsxnReg ]; then
Expand Down
22 changes: 16 additions & 6 deletions Management-Utilities/fsx-ontap-aws-cli-scripts/list_fsxn_svms
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# o Region
# o File system ID
# o File System Name - optional
# o The managment and NAS IP address of the SVM - optional
# o The management and NAS IP address of the SVM - optional
# o SVM ID
# o SVM Name
################################################################################
Expand All @@ -30,6 +30,7 @@ usage () {
cat 1>&2 <<EOF
Usage $(basename $0) [-r region] [-a] [-X excludeRegiosn] [-n] [-p] [-i fileSystemID] [-f fileSystemName] [-t seonds] [-e endpoint_url]
Where: -a means all regions.
-r means to only search the specified region(s) (comma separated list).
-X means to exclude the specified regions (comma separated list) from the -a option.
-n means to include file systems name.
-p means to include the management and NAS IP address.
Expand All @@ -43,16 +44,25 @@ EOF

################################################################################
# This function is used to kill a process, who's ID is passed as the first
# argument, that is running longger than the time specified as the second
# argurment.
# argument, that is running longer than the time specified as the second
# argument.
################################################################################
start_watchdog () {

pid=$1
maxTime=$2
region=$3
sleep $maxTime
if ps -p $pid > /dev/null; then

i=1
while [ $i -le $((maxTime*2)) ]; do
if ! ps -p $pid > /dev/null 2>&1; then
return
fi
sleep .5
let i+=1
done

if ps -p $pid > /dev/null 2>&1; then
printf "\nWarning, timed out while getting the list of SVMs from the $region region.\nConsider excluding it with the -X option or raising the timeout with the -t option.\n" 1>&2
pkill -P $pid
kill $pid
Expand Down Expand Up @@ -129,7 +139,7 @@ excludeRegions="none"
maxTime=20
while getopts "haX:nr:i:f:pe:t:" option; do
case "$option" in
r) region="$OPTARG"
r) region="$(echo "$OPTARG" | sed -e 's/,/ /g')"
;;
a) allRegions=true
;;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ usage () {
Usage $(basename $0) [-r region] [-a] [-X excludeRegions] [-o] [-f fileSystemName] [-i fileSystemId] [-n] [-s svmID] [-x] [-t seconds] [-e endpoint_url] [volume_pattern]
Where: volume_pattern - Only volumes that match the egrep pattern will be included.
An assumed '^' and '$' is added to the beginning and end of the pattern respectively.
-r region allows you to specify the region you want the list from.
-r means to only include the specified region(s) (comma separated list).
-a means all regions.
-X excludeRegions - Comma separated list of regions to exclude from the search. Only valid when -a is specified.
-n means include the file system and SVM names. Not compatible with the -x option.
Expand All @@ -53,16 +53,25 @@ EOF

################################################################################
# This function is used to kill a process, who's ID is passed as the first
# argument, that is running longger than the time specified as the second
# argurment.
# argument, that is running longer than the time specified as the second
# argument.
################################################################################
start_watchdog () {

pid=$1
maxTime=$2
region=$3
sleep $maxTime
if ps -p $pid > /dev/null; then

i=1
while [ $i -le $((maxTime * 2)) ]; do
if ! ps -p $pid > /dev/null 2>&1; then
return
fi
sleep .5
let i+=1
done

if ps -p $pid > /dev/null 2>&1; then
printf "\nWarning, timed out while getting the list of SVMs from the $region region.\nConsider excluding it with the -X option or raising the timeout with the -t option.\n" 1>&2
pkill -P $pid
kill $pid
Expand Down Expand Up @@ -214,7 +223,7 @@ volumePattern="*"
maxTime=30
while getopts "hr:aX:f:i:nos:xe:t:" option; do
case "$option" in
r) region="$OPTARG"
r) region="$(echo $OPTARG | sed -e 's/,/ /g')"
;;
a) allRegions=true
;;
Expand Down
150 changes: 150 additions & 0 deletions Management-Utilities/fsx-ontap-aws-cli-scripts/set_fsxn_password
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
#!/bin/bash
################################################################################
#
# This script is used to set the fsxadmin password for a FSxN file system.
################################################################################

################################################################################
# This function just outputs the usage information and exits.
################################################################################
usage () {
cat 1>&2 <<EOF
Usage: $(basename $0) -p password [-f fileSystemName] [-i fileSystemId] [-r region] [-w] [-e endpoint_url]
Where:
password: Is the password to set for the fsxadmin user.
fileSystemName: Is the name of the FSxN file system where you want the SVM created. This option is mutually exclusive with the -i option.
fileSystemID: Is the file system ID where you want to create the SVM on. This option is mutually exclusive with the -f option.
region: Is the AWS region where the FSxN file system resides.
-w : Wait for the SVM to be created before returning.
endpoint_url: Is the endpoint url to use when connecting to the AWS API.
EOF
exit 1
}

################################################################################
# Main logic starts here.
################################################################################
tmpout=/tmp/create_svm.$$
trap 'rm -f $tmpout' exit

if which aws jq > /dev/null 2>&1; then
:
else
echo "Error, both the 'aws' and 'jq' commands are required to run this script." 1>&2
exit 1
fi
#
# Set some defaults.
region=$(aws configure get region)
waitForCompletion=false
maxIterations=24
sleepTime=5
#
# Process command line arguments.
while getopts "hwp:r:f:i:e:" option; do
case $option in
p) password=$OPTARG
;;
r) region=$OPTARG
;;
f) fileSystemName=$OPTARG
;;
i) fsid=$OPTARG
;;
w) waitForCompletion=true
;;
e) endpoint_url="--endpoint-url $OPTARG"
;;
*) usage
;;
esac
done

if [ ! -z "$fileSystemName" -a ! -z "$fsid" ]; then
echo "Error, you can only specify the -i OR the -f option. Not both." 1>&2
usage
fi

if [ -z "$password" ]; then
read -sp "Enter the password to set for the fsxadmin user: " password1
echo ""
read -sp "Confirm the password: " password2
echo ""
if [ "$password1" != "$password2" ]; then
echo "Error, the passwords do not match." 1>&2
exit 1
else
password=$password1
fi
fi
#
# Ensure all the required parameters have been provided.
if [ -z "$password" -o -z "$fileSystemName" -a -z "$fsid" ]; then
echo "Error, missing required arguments." 1>&2
usage
fi
#
# Get the file system id from the file system name.
if [ -z "$fsid" ]; then
fsid=$(aws fsx describe-file-systems $endpoint_url --region $region --output=json 2> /dev/null | jq -r ".FileSystems[] | if((.Tags[] | select(.Key == \"Name\") .Value) == \"${fileSystemName}\") then .FileSystemId else empty end" 2> /dev/null)
fi

if [ -z "$fsid" ]; then
echo "Error, could not find the file system with name '${fileSystemName}' in region $region." 1>&2
exit 1
fi
#
# Set the password
aws fsx update-file-system $endpoint_url --ontap-configuration '{"FsxAdminPassword": "'$password'"}' --region=$region --file-system-id "$fsid" --output=json > $tmpout 2>&1
if [ $? != "0" ]; then
echo "Failed to set the password." 1>&2
cat $tmpout 1>&2
exit 1
else
status=$(jq -r .FileSystem.AdministrativeActions[0].Status $tmpout 2> /dev/null)
if [ "$status" == "PENDING" ]; then
printf "Password is being set."
#
# Wait for the svm to be deleted.
if [ $waitForCompletion == true ]; then
i=0
while [ $i -lt $maxIterations ]; do
aws fsx describe-file-systems $endpoint_url --file-system-id $fsid --output=json --region=$region > $tmpout 2>&1
if [ $? -eq 0 ]; then
#
# Assume the first administrative action is the one we just created.
status=$(jq -r .FileSystems[0].AdministrativeActions[0].Status $tmpout 2> /dev/null)
if [ "$status" == "COMPLETED" ]; then
printf "\nPassword has been set.\n"
break
fi
if [ "$status" != "PENDING" -a "$status" != "IN_PROGRESS" ]; then
printf "\nError, failed to set the password on '$fsid'. Status = $status\n" 1>&2
if [ "$status" == "FAILED" ]; then
jq -r .FileSystems[0].AdministrativeActions[0].FailureDetails.Message $tmpout 1>&2
fi
exit 1
fi
else
printf "\nError, failed to get status of filesystem with ID '$fsid'.\n" 1>&2
cat $tmpout 1>&2
exit 1
fi
printf "."
sleep $sleepTime
let i+=1
done
if [ $i -ge $maxIterations ]; then
printf "\nFailed to set the password on file system id '$fsid'. Taking too long.\n" 1>&2
exit 1
fi
else
printf "\n"
fi
else
echo "Unknown status '$status'. Complete output returned from the AWS api:" 1>&2
cat $tmpout 1>&2
exit 1
fi
fi
exit 0
Loading
Loading