#!/bin/sh

#######################################################################
# copyright (C) 2016 by NetApp.  All Rights Reserved.
#
#######################################################################

prog_name="netapp_ipspace_limit_check"
IPSPACE_LIMIT=512

echo "${prog_name} script start";

count=`ngsh -c "set -rows 0; network ipspace show -fields ipspace" | wc -l`
count=`expr $count - 7` #exclude Default IPspace and Cluster IPspace + header lines (2) and footers (2) + 1 (set rows)

if [ $count -gt $IPSPACE_LIMIT ]; then
    cat << EOF
WARNING: There are $count IPspaces configured on the cluster.
         The maximum supported IPspace count is $IPSPACE_LIMIT.
         Please remove unused IPspace before upgrade to DATA ONTAP 9.0.
         To view the IPspace configured, run the command:
             network ipspace show
         To remove an IPspace, run the command:
             network ipspace delete
EOF
    exit 1
fi

echo "${prog_name} script pass"

exit 0
