-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdelete_fsxn_volume
executable file
·78 lines (74 loc) · 2.71 KB
/
delete_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
#!/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 delete an FSxN volume.
################################################################################
################################################################################
# This function just outputs the usage information and exits.
################################################################################
usage () {
cat 1>&2 <<EOF
Usage: $(basename $0) -i volumeID [-r region] [-b]
where
volumeID: is the ID of the volume to delete.
region: is the AWS region where the FSxN filesystem resides.
-b: enable final backup. Otherwise it is skipped.
EOF
exit 1
}
################################################################################
# Main logic starts here.
################################################################################
tmpout=/tmp/delete-volume.$$
trap 'rm -f $tmpout' exit
#
# Set some defaults.
region=$(aws configure list | egrep '^.*egion ' | awk '{print $2}')
#
# Process command line arguments.
skipBackup=true
while getopts "hbi:r:" option; do
case $option in
r) region="$OPTARG"
;;
i) volumeId="$OPTARG"
;;
b) skipBackup=false
;;
*) usage
;;
esac
done
#
# Ensure all the required parameters have been provided.
if [ -z "$volumeId" ]; then
echo "Error, missing required arguments." 1>&2
usage
fi
aws fsx delete-volume --volume-id $volumeId --region=$region --output=json --ontap-configuration '{"SkipFinalBackup": '$skipBackup'}' > $tmpout 2>&1
if [ $? != "0" ]; then
echo "Failed to delete volume." 1>&2
cat $tmpout 1>&2
exit 1
else
status=$(jq -r .Lifecycle $tmpout 2> /dev/null)
if [ "$status" == "DELETING" -o "$status" == "PENDING" ]; then
echo "Volume '$volumeId' is being deleted."
exit 0
else
echo "Unknown status '$status'. Complete output returned from the AWS api:" 1>&2
cat $tmpout 1>&2
exit 1
fi
fi