Skip to content

Commit 5aa506e

Browse files
authored
Merge pull request #265 from NetApp/add_s3_endpoint_support
Modified delete_fsxn_volume to handle deleting a volume that has s3 access points attached to it.
2 parents d49d41f + 4cd7cc8 commit 5aa506e

File tree

6 files changed

+70
-12
lines changed

6 files changed

+70
-12
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ numSvms=$(jq '.StorageVirtualMachines | length' $svmsFile)
176176
if [ $numVolumes -gt 0 -o $numSvms -gt 0 ]; then
177177
echo "Here are the current contents of the '$fileSystemName'($fsid) file system you have indicated you want to delete:"
178178
displayFileSystemContents $fsid
179-
read -p "Are you sure you want to delete this file system, with all the above volumes (yes/no)? " response
179+
read -p "Are you sure you want to delete this file system, with all the volumes listed above and any attached s3 Access Points (yes/no)? " response
180180
if [ "$response" != "yes" ]; then
181181
echo "Aborted."
182182
exit 1

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

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,48 @@ EOF
3030
exit 1
3131
}
3232

33+
################################################################################
34+
# This function waits for the an s3 access point attached to a volume
35+
# to be deleted.
36+
################################################################################
37+
waitForS3ApDelete () {
38+
39+
local s3ApName=$1
40+
local volumeId=$2
41+
local MaxIterations=60
42+
local SleepTime=5
43+
#
44+
# Wait for the s3ap to be deleted.
45+
i=0
46+
while [ $i -lt $MaxIterations ]; do
47+
aws fsx describe-s3-access-point-attachments --names $s3ApName --output=json --region=$region > $tmpout 2>&1
48+
if [ $? -eq 0 ]; then
49+
status=$(jq -r .S3AccessPointAttachments[0].Lifecycle $tmpout 2> /dev/null)
50+
if [ "$status" != "DELETING" -a "$status" != "PENDING" ]; then
51+
printf "\nError, failed to delete volume S3 Access Point $s3ApName attached to volume ID '$volumeId'. Status = ${status}.\n" 1>&2
52+
reason="$(jq -r '.S3AccessPointAttachments[0].LifecycleTransitionReason.Message' $tmpout 2> /dev/null)"
53+
if [ ! -z "$reason" ]; then
54+
echo "Reason: $reason" 1>&2
55+
else
56+
cat $tmpout 1>&2
57+
fi
58+
return 1
59+
fi
60+
else
61+
# Assume if it failed, it is because the s3 AP was deleted and doesn't exist anymore.
62+
break
63+
fi
64+
[ $quiet != "true" ] && printf "."
65+
sleep $SleepTime
66+
let i+=1
67+
done
68+
if [ $i -ge $MaxIterations ]; then
69+
printf "\nFailed to delete volume with volume ID of '$volumeId'. Taking too long.\n" 1>&2
70+
return 1
71+
fi
72+
return 0
73+
}
74+
3375
################################################################################
3476
# This function waits for the volume to be deleted.
3577
################################################################################
@@ -113,7 +155,21 @@ if [ -z "$volumeId" ]; then
113155
usage
114156
fi
115157

116-
aws fsx delete-volume --volume-id $volumeId --region=$region --output=json --ontap-configuration '{"SkipFinalBackup": '$skipBackup'}' > $tmpout 2>&1
158+
aws fsx describe-s3-access-point-attachments --filter "Name=volume-id,Values=$volumeId" --region=$region --output=json > $tmpout 2>&1
159+
if [ "$(jq -r '.S3AccessPointAttachments | length' $tmpout 2>&1)" != "0" ]; then
160+
while read s3apName; do
161+
[ $quiet != "true" ] && printf "S3 Access Point '$s3apName' is being deleted." 1>&2
162+
aws fsx detach-and-delete-s3-access-point --name $s3apName --region=$region --output=json > $tmpout 2>&1
163+
if waitForS3ApDelete $s3apName $volumeId; then
164+
:
165+
else
166+
exit 1
167+
fi
168+
[ $quiet != "true" ] && printf "\n"
169+
done < <(jq -r '.S3AccessPointAttachments[] | .S3AccessPoint.ResourceARN | split("/")[1]' $tmpout 2>/dev/null)
170+
fi
171+
172+
aws fsx delete-volume --volume-id $volumeId --region=$region --output=json --ontap-configuration '{"SkipFinalBackup": '$skipBackup'}' --output=json > $tmpout 2>&1
117173

