Skip to content

Commit ab0af06

Browse files
committed
Made all the create and delete script support a 'wait' option; Made the delete_fsxn_svm support deleting all the volumes under the SVM; Now delete_fsxn_filesystem calls delete_fsxn_svm to delete SVMs, and delete_fsxn_svm calls delete_fsxn_volume to delete volumes.
1 parent 3511e27 commit ab0af06

File tree

7 files changed

+464
-261
lines changed

7 files changed

+464
-261
lines changed

Management-Utilities/fsx-ontap-aws-cli-scripts/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ Before running the UNIX based scripts, make sure the following package is instal
1414

1515
| Script | Description |
1616
|:------------------------|:----------------|
17-
|create_fsxn_filesystem | Creates a new FSx for NetApp ONTAP file-system |
18-
|create_fsxn_svm | Creates a new Storage Virtual Server (svm) in a soecific FSx ONTAP filesystem |
17+
|create_fsxn_filesystem | Creates a new FSx for NetApp ONTAP file-system. |
18+
|create_fsxn_svm | Creates a new Storage Virtual Server (SVM) in a soecific FSx ONTAP filesystem. |
1919
|create_fsxn_volume | Creates a new volume under a specified SVM. |
2020
|list_fsx_filesystems | List all the FSx for NetApp ONTAP filesystems that the user has access to. |
2121
|list_fsx_filesystems.ps1 | List all the FSx for NetApp ONTAP filesystems that the user has access to, written in PowerShell. |
2222
|list_fsxn_volumes | List all the FSx for NetApp ONTAP volumes that the user has access to. |
2323
|list_fsxn_svms | List all the storage virtual machines that the user access to. |
2424
|list_aws_subnets | List all the aws subnets. |
25-
|list_aws_vpcs | List all the aws vpcs. |
26-
|delete_fsxn_filesystem | Deletes an FSx for NetApp ONTAP filesystem. |
27-
|delete_fsxn_svm | Deletes an svm. |
25+
|list_aws_vpcs | List all the aws VPCs. |
26+
|delete_fsxn_filesystem | Deletes an FSx for NetApp ONTAP filesystem. Including all the SVMs and volumes on it. |
27+
|delete_fsxn_svm | Deletes an svm. Including all the volumes assigned to it. |
2828
|delete_fsxn_volume | Deletes a volume. |
2929

3030

Management-Utilities/fsx-ontap-aws-cli-scripts/create_fsxn_filesystem

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
################################################################################
2121
usage () {
2222
cat 1>&2 <<EOF
23-
Usage: $(basename $0) -name fileSystemName -subnetID1 subnetID1 -subnetID2 subnetID2 [-region region] [-type availability] [-size size] [-security-group-id securityGroupID] [-throughput throughput] [-endpointIPrange CIDR]
23+
Usage: $(basename $0) -name fileSystemName -subnetID1 subnetID1 -subnetID2 subnetID2 [-region region] [-type availability] [-size size] [-security-group-id securityGroupID] [-throughput throughput] [-endpointIPrange CIDR] [-wait]
2424
where
2525
fileSystemName: Is the name you want to assign the file system.
2626
subnetID1: Is the subnet ID of the preferred subnet you want the file system to be accessible from.
@@ -31,6 +31,7 @@ where
3131
size: Is size, in gigabytes, you want the file system to be. Minimum and the default is 1024.
3232
throughput: Is the throughput capacity you the file system to have. Valid numbers are 128, 256, 512, 1024, 2048, and 4096. Default is 128.
3333
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.
34+
--wait: Forces the script to wait until the file system is created before returning.
3435
EOF
3536
exit 1
3637
}
@@ -40,13 +41,23 @@ EOF
4041
################################################################################
4142
tmpout=/tmp/fsx_fs_create.$$
4243
trap 'rm -f $tmpout' exit
44+
#
45+
# Set the maximum number of times to check that the file system was created.
46+
# Multiple it by the SleepTime set below to the total amount of time allowed.
47+
MaxIterations=180
48+
#
49+
# Set the number of seconds to wait between checks that the file system
50+
# has been created.
51+
SleepTime=15
4352

