-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcreate_fsxn_volume
executable file
·154 lines (149 loc) · 5.53 KB
/
create_fsxn_volume
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
#!/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 volume under the specified SVM. The
# FSxN "filesystem" is implied by the SVM ID.
################################################################################
################################################################################
# This function just outputs the usage information and exits.
################################################################################
usage () {
cat 1>&2 <<EOF
Usage: $(basename $0) -i svmID -n volumeName [-r region] [-s size] [-v volumeStyle] [-a aggregate] [-w]
where
svmID: is the SVM ID in the filesystem you want to create the volume.
volumeName: is the name you want to assign the volume.
region: is the AWS region where the FSxN filesystem resides.
size: is size, in megabytes, you want the filesystem. Default is 20.
volumeStyle: Is the style of the volume. Either FlexVol or FlexGroup. Default is flexvol.
aggregate: is the name of the aggregate you want the volume put on. Required for FlexVol volumes on Scale-Out deployments. Default is aggr1.
-w : wait for the volume to be created before returning.
EOF
exit 1
}
################################################################################
# Main logic starts here.
################################################################################
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
#
intergerRegex='^[0-9]+$'
#
# Set some defaults.
size=20
region=$(aws configure list | egrep '^.*egion ' | awk '{print $2}')
waitForCompletion=false
volumeStyle="flexvol"
aggregateOption=""
#
# Process command line arguments.
while getopts "ha:i:n:r:s:v:w" option; do
case $option in
i) svmId=$OPTARG
;;
n) volumeName=$OPTARG
;;
r) region=$OPTARG
;;
s) size=$OPTARG
if ! [[ $size =~ $intergerRegex ]]; then
echo "Error, size must be an integer." 1>&2
usage
fi
;;
v) volumeStyle=$OPTARG
;;
a) aggregateOption='"AggregateConfiguration":{"Aggregates":["'$OPTARG'"]},'
;;
w) waitForCompletion=true
;;
*) usage
;;
esac
done
#
# Ensure all the required parameters have been provided.
if [ -z "$volumeName" -o -z "$svmId" ]; then
echo "Error, you must provide a volume name and SVM ID." 1>&2
usage
fi
volumeStyle=$(echo $volumeStyle | tr '[a-z] ' '[A-Z]')
if [ $volumeStyle != "FLEXVOL" -a $volumeStyle != "FLEXGROUP" ]; then
echo "Error, volume style must be either FlexVol or FlexGroup." 1>&2
usage
fi
aws fsx create-volume --volume-type ONTAP --name $volumeName --ontap-configuration '{
"JunctionPath": "/'$volumeName'",
"SecurityStyle": "UNIX",
"SizeInMegabytes" : '$size',
"StorageEfficiencyEnabled": true,
"StorageVirtualMachineId": "'$svmId'",
"TieringPolicy" : {"CoolingPeriod": 31, "Name": "SNAPSHOT_ONLY"},
"OntapVolumeType": "RW",
"VolumeStyle": "'$volumeStyle'",
'$aggregateOption'
"SnapshotPolicy": "default"}' --region=$region --output=json > $tmpout 2>&1
if [ $? != "0" ]; then
echo "Failed to create the FSxN volume." 1>&2
cat $tmpout 1>&2
exit 1
else
status=$(jq -r .Volume.Lifecycle $tmpout 2> /dev/null)
if [ "$status" == "CREATING" -o "$status" == "PENDING" ]; then
volumeId=$(jq -r .Volume.VolumeId $tmpout)
printf "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
reason="$(jq -r '.Volumes[0].LifecycleTransitionReason.Message' $tmpout 2> /dev/null)"
if [ -n "$reason" ]; then
echo "Reason: $reason" 1>&2
else
cat $tmpout 1>&2
fi
exit 1
fi
echo -n "."
sleep $sleepTime
done
if [ $i -gt $maxIterations ]; then
printf "\nError, volume creation failed. Took too long." 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