118174
if [ $? != "0" ]; then
119175
echo "Failed to delete volume." 1>&2

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ for region in $regions; do
5151
printf "\nRegion: $region\n"
5252
fi
5353
if [ -z "$vpcId" ]; then
54-
aws ec2 describe-subnets --region=$region | jq -r '.Subnets[] | .VpcId + "," + .SubnetId + "," + .CidrBlock + "," + (if(has("Tags")) then first(.Tags[] | select(.Key == "Name").Value) // "" else "" end)' | awk -F, 'BEGIN {formatStr="%21s %24s %18s %s\n"; printf(formatStr, "VPC Id", "Subnet ID", "CIDR", "Name")} {printf(formatStr , $1, $2, $3, $4)}'
54+
aws ec2 describe-subnets --region=$region --output=json | jq -r '.Subnets[] | .VpcId + "," + .SubnetId + "," + .CidrBlock + "," + (if(has("Tags")) then first(.Tags[] | select(.Key == "Name").Value) // "" else "" end)' | awk -F, 'BEGIN {formatStr="%21s %24s %18s %s\n"; printf(formatStr, "VPC Id", "Subnet ID", "CIDR", "Name")} {printf(formatStr , $1, $2, $3, $4)}'
5555
else
56-
aws ec2 describe-subnets --region=$region --filters '[{"Name": "vpc-id", "Values": ["'$vpcId'"]}]' | jq -r '.Subnets[] | .VpcId + "," + .SubnetId + "," + .CidrBlock + "," + (if(has("Tags")) then first(.Tags[] | select(.Key == "Name").Value) // "" else "" end)' | awk -F, 'BEGIN {formatStr="%21s %24s %18s %s\n"; printf(formatStr, "VPC Id", "Subnet ID", "CIDR", "Name")} {printf(formatStr , $1, $2, $3, $4)}'
56+
aws ec2 describe-subnets --region=$region --output=json --filters '[{"Name": "vpc-id", "Values": ["'$vpcId'"]}]' | jq -r '.Subnets[] | .VpcId + "," + .SubnetId + "," + .CidrBlock + "," + (if(has("Tags")) then first(.Tags[] | select(.Key == "Name").Value) // "" else "" end)' | awk -F, 'BEGIN {formatStr="%21s %24s %18s %s\n"; printf(formatStr, "VPC Id", "Subnet ID", "CIDR", "Name")} {printf(formatStr , $1, $2, $3, $4)}'
5757
fi
5858
done

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ vpcFormatStr="%21s %19s %s\n"
5959
for region in $regions; do
6060
[ "$quiet" != "True" ] && printf "\nRegion: $region\n"
6161
first=True
62-
aws ec2 describe-vpcs --region=$region | jq -r '.Vpcs[] | .VpcId + " " + .CidrBlock + " " + (if (has("Tags")) then .Tags[] | (select(.Key == "Name") .Value) else "" end)' | \
62+
aws ec2 describe-vpcs --region=$region --output=json | jq -r '.Vpcs[] | .VpcId + " " + .CidrBlock + " " + (if (has("Tags")) then .Tags[] | (select(.Key == "Name") .Value) else "" end)' | \
6363
while read vpcId cidr name; do
6464
if [ "$quiet" != "True" -a "$first" == "True" ]; then
6565
printf "\n$vpcFormatStr" "VPC IP" "CIDR" "Name"
@@ -69,7 +69,7 @@ for region in $regions; do
6969