44-
if which jq aws > /dev/null 2>&1; then
45-
:
46-
else
47-
echo "Error, both the 'aws' and 'jq' commands are required to run this script." 1>&2
48-
exit 1
49-
fi
53+
for cmd in jq aws; do
54+
if which $cmd > /dev/null 2>&1; then
55+
:
56+
else
57+
echo "Error, the '$cmd' is required to run this script." 1>&2
58+
exit 1
59+
fi
60+
done
5061
#
5162
# Set some defaults.
5263
size=1024
@@ -55,6 +66,7 @@ region=$(aws configure list | egrep '^.*egion ' | awk '{print $2}')
5566
securityGroupOption=""
5667
endpointips=""
5768
azType="MULTI_AZ_1"
69+
waitForCompletion=false
5870
#
5971
# Process command line arguments.
6072
while [ ! -z "$1" ]; do
@@ -110,6 +122,9 @@ while [ ! -z "$1" ]; do
110122
endpointips='"EndpointIpAddressRange": "'$2'",'
111123
shift
112124
;;
125+
-wait|--wait)
126+
waitForCompletion=true
127+
;;
113128
-h|-help|--help)
114129
usage
115130
;;
@@ -151,11 +166,44 @@ if [ $? != "0" ]; then
151166
else
152167
status=$(jq -r .FileSystem.Lifecycle $tmpout 2> /dev/null)
153168
if [ "$status" == "CREATING" -o "$status" == "PENDING" ]; then
154-
echo "File system '$fileSystemName' ($(jq -r .FileSystem.FileSystemId $tmpout)) is being created."
155-
exit 0
169+
fsid=$(jq -r .FileSystem.FileSystemId $tmpout)
170+
printf "File system '$fileSystemName' ($fsid) is being created."
171+
if [ $waitForCompletion == "true" ]; then
172+
i=0
173+
while [ $i -lt $MaxIterations ]; do
174+
aws fsx describe-file-systems --file-system-ids $fsid --output=json --region=$region > $tmpout 2>&1
175+
if [ $? -eq 0 ]; then
176+
status=$(jq -r '.FileSystems[0].Lifecycle' $tmpout 2> /dev/null)
177+
if [ "$status" == "AVAILABLE" ]; then
178+
printf "\nFile system '$fileSystemName' ($fsid) has been created.\n"
179+
break
180+
fi
181+
if [ "$status" != "CREATING" -a "$status" != "PENDING" ]; then
182+
printf "\nError, failed to create the file system. Status = $status\n" 1>&2
183+
cat $tmpout 1>&2
184+
exit 1
185+
fi
186+
printf "."
187+
else
188+
printf "\nError, failed to get the file system status.\n" 1>&2
189+
cat $tmpout 1>&2
190+
exit 1
191+
fi
192+
sleep $SleepTime
193+
let i+=1
194+
done
195+
if [ $i -ge $MaxIterations ]; then
196+
printf "\nFailed to create file system('$fsid'). Taking too long.\n" 1>&2
197+
exit 1
198+
fi
199+
exit 0
200+
else
201+
echo
202+
fi
156203
else
157204
echo "Unknown status '$status'. Complete output returned from the AWS api:" 1>&2
158205
cat $tmpout 1>&2
159206
exit 1
160207
fi
161208
fi
209+
exit 0

Management-Utilities/fsx-ontap-aws-cli-scripts/create_fsxn_svm

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@
2121
################################################################################
2222
usage () {
2323
cat 1>&2 <<EOF
24-
Usage: $(basename $0) -n svmName -f fileSystemName [-r region] [-i fileSystemId]
24+
Usage: $(basename $0) -n svmName [-f fileSystemName] [-i fileSystemId] [-r region] [-w]
2525
Where:
2626
svmName: Is the name you want to assign the storage virtual machine.
2727
fileSystemName: Is the name of the FSxN file system where you want the SVM created. This option is mutually exclusive with the -i option.
28-
region: Is the AWS region where the FSxN file system resides.
2928
fileSystemID: Is the file system ID where you want to create the SVM on. This option is mutually exclusive with the -f option.
29+
region: Is the AWS region where the FSxN file system resides.
30+
-w : Wait for the SVM to be created before returning.
3031
EOF
3132
exit 1
3233
}
@@ -46,9 +47,12 @@ fi
4647
#
4748
# Set some defaults.
4849
region=$(aws configure list | egrep '^.*egion ' | awk '{print $2}')
50+
waitForCompletion=false
51+
maxIterations=24
52+
sleepTime=5
4953
#
5054
# Process command line arguments.
51-
while getopts "hn:r:f:i:" option; do
55+
while getopts "hwn:r:f:i:" option; do
5256
case $option in
5357
n) svmName=$OPTARG
5458
;;
@@ -58,6 +62,8 @@ while getopts "hn:r:f:i:" option; do
5862
;;
5963
i) fsid=$OPTARG
6064
;;
65+
w) waitForCompletion=true
66+
;;
6167
*) usage
6268
;;
6369
esac
@@ -76,11 +82,11 @@ fi
7682
#
7783
# Get the file system id from the file system name.
7884
if [ -z "$fsid" ]; then
79-
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)
85+
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)
8086
fi
8187

