echo ""
echo "          ScaleIO UI Init          "
echo "-----------------------------------"
echo ""
echo "Current UI MDM Settings:"
echo ""
echo "Primary MDM IP = " $prim_ip
echo "Secondary MDM IP = " $sec_ip
echo ""
echo -n "Are these correct? (y/n)? "
read yn
if [ "$yn" == "y" ]; then
	echo ""
	echo "MDM IP's Set Correctly"
else
	echo "MDM Environment variables need to be set!!"
	echo "Exit script and type in: "
	echo ""
	echo "export prim_ip=xxx.xxx.xxx.xxx (use correct ip address for primary mdm)"
	echo "export sec_ip=xxx.xxx.xxx.xxx (use correct ip address for secondary mdm)"
	echo ""
	read -p "Press enter to exit and correct ip information"
	
exit
fi
glob=${prim_ip},${sec_ip}
echo ""
echo -n "Do you need to login (y/n)? "
read login_y_n
if [ "$login_y_n" == "y" ]; then
echo -n "Username: "
read username1
scli --login --mdm_ip $glob --username $username1
echo ""
else
echo ""
fi

function login()
{
echo -n "Username: "
read username1
scli --login --mdm_ip $glob --username $username1
echo ""

}
#Query functions
#System object query functions
function query_sys_objects()
{
echo""
echo "Queries all System Objects"
echo ""
scli --mdm_ip $glob --query_all |more
}
#
function query_connected_sdc()
{
scli --mdm_ip $glob --query_all_sdc |grep "Connected" |more
}
#
function query_sdc_name()
{
echo ""
echo "Queries an SDC by Name"
echo ""
echo "List of SDC's"
echo ""
scli --mdm_ip $glob --query_all_sdc |more
echo ""
echo -n "Which SDC would you like to query? "
read query_sdc_by_name
scli --mdm_ip $glob --query_sdc --sdc_name $query_sdc_by_name |more
echo ""
}
 
function query_sdc_ip()
{
echo ""
echo "Queries an SDC by IP"
echo ""
echo "List of SDC's"
echo ""
scli --mdm_ip $glob --query_all_sdc |more
echo ""
echo -n "Which SDC would you like to query? "
read query_sdc_by_ip
scli --mdm_ip $glob --query_sdc --sdc_ip $query_sdc_by_ip |more
echo ""
}

