-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from NetApp/ckeith2
Adding the convenience scripts
- Loading branch information
Showing
14 changed files
with
2,961 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# FSxN Convenience Scripts | ||
This folder contains sample scripts that are designed to help you use FSxN from | ||
a command line. Most of the scripts are written in Bash, intended to be run either from | ||
a UNIX based O/S (e.g. Linux, MacOS, FreeBSD), or from a Microsoft Windows based system with a | ||
Windows Subsystem for Linux (WSL) based Linux distribution installed. | ||
|
||
## Preparation | ||
Before running the UNIX based scripts, make sure the following package is installed: | ||
|
||
* jq - lightweight and flexible command-line JSON processor | ||
* aws-cli - Command Line Environment for AWS | ||
|
||
## Summary of the convenience scripts | ||
|
||
| Script | Description | | ||
|:--------------------------|:----------------| | ||
|create_fsxn_filesystem | Createa a new FSxN file system.| | ||
|create_fsxn_svm | Creates a new storage virtual machine under the specified file system. | | ||
|create_fsxn_volume | Creates a new volume under a specified SVM. | | ||
|list_fsxn_filesystems | List all the FSxN file systems that the user has access to. | | ||
|list_fsxn_filesystems.ps1 | List all the FSxN file systems that the user has access to, written in PowerShell. | | ||
|list_fsxn_svms | List all the FSxN storage virtual machines that the user access to. | | ||
|list_fsxn_volumes | List all the FSxN volumes that the user has access to. | | ||
|delete_fsxn_filesystem | Deletes a FSxN file system. | | ||
|delete_fsxn_svm | Deltees a FSxN storage virtual machine. | | ||
|delete_fsxn_volume | Deletes a FSxN volume. | | ||
|purge_fsxn_backups | Purges old FSxN backups. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
#!/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] [-endpointIPrange CIDR] | ||
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 and the default is 1024. | ||
throughput: Is the throughput capacity you the file system to have. Valid numbers are 128, 256, 512, 1024, 2048, and 4096. Default is 128. | ||
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. | ||
EOF | ||
exit 1 | ||
} | ||
|
||
################################################################################ | ||
# Main logic starts here. | ||
################################################################################ | ||
tmpout=/tmp/fsx_fs_create.$$ | ||
trap 'rm -f $tmpout' exit | ||
|
||
if which jq aws > /dev/null 2>&1; then | ||
: | ||
else | ||
echo "Error, both the 'aws' and 'jq' commands are required to run this script." 1>&2 | ||
exit 1 | ||
fi | ||
# | ||
# Set some defaults. | ||
size=1024 | ||
throughput=128 | ||
region=$(aws configure list | egrep '^.*egion ' | awk '{print $2}') | ||
securityGroupOption="" | ||
endpointips="" | ||
azType="MULTI_AZ_1" | ||
# | ||
# 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" =~ '^[0-9]+$' ]]; then | ||
echo "-size must be an integer." | ||
usage | ||
fi | ||
if [ "$size" -le 1024 ]; then | ||
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) | ||
if [ "$(echo $2 | tr [A-Z] [a-z])" == "single" ]; then | ||
azType="SINGLE_AZ_1" | ||
elif [ "$(echo $2 | tr [A-Z] [a-z])" == "multi" ]; then | ||
azType="MULTI_AZ_1" | ||
else | ||
echo "Error, known availability type '$2'." | ||
usage | ||
fi | ||
shift | ||
;; | ||
-throughput|--throughput) throughput="$2" | ||
if ! [[ "$throughput" =~ '^[0-9]+$' ]]; then | ||
echo "-throughput must be an integer." | ||
usage | ||
fi | ||
if [ "$througput" != "128" -a "$througput" != "256" -a "$throughput" != "512" -a "$throughput" != "1024" -a "$throughput" != "2048" -a "$throughput" != "4096" ]; then | ||
echo "-throughput must be 128 or 256 or 512 or 1024 or 2048 or 4096." | ||
usage | ||
fi | ||
shift | ||
;; | ||
-endpointiprange|--endpointiprange) | ||
endpointips='"EndpointIpAddressRange": "'$2'",' | ||
shift | ||
;; | ||
-h|-help|--help) | ||
usage | ||
;; | ||
*) echo "Error, unknown option $1." 1>&2 | ||
usage | ||
;; | ||
esac | ||
shift | ||
done | ||
# | ||
# Ensure all the required parameters have been provided. | ||
if [ -z "$fileSystemName" -o -z "$subnetID1" -o "$azType" == "MULTI_AZ_1" -a -z "$subnetID2" ]; then | ||
echo "Missing arguments." 1>&2 | ||
usage | ||
exit 1 | ||
fi | ||
if [ $azType == "SINGLE_AZ_1" ]; then | ||
if [ ! -z "$endpointips" ]; then | ||
echo "Error, you can not 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 | ||
|
||
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'", | ||
"ThroughputCapacity": '$throughput'}' --region=$region > $tmpout 2>&1 | ||
|
||
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 | ||
echo "File system '$fileSystemName' ($(jq -r .FileSystem.FileSystemId $tmpout)) is being created." | ||
exit 0 | ||
else | ||
echo "Unknown status '$status'. Complete output returned from the AWS api:" 1>&2 | ||
cat $tmpout 1>&2 | ||
exit 1 | ||
fi | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
#!/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 virtual storage machine under the | ||
# specified FSxN "filesystem". | ||
################################################################################ | ||
|
||
################################################################################ | ||
# This function just outputs the usage information and exits. | ||
################################################################################ | ||
usage () { | ||
cat 1>&2 <<EOF | ||
Usage: $(basename $0) -n svmName -f fileSystemName [-r region] [-i fileSystemId] | ||
Where: | ||
svmName: Is the name you want to assign the storage virtual machine. | ||
fileSystemName: Is the name of the FSxN file system where you want the SVM created. This option is mutually exclusive with the -i option. | ||
region: Is the AWS region where the FSxN file system resides. | ||
fileSystemID: Is the file system ID where you want to create the SVM on. This option is mutually exclusive with the -f option. | ||
EOF | ||
exit 1 | ||
} | ||
|
||
################################################################################ | ||
# Main logic starts here. | ||
################################################################################ | ||
tmpout=/tmp/create_svm.$$ | ||
trap 'rm -f $tmpout' exit | ||
|
||
if which aws jq > /dev/null 2>&1; then | ||
: | ||
else | ||
echo "Error, both the 'aws' and 'jq' commands are required to run this script." 1>&2 | ||
exit 1 | ||
fi | ||
# | ||
# Set some defaults. | ||
region=$(aws configure list | egrep '^.*egion ' | awk '{print $2}') | ||
# | ||
# Process command line arguments. | ||
while getopts "hn:r:f:i:" option; do | ||
case $option in | ||
n) svmName=$OPTARG | ||
;; | ||
r) region=$OPTARG | ||
;; | ||
f) fileSystemName=$OPTARG | ||
;; | ||
i) fsid=$OPTARG | ||
;; | ||
*) usage | ||
;; | ||
esac | ||
done | ||
|
||
if [ ! -z "$fileSystemName" -a ! -z "$fsid" ]; then | ||
echo "Error, you can only specify the -i OR the -f option. Not both." 1>&2 | ||
usage | ||
fi | ||
# | ||
# Ensure all the required parameters have been provided. | ||
if [ -z "$svmName" -o -z "$fileSystemName" -a -z "$fsid" ]; then | ||
echo "Error, missing required arguments." 1>&2 | ||
usage | ||
fi | ||
# | ||
# Get the file system id from the file system name. | ||
if [ -z "$fsid" ]; then | ||
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) | ||
fi | ||
|
||
if [ -z "$fsid" ]; then | ||
echo "Error, could not find the file system with name '$fileSystemName}' in region $region." 1>&2 | ||
exit 1 | ||
fi | ||
# | ||
# Create the SVM | ||
aws fsx create-storage-virtual-machine --name $svmName --region=$region --file-system-id $fsid --output=json > $tmpout 2>&1 | ||
|
||
if [ $? != "0" ]; then | ||
echo "Failed to create storage virtual machine." 1>&2 | ||
cat $tmpout 1>&2 | ||
exit 1 | ||
else | ||
status=$(jq -r .StorageVirtualMachine.Lifecycle $tmpout 2> /dev/null) | ||
if [ "$status" == "CREATING" -o "$status" == "PENDING" ]; then | ||
echo "Stroage Virtaul Machine '$svmName'($(jq -r '.StorageVirtualMachine.StorageVirtualMachineId' $tmpout)) is being created." | ||
exit 0 | ||
else | ||
echo "Unknown status '$status'. Complete output returned from the AWS api:" 1>&2 | ||
cat $tmpout 1>&2 | ||
exit 1 | ||
fi | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#!/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] | ||
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. | ||
EOF | ||
exit 1 | ||
} | ||
|
||
################################################################################ | ||
# Main logic starts here. | ||
################################################################################ | ||
tmpout=/tmp/create_volume.$$ | ||
trap 'rm -f $tmpout' exit | ||
# | ||
# Set some defaults. | ||
size=20 | ||
region=$(aws configure list | egrep '^.*egion ' | awk '{print $2}') | ||
# | ||
# Process command line arguments. | ||
while getopts "hi:n:r:s:" option; do | ||
case $option in | ||
i) svmId=$OPTARG | ||
;; | ||
n) volumeName=$OPTARG | ||
;; | ||
r) region=$OPTARG | ||
;; | ||
s) size=$OPTARG | ||
;; | ||
*) 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 | ||
|
||
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\", | ||
\"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 | ||
echo "FSxN volume '$volumeName'($(jq -r .Volume.VolumeId $tmpout)) is being created." | ||
exit 0 | ||
else | ||
echo "Unknown status '$status'. Complete output returned from the AWS api:" 1>&2 | ||
cat $tmpout 1>&2 | ||
exit 1 | ||
fi | ||
fi |
Oops, something went wrong.