8288
if [ -z "$fsid" ]; then
83-
echo "Error, could not find the file system with name '$fileSystemName}' in region $region." 1>&2
89+
echo "Error, could not find the file system with name '${fileSystemName}' in region $region." 1>&2
8490
exit 1
8591
fi
8692
#
@@ -94,11 +100,45 @@ if [ $? != "0" ]; then
94100
else
95101
status=$(jq -r .StorageVirtualMachine.Lifecycle $tmpout 2> /dev/null)
96102
if [ "$status" == "CREATING" -o "$status" == "PENDING" ]; then
97-
echo "Stroage Virtaul Machine '$svmName'($(jq -r '.StorageVirtualMachine.StorageVirtualMachineId' $tmpout)) is being created."
98-
exit 0
103+
svmId=$(jq -r '.StorageVirtualMachine.StorageVirtualMachineId' $tmpout)
104+
printf "Stroage Virtaul Machine '$svmName'($svmId) is being created."
105+
#
106+
# Wait for the svm to be deleted.
107+
if [ $waitForCompletion == true ]; then
108+
i=0
109+
while [ $i -lt $maxIterations ]; do
110+
aws fsx describe-storage-virtual-machines --storage-virtual-machine-ids $svmId --output=json --region=$region > $tmpout 2>&1
111+
if [ $? -eq 0 ]; then
112+
status=$(jq -r '.StorageVirtualMachines[0].Lifecycle' $tmpout 2> /dev/null)
113+
if [ "$status" == "CREATED" ]; then
114+
printf "\nStorage Virtual Machine '$svmName'($svmId) has been created.\n"
115+
break
116+
fi
117+
if [ "$status" != "CREATING" -a "$status" != "PENDING" ]; then
118+
printf "\nError, failed to create SVM with SVM ID '$svmId'. Status = $status\n" 1>&2
119+
cat $tmpout 1>&2
120+
exit 1
121+
fi
122+
else
123+
printf "\nError, failed to get status of SVM with SVM ID '$svmId'.\n" 1>&2
124+
cat $tmpout 1>&2
125+
exit 1
126+
fi
127+
printf "."
128+
sleep $sleepTime
129+
let i+=1
130+
done
131+
if [ $i -ge $maxIterations ]; then
132+
printf "\nFailed to create SVM with SVM ID of '$svmID'. Taking too long.\n" 1>&2
133+
exit 1
134+
fi
135+
else
136+
printf "\n"
137+
fi
99138
else
100139
echo "Unknown status '$status'. Complete output returned from the AWS api:" 1>&2
101140
cat $tmpout 1>&2
102141
exit 1
103142
fi
104143
fi
144+
exit 0

Management-Utilities/fsx-ontap-aws-cli-scripts/create_fsxn_volume

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,18 @@ EOF
3838
tmpout=/tmp/create_volume.$$
3939
trap 'rm -f $tmpout' exit
4040
#
41+
# Set the maximum number of times to check that a volume has been
42+
# created. Multiple it by the SleepTime set below to the total amount of
43+
# time allowed.
44+
maxIterations=24
45+
#
46+
# Set the number of seconds to wait between checks that a volume and/or SVM has been deleted.
47+
sleepTime=5
48+
#
4149
# Set some defaults.
4250
size=20
4351
region=$(aws configure list | egrep '^.*egion ' | awk '{print $2}')
52+
waitForCompletion=false
4453
#
4554
# Process command line arguments.
4655
while getopts "hi:n:r:s:w" option; do
@@ -53,7 +62,7 @@ while getopts "hi:n:r:s:w" option; do
5362
;;
5463
s) size=$OPTARG
5564
;;
56-
w) wait=1
65+
w) waitForCompletion=true
5766
;;
5867
*) usage
5968
;;
@@ -84,21 +93,35 @@ else
8493
status=$(jq -r .Volume.Lifecycle $tmpout 2> /dev/null)
8594
if [ "$status" == "CREATING" -o "$status" == "PENDING" ]; then
8695
volumeId=$(jq -r .Volume.VolumeId $tmpout)
87-
echo "FSxN volume '$volumeName'($volumeId) is being created."
88-
if [ ! -z "$wait" ]; then
89-
echo -n "Waiting for volume to be created."
90-
while [ $status == "CREATING" -o $status == "PENDING" ]; do
91-
sleep 4
96+
printf "FSxN volume '$volumeName'($volumeId) is being created."
97+
if [ "$waitForCompletion" == "true" ]; then
98+
i=0
99+
while [ $i -lt $maxIterations ]; do
92100
aws fsx describe-volumes --volume-ids $volumeId --region=$region --output=json > $tmpout 2>&1
93101
status=$(jq -r .Volumes[0].Lifecycle $tmpout 2> /dev/null)
102+
if [ $status == "CREATED" ]; then
103+
printf "\nVolume '$volumeName'($volumeId) has been created.\n"
104+
break
105+
fi
106+
if [ $status != "CREATING" -a $status != "PENDING" ]; then
107+
echo "Error, volume $volumeId creation failed." 1>&2
108+
cat $tmpout 1>&2
109+
exit 1
110+
fi
94111
echo -n "."
112+
sleep $sleepTime
95113
done
96-
printf "\nVolume as been $status.\n"
114+
if [ $i -gt $maxIterations ]; then
115+
printf "\nError, volume creation failed. Took too long." 1>&2
116+
exit 1
117+
fi
118+
else
119+
printf "\n"
97120
fi
98-
exit 0
99121
else
100122
echo "Unknown status '$status'. Complete output returned from the AWS api:" 1>&2
101123
cat $tmpout 1>&2
102124
exit 1
103125
fi
104126
fi
127+
exit 0

0 commit comments

Comments
 (0)