function sdc_queries()
{
 option=0
 until [ "$option" = "5" ]; do
 echo ""
 echo "SDC Query Menu"
 echo ""
 echo "  1.) Query All Connected SDC's"
 echo "  2.) Query SDC by Name"
 echo "  3.) Query SDC by IP"
 echo "  4.) Return to Query Menu"
 echo ""
 echo -n "Enter choice: "
 read option
 echo ""
 case $option in
 1 ) query_connected_sdc;;
 2 ) query_sdc_name;;
 3 ) query_sdc_ip;;
 4 ) querymenu;;
 * ) tput setf 5;echo "Please enter 1, 2, 3 or 4";tput setf 5; 
 esac
 done
}
#
#Volume Queries
#
function query_all_volumes()
{
echo "Query all volumes"}
echo ""
scli --mdm_ip $glob --query_all_volumes |more
}
#
#volume to sdc map
function query_volume_to_sdc()
{
echo "Displaying Volume to SDC Mapping"
echo -n "Enter a keyword for search or hit 'enter' if none is requested: "
read keyword_vol
for x in $(scli --mdm_ip $glob --query_all_volumes |grep -E 'Mapped' |awk '{print $3}')
do
v_id=$(scli --mdm_ip $glob --query_volume --volume_id $x |grep "Volume ID" |awk '{print $4}')
v_name=$(scli --mdm_ip $glob --query_volume --volume_id $x |grep "Name:" |grep "prov" |awk '{print $6}')
v_size=$(scli --mdm_ip $glob --query_volume --volume_id $x |grep "Size" |awk '{print $8,$9,$10}')
v_type=$(scli --mdm_ip $glob --query_volume --volume_id $x |grep "Size" |awk '{print $7}')
v_dom=$(scli --mdm_ip $glob --query_volume --volume_id $x |grep "Protection Domain" |awk '{print $1,$2,$4,$5}')
v_pool=$(scli --mdm_ip $glob --query_volume --volume_id $x |grep "Storage Pool" |awk '{print $4,$5}')
s_name=$(scli --mdm_ip $glob --query_volume --volume_id $x |grep "SDC ID" |awk '{print $6,$7}')
s_ip=$(scli --mdm_ip $glob --query_volume --volume_id $x |grep "SDC ID" |awk '{print $4,$5}')
echo ""
echo "Volume Name: " $v_name "-> Volume ID:" $v_id " -> " $v_size " -> " $v_type " ->" $v_dom " -> Pool" $v_pool " -> SDC" $s_name " -> SDC" $s_ip |grep "$keyword_vol" |more
done
}
#
# SDS Menu Functions
#
#
#
#Function to add an SDS without any devices
function sdsadd()
{
echo ""
echo "Adds an SDS to the cluster without Devices"
echo -n "SDS IP: "
read ip
echo -n "SDS name: "
read name
echo ""
echo "Protection Domain List"
	scli --mdm_ip $glob --query_properties --object_type PROTECTION_DOMAIN --all_objects --properties NAME |grep "NAME" |awk '{print $2}'
	echo ""
echo -n "Protection Domain Name: "
read domain
echo -n "Define Fault Set? (y or n): "
read fs_yes
if [ "$fs_yes" == "y" ]; then
	echo "Fault Set Name"
	read fsname
	
	scli --mdm_ip $glob --add_sds --sds_ip $ip --sds_name $name --fault_set_name $fsname --protection_domain_name $domain
	else
	scli --mdm_ip $glob --add_sds --sds_ip $ip --sds_name $name --protection_domain_name $domain
fi
}
#function to remove SDS
function sdsrem()
{
	echo ""
	echo "Removes an SDS from the cluster"
	scli --mdm_ip $glob --query_all_sds
	echo ""
	echo -n "What SDS would you like to remove? "
    read sds_rem
	scli --mdm_ip $glob --remove_sds --sds_name $sds_rem
}
#function to add devices on an SDS
function addsdsdev()
{
echo "Adds Devices to Existing SDS"
ans="y"
yesorno="y"
while [ "$ans" == "$yesorno" ];
do
       
echo ""
	   echo "Displaying Current SDS"
		for zz in $(scli --mdm_ip $glob --query_all_sds |grep "SDS ID" |awk '{print $5}')
			do
				sds_dev_count=$(scli --mdm_ip $glob --query_sds --sds_name $zz |grep "Device")
echo "SDS Name " $zz " "$sds_dev_count
done
        echo ""
		echo -n "What SDS would you like to add a device to? "
        read sds_dev
		echo "Current " $sds_dev " Devices"
		scli --mdm_ip $glob --query_sds --sds_name $sds_dev |grep "Path"
		echo ""
        echo -n "How many devices would you like to add? " 
		read devcount
		echo ""
		echo "List of Pools"
		scli --mdm_ip $glob --query_properties --object_type STORAGE_POOL --properties UNUSED_CAPACITY_IN_KB,NAME  --all_objects
		echo ""
		echo -n "What pool would you like to add the devices to? "
		read pool_dev
		echo -n "Do you want to specify a device prefix (ex. /dev/) y or n?: "
			 read sds_prefix_yes
			 if [ $sds_prefix_yes == "y" ]; then
				echo -n "Enter Prefix: "
				read sds_prefix
				let num_dev=devcount+1
				COUNTER=1
				while [  $COUNTER -lt $num_dev ]; do
           			echo -n "Device #" $COUNTER " to add? (ex. /sdb): "
					read dev_path_pre
				echo -n "Device Name #" $COUNTER " to add?: "
				read dev_name_pre
				scli --mdm_ip $glob --add_sds_device --sds_name $sds_dev --storage_pool_name $pool_dev --device_path $sds_prefix$dev_path_pre --device_name $dev_name_pre
				let COUNTER=COUNTER+1 
				done
			else
			let num_dev=devcount+1
			COUNTER=1
			while [  $COUNTER -lt $num_dev ]; do
				echo -n "Device #" $COUNTER " to add? (ex. /dev/sdb): "
				read dev_path
				echo -n "Device Name #" $COUNTER " to add?: "
				read dev_name
				scli --mdm_ip $glob --add_sds_device --sds_name $sds_dev --storage_pool_name $pool_dev --device_path $dev_path --device_name $dev_name
				let COUNTER=COUNTER+1 
				done
			fi
    echo -n "Would you like to add more devices to another pool or to another SDS? (y or n): "
	read yesorno
done
}
#function to remove SDS dev's
function remsdsdev()
{
echo "Removes Devices from an Existing SDS"
answ="y"
yes_or_no="y"
while [ "$answ" == "$yes_or_no" ];
do
        echo "Displaying SDS"
        scli --mdm_ip $glob --query_all_sds
        echo -n "What SDS would you like to remove a device from? (Use SDS Name): "
        read sds_query
		echo ""
		scli --mdm_ip $glob --query_sds --sds_name $sds_query |grep "Path"
		echo ""
        echo -n "How many devices would you like to remove? " 
		read devcount_rem
		let num_dev_rem=devcount_rem+1
		COUNTER_rem=1
		while [  $COUNTER_rem -lt $num_dev_rem ]; do
			 echo -n "Device Name #"$COUNTER_rem "to remove? "
			 read dev_name_rem
			 scli --mdm_ip $glob --remove_sds_device --sds_name $sds_query --device_name $dev_name_rem
             let COUNTER_rem=COUNTER_rem+1 
		done
    echo -n "Would you like to remove more devices from another SDS? (y or n): "
	read yes_or_no
done
}
#
#SDC Functions
#function to add an SDC
function addsdc()
{
echo -n "Ip Address of an SDC you would like to add?  "
read sdc_ip
echo -n "What name would you like to give the SDC?  "
read sdc_name
scli --mdm_ip $glob --add_sdc --sdc_ip $sdc_ip --sdc_name $sdc_name
echo ""
}
#
#Function to rename an SDC
function renamesdc()
{
echo ""
echo "Current SDC's"
scli --mdm_ip $glob --query_all_sdc |grep "SDC ID"
echo -n "IP of the SDC to Rename? "
read sdc_ip_rename
echo -n " New SDC Name? "
read sdc_new_name
scli --mdm_ip $glob --rename_sdc --sdc_ip $sdc_ip_rename --new_name $sdc_new_name
echo ""
}
#
#Volume Functions
#
#function to create a single volumes
function volumecreate()
{
answer_volumecreate="y"
yesorno_volumecreate="y"
while [ "$answer_volumecreate" == "$yesorno_volumecreate" ];
do
	echo -n "Volume Name: "
	read volname_volumecreate
	for vol_x in $(scli --mdm_ip $glob --query_all_volumes |grep "Volume ID" |awk '{print $5}')
	do 
	if [ $vol_x == $volname_volumecreate ]; then
	 echo "Volume name is already in use, pick another"	
	volumecreate
	else
	echo -n ""
	fi
	done
	echo -n "Thick or thin volumes (use thick of thin)? "
	read prov_volumecreate
	prov_type_volume_create=""
	if [ "$prov_volumecreate" == "thin" ]; then
		prov_type_volumecreate="thin_provisioned"
		else
		prov_type_volumecreate="thick_provisioned"
	fi
	echo -n  "Volume Size in GB (examples: 8, 16, 24): "
	read volsize_volumecreate
	echo ""
	echo "Protection Domain List"
	scli --mdm_ip $glob --query_properties --object_type PROTECTION_DOMAIN --all_objects --properties NAME |grep "NAME" |awk '{print $2}'
	echo ""
	echo -n "Which Protection Domain? "
	read domain_volumecreate
	echo ""
	echo "List of Pools"
	scli --mdm_ip $glob --query_properties --object_type STORAGE_POOL --properties UNUSED_CAPACITY_IN_KB,NAME --all_objects
	echo ""
	echo -n "Which Storage Pool? "	
	read pool_volumecreate
	scli --mdm_ip $glob --add_volume --volume_name $volname_volumecreate --$prov_type_volumecreate --protection_domain_name $domain_volumecreate --storage_pool_name $pool_volumecreate --size_gb $volsize_volumecreate
	echo -n "Would you like to create another volume? (y or n) "
	read yesorno_volumecreate
done
}
#function to bulk create volumes
function bulkvolumecreate()
{
answer_bulkvolumecreate="y"
yesorno_bulkvolumecreate="y"
while [ "$answer_bulkvolumecreate" == "$yesorno_bulkvolumecreate" ];
do
	echo -n "Volume Name (# Iterator will be added to Volume Name ex. myvol1, myvol2): "
	read volname_bulkvolumecreate
	echo "Printout of existing volumes with the same name: "
	scli --mdm_ip $glob --query_all_volumes |grep "$volname_bulkvolumecreate" |grep "Size" |awk '{print $5}'
	echo -n "How Many Volumes Would You Like to Create? "
	read volcount
	echo -n "Starting Volume Number: "
	read startvol_bulkvolumecreate
	echo -n "Thick or thin volumes (use thick or thin): "
	read prov_bulkvolumecreate
	prov_type_bulkvolumecreate=""
	if [ "$prov_bulkvolumecreate" == "thin" ]; then
	prov_type_bulkvolumecreate="thin_provisioned"
	else
	prov_type_bulkvolumecreate="thick_provisioned"
	fi
	echo -n "Volume Size in GB (ex. 8, 16, 32)? "
	read volsize_bulkvolumecreate
	echo ""
	echo "Protection Domain List"
	scli --mdm_ip $glob --query_properties --object_type PROTECTION_DOMAIN --all_objects --properties NAME |grep "NAME" |awk '{print $2}'
	echo ""
	echo -n "Protection Domain? "
	read domain_bulkvolumecreate
	scli --mdm_ip $glob --query_properties --object_type STORAGE_POOL --properties UNUSED_CAPACITY_IN_KB,NAME  --all_objects
	echo -n "Pool to create volumes: "
	read pool_bulkvolumecreate
		END=$((startvol_bulkvolumecreate + volcount-1))
		array=($volname_bulkvolumecreate)
	for ((i=$startvol_bulkvolumecreate;i<=END; i++)); do
	scli --mdm_ip $glob --add_volume --volume_name $volname_bulkvolumecreate$i --$prov_type_bulkvolumecreate --protection_domain_name $domain_bulkvolumecreate --storage_pool_name $pool_bulkvolumecreate --size_gb $volsize_bulkvolumecreate
	done 
	echo -n "Would you like to create another batch of volumes (y or n)? "
	read yesorno_bulkvolumecreate
done	
}
#
function removebyvolumename()
{
answer_removebyvolumename="y"
yesorno_removebyvolumename="y"
while [ "$answer_removebyvolumename" == "$yesorno_removebyvolumename" ];
do
	echo "Displaying Unmapped Volumes:"
	echo ""
	scli --mdm_ip $glob --query_all_volumes
	echo ""
	echo -n "Volume Name to Remove: "
	read vname_removebyvolumename
	scli --mdm_ip $glob --remove_volume --volume_name $vname_removebyvolumename --i_am_sure
	echo -n "Would you like to remove another volume by name (y or n)? "
	read yesorno_removebyvolumename
done
}
#function to remove volumes by ID
function removebyvolumeid()
{
answer_removebyvolumeid="y"
yesorno_removebyvolumeid="y"
while [ "$answer_removebyvolumeid" == "$yesorno_removebyvolumeid" ];
do
	echo "Displaying Unmapped Volumes:"
	echo ""
	scli --mdm_ip $glob --query_all_volumes
	echo -n "Volume ID to Remove: "
	read vname_removebyvolumeid
	scli --mdm_ip $glob --remove_volume --volume_id $vname_removebyvolumeid --i_am_sure
	echo -n "Would you like to create another batch of volumes (y or n)? "
	read yesorno_removebyvolumeid
done
}

