-
Notifications
You must be signed in to change notification settings - Fork 2
/
create_fsxn_filesystem
executable file
·284 lines (270 loc) · 10 KB
/
create_fsxn_filesystem
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
#!/bin/bash
################################################################################
# THIS SOFTWARE IS PROVIDED BY NETAPP "AS IS" AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
# EVENT SHALL NETAPP BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR'
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
################################################################################
#
# This script is used to create an FSxN filesystem.
################################################################################
################################################################################
# This function just outputs the usage information and exits.
################################################################################
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] [-numberPairs numberPairs] [-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.
subnetID2: Is the subnet ID of the standby subnet you want the file system to be accessible from. Only allowed for multi availability zone deployments.
security-group-id: Is the security ID that you want applied to the ENIs that are assigned to the file system.
region: Is the AWS region where the FSxN file system will reside.
availability: Specifies whether the HA pair should be spread across 'single' or 'multiple' availability zones. Valid settings are 'single' or 'multi' (default).
size: Is size, in gigabytes, you want the file system to be. Minimum is 1024 per number of HA pairs. Default is 1024.
throughput: Is the throughput capacity you the file system to have. Valid Gen1 numbers are 128, 256, 512, 1024, 2048, and 4096. Valid Gen2 numbers are 384, 768, 1536, 3072, and 6144. Default is 128.
numberPairs: Is the number of HA pairs you want the file system to have. Can only be greater than 1 with throupghput numbers of 1536, 3072, and 6144. Default is 1.
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
}
################################################################################
# Main logic starts here.
################################################################################
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
#
# Possible throughput values
throughputValuesGen1=(128 256 512 1024 2048 4096)
throughputValuesGen2=(384 768 1536 3072 6144)
throughputValuesMultiHAPairs=(1536 3072 6144)
integerRegex='^[0-9]+$'
################################################################################
# This function is used to see if the first value passed is in one of the
# other parameters passed.
################################################################################
is_in(){
local value=$1
shift
for i in "$@"; do
if [ $i == $value ]; then
return 0
fi
done
return 1
}
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
throughput=128
region=$(aws configure list | egrep '^.*egion ' | awk '{print $2}')
securityGroupOption=""
endpointips=""
availType=multi
numPairs=1
waitForCompletion=false
#
# Process command line arguments.
while [ ! -z "$1" ]; do
case $(echo "$1" | tr [A-Z] [a-z]) in
-name|--name) fileSystemName="$2"
shift
;;
-region|--region) region="$2"
shift
;;
-size|--size) size="$2"
if ! [[ "$size" =~ $integerRegEx ]]; then
echo "-size must be an integer."
usage
fi
shift
;;
-subnetid1|--subnetid1) subnetID1="$2"
shift
;;
-subnetid2|--subnetid2) subnetID2="$2"
shift
;;
-security-group-id|--security-group-id) securityGroupOption="--security-group-ids $2"
shift
;;
-type|--type)
availType=$2
if [ $availType != "single" -a $availType != "multi" ]; then
echo "-type must be 'single' or 'multi'." 1>&2
usage
fi
shift
;;
-throughput|--throughput) throughput="$2"
if ! [[ "$throughput" =~ $integerRegEx ]]; then
echo "-throughput must be an integer."
usage
fi
shift
;;
-endpointiprange|--endpointiprange)
endpointips='"EndpointIpAddressRange": "'$2'",'
shift
;;
-numberpairs|--numberpairs) numPairs="$2"
if ! [[ "$numPairs" =~ $integerRegEx ]]; then
echo "-numPairs must be an integer."
usage
fi
shift
;;
-wait|--wait)
waitForCompletion=true
;;
-h|-help|--help)
usage
;;
*) echo "Error, unknown option $1." 1>&2
usage
;;
esac
shift
done
if is_in "$throughput" "${throughputValuesGen1[@]}"; then
if [ $availType == "single" ]; then
azType="SINGLE_AZ_1"
elif [ $availType == "multi" ]; then
azType="MULTI_AZ_1"
else
echo "Error, unknown availability type '$availType'."
usage
fi
elif is_in "$throughput" "${throughputValuesGen2[@]}"; then
if [ $availType == "single" ]; then
azType="SINGLE_AZ_2"
elif [ $availType == "multi" ]; then
azType="MULTI_AZ_2"
else
echo "Error, unknown availability type '$availType'."
usage
fi
else
echo "Error, unsupported throughput value '$throughput'."
usage
fi
#
# Ensure all the required parameters have been provided.
if [ -z "$fileSystemName" ]; then
echo "Error, you must specify a file system name." 1>&2
usage
fi
if [ -z "$subnetID1" -o "$azType" == "MULTI_AZ_1" -a -z "$subnetID2" -o "$azType" == "MULTI_AZ_2" -a -z "$subnetID2" ]; then
echo "Error, you must specify only subnetID1 for a single availability zone deployments or both subnetID1 and subnetID2 for a multi availability zone deployments." 1>&2
usage
fi
if [[ $azType == *"SINGLE_AZ"* ]]; then
if [ ! -z "$endpointips" ]; then
echo "Error, you cannot specify Endpoint IP address range when deploying in a single availability zone." 1>&2
exit 1
fi
if [ ! -z "$subnetID2" ]; then
echo "Error, you can't specify a second subnet with deploying in a single availability zone." 1>&2
exit 1
fi
fi
if [ $numPairs -gt 1 ]; then
if ! is_in "$throughput" "${throughputValuesMultiHAPairs[@]}"; then
echo "Error, you can only specify more than one HA pair with throughput values of 1536, 3072, and 6144." 1>&2
usage
fi
if [ $azType != "SINGLE_AZ_2" ]; then
echo "Error, you can only specify more than one HA pair with a single availability zone deployment." 1>&2
usage
fi
fi
minSize=$((1024*numPairs))
if [ $size -lt $minSize ]; then
echo "Error, the size must be at least $minSize for $numPairs HA pairs. In other words 1024 per HA pair." 1>&2
usage
fi
echo aws fsx create-file-system --output=json --file-system-type ONTAP --storage-capacity $size --subnet-ids $subnetID1 $subnetID2 --storage-type SSD --tags "Key=Name,Value=$fileSystemName" $securityGroupOption --ontap-configuration '{
"PreferredSubnetId": "'$subnetID1'",
'$endpointips'
"DeploymentType": "'$azType'",
"HAPairs": '$numPairs',
"ThroughputCapacityPerHAPair": '$throughput'}' --region=$region
# "ThroughputCapacityPerHAPair": '$throughput'}' --region=$region > $tmpout 2>&1
exit
if [ $? != "0" ]; then
echo "Failed to create FSxN file system." 1>&2
cat $tmpout 1>&2
exit 1
else
status=$(jq -r .FileSystem.Lifecycle $tmpout 2> /dev/null)
if [ "$status" == "CREATING" -o "$status" == "PENDING" ]; then
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
reason="$(jq -r '.FileSystems[0].LifecycleTransitionReason.Message' $tmpout 2> /dev/null)"
if [ ! -z "$reason" ]; then
echo "Reason: $reason" 1>&2
else
cat $tmpout 1>&2
fi
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