#!/bin/tcsh
# Name: findsrvs
# This script is called by manage script. It called slptool to query the target
# service and then use the functions in parse.c to parse the returned string 
# from slptool to get the target url, port, and target name.
# 
set SVR=(`slptool "findsrvs" "service:iscsi:target"`)
#set SVR=(`slptool "findsrvs" "service:iscsi:target" "(alias=jaguar)"`)
#set SVR=(`slptool findsrvs service:iscsi:target "(iscsi-name=tweety)"`)

#use more than one property as filter to query
#set SVR=(`slptool findsrvs service:iscsi:target "(alias=jaguar)" "(auth-addr=132.177.117.67)"`)

#use one item of the property list as filter to query
#set SVR=(`slptool findsrvs service:iscsi:target "(auth-name=iqn.edu.unh.initiator.tweety)"`)

#set SVR=(`slptool findsrvs service:iscsi:target "(auth-name=iqn.edu.unh.initiator.jaguar)"`)
#set SVR=(`slptool findsrvs service:iscsi:target "(auth-addr=132.177.117.67)"`)
#set SVR=(`slptool findsrvs service:iscsi:target "(auth-cred=chap/foo)"`)
#set SVR=(`slptool findsrvs service:iscsi:target "(auth-name=any)"`)

#use more than values for one attribute to query
#set SVR=(`slptool findsrvs service:iscsi:target "(tryany=any)" "(tryany=other)"`)


if ( $#SVR != 0 ) then
	echo "All available iSCCSI taregets discovered by  SLP are:"
	set num=1
	while ($num <= $#SVR)
		echo "("$num") " $SVR[$num]
		@ num += 1
		#echo "It has attributes:"
		#set attr=(`slptool findattrs ...`)
		#print the attributes here 
	end
	echo ""
	echo "Please choose the iSCSI server" 
	set choice = "$<"
	echo "the choice is:  $SVR[$choice]"
	set ip = `./parse -h $SVR[$choice]`
	set port = `./parse -p $SVR[$choice]`
	set tn = `./parse -n $SVR[$choice]`
	
else
echo "No iSCSI target found!"
exit 1
endif
