Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made delete_fsxn_svm smarter #194

Merged
merged 11 commits into from
Oct 5, 2024
18 changes: 9 additions & 9 deletions Management-Utilities/fsx-ontap-aws-cli-scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ Before running the UNIX based scripts, make sure the following package is instal

| Script | Description |
|:------------------------|:----------------|
|create_fsxn_filesystem | Creates a new FSx for NetApp ONTAP file-system |
|create_fsxn_svm | Creates a new Storage Virtual Server (svm) in a soecific FSx ONTAP filesystem |
|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. |
|list_fsx_filesystems | List all the FSx for NetApp ONTAP filesystems that the user has access to. |
|list_fsx_filesystems.ps1 | List all the FSx for NetApp ONTAP filesystems that the user has access to, written in PowerShell. |
|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 an FSx for NetApp ONTAP filesystem. |
|delete_fsxn_svm | Deletes an svm. |
|delete_fsxn_volume | Deletes a volume. |
|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. |


## Author Information
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
################################################################################
usage () {
cat 1>&2 <<EOF
Usage: $(basename $0) -name fileSystemName -subnetID1 subnetID1 -subnetID2 subnetID2 [-region region] [-type availability] [-size size] [-security-group-id securityGroupID] [-throughput throughput] [-endpointIPrange CIDR]
Usage: $(basename $0) -name fileSystemName -subnetID1 subnetID1 -subnetID2 subnetID2 [-region region] [-type availability] [-size size] [-security-group-id securityGroupID] [-throughput throughput] [-endpointIPrange CIDR] [-wait]
where
fileSystemName: Is the name you want to assign the file system.
subnetID1: Is the subnet ID of the preferred subnet you want the file system to be accessible from.
Expand All @@ -31,6 +31,7 @@ where
size: Is size, in gigabytes, you want the file system to be. Minimum and the default is 1024.
throughput: Is the throughput capacity you the file system to have. Valid numbers are 128, 256, 512, 1024, 2048, and 4096. Default is 128.
CIDR: Is an address range that the system management, and data access, IPs will be allocated from. It is only allowed for multi availability zone deployments.
--wait: Forces the script to wait until the file system is created before returning.
EOF
exit 1
}
Expand All @@ -40,13 +41,23 @@ EOF
################################################################################
tmpout=/tmp/fsx_fs_create.$$
trap 'rm -f $tmpout' exit
#
# Set the maximum number of times to check that the file system was created.
# Multiple it by the SleepTime set below to the total amount of time allowed.
MaxIterations=180
#
# Set the number of seconds to wait between checks that the file system
# has been created.
SleepTime=15