function removemenu()
{
 option=0
 until [ "$option" = "3" ]; do
 echo "How would you like to remove volumes - by name or object ID"
 echo "  1.) Remove by Volume Name"
 echo "  2.) Remove by Volume Object ID"
 echo "  3.) Back to Volumes Menu"
 echo ""
 echo -n "Enter choice: "
 read option
 echo ""
 case $option in
 1 ) removebyvolumename;;
 2 ) removebyvolumeid;;
 3 ) volmenu;;
 * ) echo "Please enter 1,2, or 3"; 
 esac
 done
 }
# function to unmap a single volume
function volumeunmap()
{
echo ""
echo "Unmap select volumes from an SDC"
echo ""
echo ""
echo "Current SDC's"
scli --mdm_ip $glob --query_all_sdc |grep "Connected GUID" |awk '{print $5}'
echo -n "Enter SDC Name: "
read sdcname
answer="y"
yesno="y"
while [ "$answer" == "$yesno" ];
do
        echo "Displaying Volumes on SDC:"
        scli --mdm_ip $glob --query_sdc --sdc_name $sdcname |grep "Volume ID"
        echo -n "What Volume to Unmap from " $sdcname " (use vol name): "
        read volremove
        echo "Umapping " $volremove
        scli --mdm_ip $glob --unmap_volume_from_sdc --volume_name $volremove --sdc_name $sdcname --i_am_sure
        echo "Remove another volume from" $sdcname " ? (y or n)"
        read yesno
done
}
#
function removebyvolumename()
{
answer_removebyvolumename="y"
yesorno_removebyvolumename="y"
while [ "$answer_removebyvolumename" == "$yesorno_removebyvolumename" ];
do
	echo "Displaying Unmapped Volumes:"
	echo ""
	scli --mdm_ip $glob --query_all_volumes |grep -E 'vol.*Unmapped' |awk '{print}'
	echo -n "Volume Name to Remove: "
	read vname_removebyvolumename
	scli --mdm_ip $glob --remove_volume --volume_name $vname_removebyvolumename --i_am_sure
	echo -n "Would you like to remove another volume by name (y or n)? "
	read yesorno_removebyvolumename
done
}
#function to remove volumes by ID
function removebyvolumeid()
{
answer_removebyvolumeid="y"
yesorno_removebyvolumeid="y"
while [ "$answer_removebyvolumeid" == "$yesorno_removebyvolumeid" ];
do
	echo "Displaying Unmapped Volumes:"
	echo ""
	scli --mdm_ip $glob --query_all_volumes |grep -E 'vol.*Unmapped' |awk '{print}'
	echo -n "Volume ID to Remove: "
	read vname_removebyvolumeid
	scli --mdm_ip $glob --remove_volume --volume_id $vname_removebyvolumeid --i_am_sure
	echo -n "Would you like to create another batch of volumes (y or n)? "
	read yesorno_removebyvolumeid
done
}