7070
if [ "$subnets" == "True" ]; then
7171
printf "\n\tSubnets:\n"
72-
aws ec2 describe-subnets --region=$region --filters '[{"Name": "vpc-id", "Values": ["'$vpcId'"]}]' | jq -r '.Subnets[] | .VpcId + " " + .SubnetId + " " + .CidrBlock + " " + (if(has("Tags")) then first(.Tags[] | select(.Key == "Name").Value) // "" else "" end)' | awk 'BEGIN {formatStr="\t\t%24s %18s %s\n"; printf(formatStr, "Subnet ID", "CIDR", "Name")} {name=$4; for (i=5; i<=NF; i++) {name=name " " $(i)}; printf(formatStr , $2, $3, name)}'
72+
aws ec2 describe-subnets --region=$region --output=json --filters '[{"Name": "vpc-id", "Values": ["'$vpcId'"]}]' | jq -r '.Subnets[] | .VpcId + " " + .SubnetId + " " + .CidrBlock + " " + (if(has("Tags")) then first(.Tags[] | select(.Key == "Name").Value) // "" else "" end)' | awk 'BEGIN {formatStr="\t\t%24s %18s %s\n"; printf(formatStr, "Subnet ID", "CIDR", "Name")} {name=$4; for (i=5; i<=NF; i++) {name=name " " $(i)}; printf(formatStr , $2, $3, name)}'
7373
first=True
7474
fi
7575
done

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,14 +250,16 @@ for region in ${regions[*]}; do
250250
jq -r '.[] | if(.FileSystemType == "ONTAP") then .FileSystemId + "," + .ResourceARN + "," + .Name + "," + .Lifecycle + "," + .ManagementIp + "," + .VpcId + "," + .SubnetId + "," + if(.AutomaticBackupRetentionDays == null) then "Dissabled" else (.AutomaticBackupRetentionDays | tostring) end + "," + .DeploymentType + "," + (.DiskIopsConfiguration | tostring) + "," + (.ThroughputCapacity | tostring) + "," + (.StorageCapacity | tostring) else empty end' $fileSystemsFile > $tmpout
251251
fi
252252