if which jq aws > /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
for cmd in jq aws; do
if which $cmd > /dev/null 2>&1; then
:
else
echo "Error, the '$cmd' is required to run this script." 1>&2
exit 1
fi
done
#
# Set some defaults.
size=1024
Expand All @@ -55,6 +66,7 @@ region=$(aws configure list | egrep '^.*egion ' | awk '{print $2}')
securityGroupOption=""
endpointips=""
azType="MULTI_AZ_1"
waitForCompletion=false
#
# Process command line arguments.
while [ ! -z "$1" ]; do
Expand Down Expand Up @@ -110,6 +122,9 @@ while [ ! -z "$1" ]; do
endpointips='"EndpointIpAddressRange": "'$2'",'
shift
;;
-wait|--wait)
waitForCompletion=true
;;
-h|-help|--help)
usage
;;
Expand Down Expand Up @@ -151,11 +166,44 @@ if [ $? != "0" ]; then
else
status=$(jq -r .FileSystem.Lifecycle $tmpout 2> /dev/null)
if [ "$status" == "CREATING" -o "$status" == "PENDING" ]; then
echo "File system '$fileSystemName' ($(jq -r .FileSystem.FileSystemId $tmpout)) is being created."
exit 0
fsid=$(jq -r .FileSystem.FileSystemId $tmpout)
printf "File system '$fileSystemName' ($fsid) is being created."
if [ $waitForCompletion == "true" ]; then
i=0
while [ $i -lt $MaxIterations ]; do
aws fsx describe-file-systems --file-system-ids $fsid --output=json --region=$region > $tmpout 2>&1
if [ $? -eq 0 ]; then
status=$(jq -r '.FileSystems[0].Lifecycle' $tmpout 2> /dev/null)
if [ "$status" == "AVAILABLE" ]; then
printf "\nFile system '$fileSystemName' ($fsid) has been created.\n"
break
fi
if [ "$status" != "CREATING" -a "$status" != "PENDING" ]; then
printf "\nError, failed to create the file system. Status = $status\n" 1>&2
cat $tmpout 1>&2
exit 1
fi
printf "."
else
printf "\nError, failed to get the file system status.\n" 1>&2
cat $tmpout 1>&2
exit 1
fi
sleep $SleepTime
let i+=1
done
if [ $i -ge $MaxIterations ]; then
printf "\nFailed to create file system('$fsid'). Taking too long.\n" 1>&2
exit 1
fi
exit 0
else
echo
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
54 changes: 47 additions & 7 deletions Management-Utilities/fsx-ontap-aws-cli-scripts/create_fsxn_svm
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
################################################################################
usage () {
cat 1>&2 <<EOF
Usage: $(basename $0) -n svmName -f fileSystemName [-r region] [-i fileSystemId]
Usage: $(basename $0) -n svmName [-f fileSystemName] [-i fileSystemId] [-r region] [-w]
Where:
svmName: Is the name you want to assign the storage virtual machine.
fileSystemName: Is the name of the FSxN file system where you want the SVM created. This option is mutually exclusive with the -i option.
region: Is the AWS region where the FSxN file system resides.
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.
EOF
exit 1
}
Expand All @@ -46,9 +47,12 @@ fi
#
# Set some defaults.
region=$(aws configure list | egrep '^.*egion ' | awk '{print $2}')
waitForCompletion=false
maxIterations=24
sleepTime=5
#
# Process command line arguments.
while getopts "hn:r:f:i:" option; do
while getopts "hwn:r:f:i:" option; do
case $option in
n) svmName=$OPTARG
;;
Expand All @@ -58,6 +62,8 @@ while getopts "hn:r:f:i:" option; do
;;
i) fsid=$OPTARG
;;
w) waitForCompletion=true
;;
*) usage
;;
esac
Expand All @@ -76,11 +82,11 @@ fi
#
# Get the file system id from the file system name.
if [ -z "$fsid" ]; then
fsid=$(aws fsx describe-file-systems --output=json 2> /dev/null | jq -r ".FileSystems[] | if((.Tags[] | select(.Key == \"Name\") .Value) == \"${fileSystemName}\") then .FileSystemId else empty end" 2> /dev/null)
fsid=$(aws fsx describe-file-systems --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
echo "Error, could not find the file system with name '${fileSystemName}' in region $region." 1>&2
exit 1
fi
#
Expand All @@ -94,11 +100,45 @@ if [ $? != "0" ]; then
else
status=$(jq -r .StorageVirtualMachine.Lifecycle $tmpout 2> /dev/null)
if [ "$status" == "CREATING" -o "$status" == "PENDING" ]; then
echo "Stroage Virtaul Machine '$svmName'($(jq -r '.StorageVirtualMachine.StorageVirtualMachineId' $tmpout)) is being created."
exit 0
svmId=$(jq -r '.StorageVirtualMachine.StorageVirtualMachineId' $tmpout)
printf "Stroage Virtaul Machine '$svmName'($svmId) is being created."
#
# Wait for the svm to be deleted.
if [ $waitForCompletion == true ]; then
i=0
while [ $i -lt $maxIterations ]; do
aws fsx describe-storage-virtual-machines --storage-virtual-machine-ids $svmId --output=json --region=$region > $tmpout 2>&1
if [ $? -eq 0 ]; then
status=$(jq -r '.StorageVirtualMachines[0].Lifecycle' $tmpout 2> /dev/null)
if [ "$status" == "CREATED" ]; then
printf "\nStorage Virtual Machine '$svmName'($svmId) has been created.\n"
break
fi
if [ "$status" != "CREATING" -a "$status" != "PENDING" ]; then
printf "\nError, failed to create SVM with SVM ID '$svmId'. Status = $status\n" 1>&2
cat $tmpout 1>&2
exit 1
fi
else
printf "\nError, failed to get status of SVM with SVM ID '$svmId'.\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 create SVM with SVM ID of '$svmID'. 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
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,18 @@ EOF
tmpout=/tmp/create_volume.$$
trap 'rm -f $tmpout' exit
#
# Set the maximum number of times to check that a volume has been
# created. Multiple it by the SleepTime set below to the total amount of
# time allowed.
maxIterations=24
#
# Set the number of seconds to wait between checks that a volume and/or SVM has been deleted.
sleepTime=5
#
# Set some defaults.
size=20
region=$(aws configure list | egrep '^.*egion ' | awk '{print $2}')
waitForCompletion=false
#
# Process command line arguments.
while getopts "hi:n:r:s:w" option; do
Expand All @@ -53,7 +62,7 @@ while getopts "hi:n:r:s:w" option; do
;;
s) size=$OPTARG
;;
w) wait=1
w) waitForCompletion=true
;;
*) usage
;;
Expand Down Expand Up @@ -84,21 +93,35 @@ else
status=$(jq -r .Volume.Lifecycle $tmpout 2> /dev/null)
if [ "$status" == "CREATING" -o "$status" == "PENDING" ]; then
volumeId=$(jq -r .Volume.VolumeId $tmpout)
echo "FSxN volume '$volumeName'($volumeId) is being created."
if [ ! -z "$wait" ]; then
echo -n "Waiting for volume to be created."
while [ $status == "CREATING" -o $status == "PENDING" ]; do
sleep 4
printf "FSxN volume '$volumeName'($volumeId) is being created."
if [ "$waitForCompletion" == "true" ]; then
i=0
while [ $i -lt $maxIterations ]; do
aws fsx describe-volumes --volume-ids $volumeId --region=$region --output=json > $tmpout 2>&1
status=$(jq -r .Volumes[0].Lifecycle $tmpout 2> /dev/null)
if [ $status == "CREATED" ]; then
printf "\nVolume '$volumeName'($volumeId) has been created.\n"
break
fi
if [ $status != "CREATING" -a $status != "PENDING" ]; then
echo "Error, volume $volumeId creation failed." 1>&2
cat $tmpout 1>&2
exit 1
fi
echo -n "."
sleep $sleepTime
done
printf "\nVolume as been $status.\n"
if [ $i -gt $maxIterations ]; then
printf "\nError, volume creation failed. Took too long." 1>&2
exit 1
fi
else
printf "\n"
fi
exit 0
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