function removemenu()
{
 option=0
 until [ "$option" = "3" ]; do
 echo "How would you like to remove volumes - by name or object ID"
 echo "  1.) Remove by Volume Name"
 echo "  2.) Remove by Volume Object ID"
 echo "  3.) Back to Volumes Menu"
 echo ""
 echo -n "Enter choice: "
 read option
 echo ""
 case $option in
 1 ) removebyvolumename;;
 2 ) removebyvolumeid;;
 3 ) volmenu;;
 * ) echo "Please enter 1 or 2";
 esac
#   }
 done
 #
} 
 
#function to unmap all volumes froms an SDC
function volumeunmapallsdc()
{
echo "Current SDC's"
scli --mdm_ip $glob --query_all_sdc |grep "Connected GUID" |awk '{print $5}'
echo -n "Enter SDC name: " 
read sdcname
echo "Displaying Volumes on SDC:"
scli --mdm_ip $glob --query_sdc --sdc_name $sdcname |grep "Volume ID"
echo ""
echo -n "Are you sure you want to unmap all volumes from "$sdcname " (y or n) ?"
read unmap_all_yn
echo ""
if [ $unmap_all_yn == y ]; then
for x in $(scli --mdm_ip $glob --query_sdc --sdc_name $sdcname |grep "Volume ID" | awk '{print $6}')
do
echo ""
scli --mdm_ip $glob --unmap_volume_from_sdc --volume_name $x --sdc_name $sdcname --i_am_sure
done
else
echo""
volmenu
fi
}