253+
largestName=$(awk -F, 'BEGIN {max=0} {if(length($3) > max){max=length($3)}} END {print max}' < $tmpout)
254+
nameFieldWidth=$((largestName + 4))
253255
if [ "$includeExtraInfo" == "true" ]; then
254-
awk -F, -v region=$region 'BEGIN {first=1; formatStr="%12s %23s %35s %10s %15s %22s %25s %6s %12s %11s %6s\n"}; {if(first) {printf "\n"; printf formatStr, "Region", "FileSystem ID", "Name", "Status", "Management IP", "VPC ID", "Subnet ID", "Size", "Deployment", "Throughput", "Iops"; first=0}; printf formatStr, region, $1, "\"" $3 "\"", $4, $5, $6, $7, $(12), $9, $(11), $(10)}' < $tmpout
256+
awk -F, -v region=$region 'BEGIN {first=1; formatStr="%12s %23s %'$nameFieldWidth's %14s %15s %22s %25s %6s %12s %11s %6s\n"}; {if(first) {printf "\n"; printf formatStr, "Region", "FileSystem ID", "Name", "Status", "Management IP", "VPC ID", "Subnet ID", "Size", "Deployment", "Throughput", "Iops"; first=0}; printf formatStr, region, $1, "\"" $3 "\"", $4, $5, $6, $7, $(12), $9, $(11), $(10)}' < $tmpout
255257
else
256258
if [ "$showARN" == "true" ]; then
257-
awk -F, -v region=$region 'BEGIN {first=1; formatStr="%12s %23s %70s %35s %10s %15s\n"}; {if(first) {printf "\n"; printf formatStr, "Region", "FileSystem ID", "ARN", "Name", "Status", "Management IP"; first=0}; printf formatStr, region, $1, $2, "\"" $3 "\"", $4, $5}' < $tmpout
259+
awk -F, -v region=$region 'BEGIN {first=1; formatStr="%12s %23s %70s %'$nameFieldWidth's %14s %15s\n"}; {if(first) {printf "\n"; printf formatStr, "Region", "FileSystem ID", "ARN", "Name", "Status", "Management IP"; first=0}; printf formatStr, region, $1, $2, "\"" $3 "\"", $4, $5}' < $tmpout
258260
else
259-
formatStr='%12s %23s %35s %10s %15s\n'
260-
[ "$showBackup" == "true" ] && formatStr='%12s %23s %35s %10s %15s %17s\n'
261+
formatStr='%12s %23s %'$nameFieldWidth's %14s %15s\n'
262+
[ "$showBackup" == "true" ] && formatStr='%12s %23s %'$nameFieldWidth's %14s %15s %17s\n'
261263
awk -F, -v region=$region 'BEGIN {first=1; formatStr="'"${formatStr}"'"}; {if(first) {printf "\n"; printf formatStr, "Region", "FileSystem ID", "Name", "Status", "Management IP", "Backup Retention"; first=0}; printf formatStr, region, $1, "\"" $3 "\"", $4, $5, $8}' < $tmpout
262264
fi
263265
fi

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ for region in ${regions[*]}; do
126126
else
127127
filter="--filter Name=file-system-id,Values=$fileSystemID"
128128
fi
129-
aws fsx describe-storage-virtual-machines --region=$region $filter | jq -r '.StorageVirtualMachines[] | "\(.FileSystemId),\(.StorageVirtualMachineId),\(.Endpoints.Nfs.IpAddresses[0]),\(.Name),\(.Lifecycle)"' | sort > $tmpout
129+
aws fsx describe-storage-virtual-machines --output=json --region=$region $filter | jq -r '.StorageVirtualMachines[] | "\(.FileSystemId),\(.StorageVirtualMachineId),\(.Endpoints.Nfs.IpAddresses[0]),\(.Name),\(.Lifecycle)"' | sort > $tmpout
130130
if [ $includeIp == "true" ]; then
131131
ipFmt="%16s"
132132
ipHeader="IP"
@@ -136,7 +136,7 @@ for region in ${regions[*]}; do
136136
fi
137137

138138
if [ $includeFsName == "true" ]; then
139-
aws fsx describe-file-systems --region=$region | jq -r '.FileSystems[] | .FileSystemId + "," + (.Tags[] | select(.Key == "Name") .Value)' > $tmpout2
139+
aws fsx describe-file-systems --output=json --region=$region | jq -r '.FileSystems[] | .FileSystemId + "," + (.Tags[] | select(.Key == "Name") .Value)' > $tmpout2
140140
awk -F, -v region=$region -v ipFmt=$ipFmt -v ipHeader=$ipHeader 'BEGIN {first=1; maxNameLen=0; while(getline < "'$tmpout2'") {fss[$1]=$2; if(length($2) > maxNameLen) {maxNameLen=length($2)}}; maxNameLen +=2; formatStr="%12s %20s%-"maxNameLen"s %23s "ipFmt" %13s %s\n"}; {if(first) {printf "\n"; printf formatStr, "Region", "FileSystem ID", "(Name)", "SVM ID", ipHeader, "State", "SVM Name"; first=0}; if(ipHeader != "IP") {ip=""} else {ip=$3}; name="("fss[$1]")"; printf formatStr, region, $1, name, $2, ip, $5, $4}' < $tmpout
141141
else
142142
awk -F, -v region=$region -v ipFmt=$ipFmt -v ipHeader=$ipHeader 'BEGIN {first=1; formatStr="%12s %23s %23s "ipFmt" %13s %s\n"}; {if(first) {printf "\n"; printf formatStr, "Region", "FileSystem ID", "SVM ID", ipHeader, "State", "SVM Name"; first=0}; if(ipHeader != "IP") {ip=""} else {ip=$3}; printf formatStr, region, $1, $2, ip, $5, $4}' < $tmpout

0 commit comments

Comments
 (0)