#function to map a volume to an sdc
function mapvolume()
{
answer="y"
yes_o_no="y"
while [ "$answer" == "$yes_o_no" ];
do
	echo "Approved SDC's"
	echo ""
	scli --mdm_ip $glob --query_all_sdc |grep "Name:" |awk '{print $4,$5,$6,$7}'
	echo ""
	echo -n "Enter SDC Name: "
	read sdcname
	echo ""
	echo -n "Add a keyword to search for a volume ex. vol (leave blank to view all): "
	read search
	echo ""
	echo "Current Volumes"
	echo ""
	scli --mdm_ip $glob --query_all_volumes |grep "Name" |grep "$search" |grep "Size"
	echo ""
	echo -n "Volume name to map: "
	read vv
	echo -n "Is this volume mapped to another SDC - multi map (y or n)? "
	read multi_map
	if [ "$multi_map" == "y" ]; then
	scli --mdm_ip $glob --map_volume_to_sdc --volume_name $vv --sdc_name $sdcname --allow_multi_map
	else
	scli --mdm_ip $glob --map_volume_to_sdc --volume_name $vv --sdc_name $sdcname
	fi
	echo -n "Would you like to map another volume? (y or n)? "
	read yes_o_no
done	
}

#function to expand a volume
function increasevolumesize()
{
answer_increasevolumesize="y"
yesorno_increasevolumesize="y"
while [ "$answer_increasevolumesize" == "$yesorno_increasevolumesize" ];
do
	echo "Displaying Volumes:"
	scli --mdm_ip $glob --query_all_volumes
	echo -n "Enter Volume to Expand "
	read volume_expand
	echo -n "Desired Size of volume in GB (8, 16, 24, etc) "
	read newsize
	scli --mdm_ip $glob --modify_volume_capacity --volume_name $volume_expand --size_gb $newsize
	echo -n "Would you like to modify another volume? (y or n) "
	read yesorno_increasevolumesize
done	
}

#menu functions and loops
function sdsmenu()
{
 option=0
 until [ "$option" = "6" ]; do
 echo ""
 echo "SDS Menu"
 echo "  1.) Add SDS"
 echo "  2.) Remove SDS"
 echo "  3.) Add SDS Device"
 echo "  4.) Remove SDS Device"
 echo "  5.) Return to Main Menu"
 echo ""
 echo -n "Enter choice: "
 read option
 echo ""
 case $option in
 1 ) sdsadd;;
 2 ) sdsrem;;
 3 ) addsdsdev;;
 4 ) remsdsdev;;
 5 ) main_menu;;
 * ) echo "Please enter 1, 2, 3, 4 or 5"; 
 esac
#   }
 done
}
#
function querymenu()
{
 option=0
 until [ "$option" = "4" ]; do
 echo ""
 echo "System Query Menu"
 echo "  1.) Query All System Objects"
 echo "  2.) Query Connected SDCs"
 echo "  3.) Query All Volumes"
 echo "  4.) Return to Main Menu"
 echo ""
 echo -n "Enter choice: "
 read option
 echo ""
 case $option in
 1 ) query_sys_objects;;
 2 ) sdc_queries;;
 3 ) query_all_volumes;;
 4 ) main_menu;;
 * ) echo "Please enter 1, 2, 3, or 4";; 
 esac
 done
}

function sdcmenu()
{
 option=0
 until [ "$option" = "3" ]; do
 echo "SDC Menu"
 echo "  1.) Add SDC"
 echo "  2.) Rename SDC"
 echo "  3.) Return to Main Menu"
 echo ""
 echo -n "Enter choice: "
 read option
 echo ""
 case $option in
 1 ) addsdc;;
 2 ) renamesdc;;
 3 ) main_menu;;
 * ) echo "Please enter 1, 2 or 3";
 esac
#   }
 done
}

function volmenu()
{
 option=0
 until [ "$option" = "9" ]; do
 echo ""
 echo "Volume Menu"
 echo "  1.) Show Volume to SDC Mapping"
 echo "  2.) Create Single Volume"
 echo "  3.) Create Bulk Volumes (same size, type, pool/PD - uses a number iterator)"
 echo "  4.) Remove Volumes"
 echo "  5.) Map Volumes to an Single SDC"
 echo "  6.) Unmap Individual Volumes from an SDC"
 echo "  7.) Unmap all volumes from an SDC"
 echo "  8.) Increase the size of a volume"
 echo "  9.) Main Menu"
 echo ""
 echo -n "Enter choice: "
 read option
 echo ""
 case $option in
 1 ) query_volume_to_sdc;;
 2 ) volumecreate;;
 3 ) bulkvolumecreate;;
 4 ) removemenu;;
 5 ) mapvolume;;
 6 ) volumeunmap;;
 7 ) volumeunmapallsdc;;
 8 ) increasevolumesize;;
 9 ) main_menu;;
 * ) echo "Please enter 1-9"; 
 esac
 done
}

function main_menu() 
{
option=0
until [ "$option" = "6" ]; do
echo ""
echo ""
echo "       ScaleIO Main Menu         "
echo "---------------------------------"
clustername=$(scli --mdm_ip $glob --query_properties --object_type SYSTEM --all_objects --properties NAME |grep "NAME" |awk '{print $2}')
echo "Cluster Name: " $clustername 
echo "MDM IPs: "$glob
total_capacity=$(scli --mdm_ip $glob --query_properties --object_type SYSTEM --all_objects --properties MAX_CAPACITY_IN_KB |grep "MAX_CAPACITY_IN_KB" |awk '{print $2,$3,$4,$5,$6}')
avail_capacity=$(scli --mdm_ip $glob --query_properties --object_type SYSTEM --all_objects --properties UNUSED_CAPACITY_IN_KB |grep "UNUSED_CAPACITY_IN_KB" |awk '{print $2,$3,$4,$5,$6}')
cap_in_use=$(scli --mdm_ip $glob --query_properties --object_type SYSTEM --all_objects --properties CAPACITY_IN_USE_IN_KB |grep "CAPACITY_IN_USE_IN_KB" |awk '{print $2,$3,$4,$5,$6}')
spare_capacity=$(scli --mdm_ip $glob --query_properties --object_type SYSTEM --all_objects --properties SPARE_CAPACITY_IN_KB |grep "SPARE_CAPACITY_IN_KB" |awk '{print $2,$3,$4,$5,$6}')
echo "Total System Capacity(Raw): " $total_capacity
echo "Spare Capacity (RAW): " $spare_capacity
echo "Available Capacity (Raw): " $avail_capacity
rebal_capacity=$(scli --mdm_ip $glob --query_properties --object_type SYSTEM --all_objects --properties REBALANCE_CAPACITY_IN_KB |grep "REBALANCE_CAPACITY_IN_KB" |awk '{print $2,$3,$4,$5,$6}')
brb_capacity=$(scli --mdm_ip $glob --query_properties --object_type SYSTEM --all_objects --properties BCK_REBUILD_CAPACITY_IN_KB |grep "BCK_REBUILD_CAPACITY_IN_KB" |awk '{print $2,$3,$4,$5,$6}')
frb_capacity=$(scli --mdm_ip $glob --query_properties --object_type SYSTEM --all_objects --properties FWD_REBUILD_CAPACITY_IN_KB |grep "FWD_REBUILD_CAPACITY_IN_KB" |awk '{print $2,$3,$4,$5,$6}')
echo "Rebalance Capacity (Raw): " $rebal_capacity 
echo "Rebuild Capacity (Raw)-> Backwards / Forward: "$brb_capacity "/" $frb_capacity
echo ""
echo "  1.) Login"
echo "  2.) Query System Menu"
echo "  3.) SDS Menu"
echo "  4.) SDC Menu"
echo "  5.) Create, Map, and Remove Volumes Menu"
echo "  6.) Quit"
echo ""
echo -n "Enter choice: "
read option
echo ""
case $option in
    1 ) login ;;
    2 ) querymenu ;;
    3 ) sdsmenu ;;
	4 ) sdcmenu ;;
	5 ) volmenu ;;
    6 ) exit;;
    * ) echo "Please enter 1, 2, 3, 4, or 5"; 
esac
done
}

main_menu
