Hi,

Sorry for the delay and thanks for the reminder.

On Mon, Mar 08, 2010 at 08:25:05AM +0100, Helmut Weymann wrote:
> Hi,
> 
> Am Freitag, 26. Februar 2010 schrieb Dejan Muhamedagic:
> > On Fri, Feb 26, 2010 at 11:54:41AM +0100, Dejan Muhamedagic wrote:
> > > Hi,
> > >
> > > On Fri, Feb 26, 2010 at 01:23:17AM +0100, Helmut Weymann wrote:
> >
> > [...]
> >
> > > Well, if that's the only way, let's have it like that. Perhaps
> > > also to allow for a host-port map file, which would be preferable
> > > if for instance ports 7 and 8 are used. Though that file could be
> > > a maintenance issue, with csync2 or rsync it could be kept in
> > > good shape.
> > >
> > > The parameter hostlist should be renamed to port_map or similar.
> >
> > Actually not, hostlist is better.
> >
> > A few more suggestions:
> >
> > - you could allow for "empty" slots other values apart from NULL
> >   (say "N" or "X")
> >
> Managed to get a list from the device via the web-interface.

Great!

> Nevertheless I still allow to define the parameter hostlist.

Probably not a bad idea, in case the device is used to manage
more than just this cluster.

> Names used in that list are only used if CRM requests to kill a cluster-node. 
> (thats my guess.)  So any name should be allowed. Only the names of cluster 
> nodes should make a difference.

It would make sense to also check if the names in the given
hostlist are available for management at the device.

> Please review the attached submission. It includes:
> - external/ippower9258 (the plugin in bin folder)
> - README.ippower9258 in doc folder.
> 
> As an addon I have included in folder doc/example the relevant html-files the 
> device creates.

Thanks, that was helpful.

> I have marked a few lines of the plugin with the comment "please review".
> These are about loglevels supported by ha_log.sh, pathnames below 
> /var/run/heartbeat/rsctmp and a piece of code between the lines 233 to 263.
> 
> Please feel free to make any adjustments. I'll run the necessary tests.

You'll find a patch attached. It contains the following changes:

- different build_hostlist procedure based on output of w3m -dump
- exit on error in get_*_from_device
- a few other minor changes

BTW, if you could leave out most of {} around variable
references, that'd make my eyes less wobble.

Cheers,

Dejan

> > - take out the documentation part (comments at the top of the
> >   file) and put it in a separate README file (README.ippower9258)
> Done
> >
> > - please make the indentation consistent, sometimes there are
> >   spaces, sometime tabs
> Done.
> >
> > Cheers,
> >
> > Dejan
> Regards,
> 
> Helmut
> 
> 
> 


> _______________________________________________
> Linux-HA mailing list
> [email protected]
> http://lists.linux-ha.org/mailman/listinfo/linux-ha
> See also: http://linux-ha.org/ReportingProblems

diff -ur IPower9258/bin/ippower9258 IPower9258.new/bin/ippower9258
--- IPower9258/bin/ippower9258	2010-02-28 13:17:51.000000000 +0100
+++ IPower9258.new/bin/ippower9258	2010-03-08 16:39:29.000000000 +0100
@@ -36,8 +36,9 @@
 IPPort0=60
 HTTP_COMMAND="wget -q -O - --"
 LOG_ERROR="ha_log.sh err"
-LOG_WARNING="ha_log.sh WARNING" #                                                 please review
-LOG_INFO="ha_log.sh message" #                                                    please review
+LOG_WARNING="ha_log.sh warn"
+LOG_INFO="ha_log.sh info"
+LOG_DEBUG="ha_log.sh debug"
 MY_COOKIES="cookies.txt"
 MY_TEMPFILE="temp.htm"
 DEVICE_SETTINGS="system.htm"
@@ -47,7 +48,9 @@
 #
 # check MY_ROOT_PATH for IP Power 9258 and create it if necessary
 #
-MY_ROOT_PATH="/var/run/heartbeat/rsctmp/ippower9258" #                             please review
+# in final version:
+# MY_ROOT_PATH="@GLUE_STATE_DIR@/heartbeat/rsctmp/ippower9258"
+MY_ROOT_PATH="/var/run/heartbeat/rsctmp/ippower9258"
 test -d $MY_ROOT_PATH || { mkdir $MY_ROOT_PATH; }
 
 #
@@ -68,12 +71,12 @@
 	response=`echo -n "${username}${password}${challenge}" | md5sum | cut -b -32`
 	postdata="Username=${username}&Password=&Challenge=&Response=${response}&ScreenWidth=1024"
 	send_web_command " ${MY_PATH}/${MY_TEMPFILE} --post-data=${postdata}" "http://${deviceip}/tgi/login.tgi";
-    ret=`cat ${MY_PATH}/${MY_TEMPFILE} | grep "Invalid User name or Password"`
-	if [ "X${ret}" != "X" ]
+	if grep -qs "Invalid User name or Password" ${MY_PATH}/${MY_TEMPFILE}
 	then
-		$LOG_WARNING "Login to device ${deviceip} failed."
-		$LOG_WARNING "Received Challenge = <<<$challenge>>>."
-		$LOG_WARNING "Sent postdata = <<<$postdata>>>."
+		$LOG_ERROR "Login to device ${deviceip} failed."
+		$LOG_ERROR "Received Challenge = <<<$challenge>>>."
+		$LOG_ERROR "Sent postdata = <<<$postdata>>>."
+		exit 1
 	fi
 }
 
@@ -82,17 +85,18 @@
 	rm -f "${MY_PATH}/${PORT_STATUS}"
 	rm -f "${MY_PATH}/${DEVICE_SETTINGS}"
 	send_web_command "${MY_PATH}/${PORT_STATUS}" "http://${deviceip}/${PORT_STATUS}";
-    ret=`cat ${MY_PATH}/${PORT_STATUS} | grep "Cookie Time Out"`
-	if [ "X${ret}" != "X" ]
+	if grep -qs "Cookie Time Out" ${MY_PATH}/${PORT_STATUS}
 	then
-		$LOG_WARNING "Got no port data from ${deviceip}. Reveived: Cookie Time Out"
+		$LOG_ERROR "received no port data from ${deviceip} (Cookie Time Out)"
+		exit 1
 	fi
 	send_web_command "${MY_PATH}/${DEVICE_SETTINGS}" "http://${deviceip}/${DEVICE_SETTINGS}";
-	if [ "X${ret}" != "X" ]
+	# Is this supposed to be the same ret? New grep command?
+	if grep -qs "Cookie Time Out" ${MY_PATH}/${DEVICE_SETTINGS}
 	then
-		$LOG_WARNING "Got no device info from ${deviceip}. Reveived: Cookie Time Out"
+		$LOG_ERROR "received no device info from ${deviceip} (Cookie Time Out)"
+		exit 1
 	fi
-
 }
 
 send_http_request() {
@@ -110,12 +114,13 @@
 
 resolve_name_to_port() {
 #
-	i=`expr $IPPort0`
+	i=$IPPort0
 	port="invalid"
 	for h in $hostlist ; do
 		if [ $h = ${1} ]
 		then
-			port="$IPPort_name"$i
+			port=$IPPort_name$i
+			break
 		fi
 		i=`expr $i + 1`
 	done
@@ -146,23 +151,24 @@
 	# 
 	# hostnames are available from http://${deviceip}/iocontrol.htm";
 	# check for number of ports
-	ret=`cat ${MY_PATH}/${PORT_STATUS} | grep '<!--'`
-	if [ "X${ret}" = "X" ]
-	then
-		portlist="pw1Name pw2Name pw3Name pw4Name pw5Name pw6Name pw7Name pw8Name"
-	else # html-code for the ports 5 to 8 is a html-comment
-		portlist="pw1Name pw2Name pw3Name pw4Name"
-	fi
-	hostlist=""
-	for h in $portlist ; do
-		ret=`cat ${MY_PATH}/${PORT_STATUS} | grep $h | cut -f 4 -d '"'`
-		if [ "X${ret}" = "X" ]
-		then
-			ret=$UNDEFINED_HOSTNAME
-		fi
-		hostlist="${hostlist} ${ret}"
+	#
+	#DM# This is a very weak way to calculate the number of available ports.
+	# perhaps to make use of w3m -dump:
+	# w3m -dump iocontrol.htm  | grep 'Power[1-8]'
+	# │Power1│[adam            ]│(*) On ( ) Off│[0    ] Sec (*) On ( ) Off│
+	# │Power2│[test            ]│( ) On (*) Off│[0    ] Sec ( ) On (*) Off│
+	# │Power3│[                ]│(*) On ( ) Off│[0    ] Sec (*) On ( ) Off│
+	# │Power4│[eva             ]│(*) On ( ) Off│[0    ] Sec (*) On ( ) Off│
+	hostlist=$(
+	w3m -dump ${MY_PATH}/${PORT_STATUS} | grep 'Power[1-8]' |
+	sed 's/[^[]*\[//;s/\].*//;s/ *//' |
+	while read h; do
+		[ -z "$h" ] &&
+			echo $UNDEFINED_HOSTNAME ||
+			echo $h
 	done
-	$LOG_INFO "Got new hostlist ($hostlist) from $deviceip"
+	)
+	$LOG_DEBUG "Got new hostlist ($hostlist) from $deviceip"
 }
 
 prepare_hostlist() {
@@ -177,19 +183,15 @@
 	fi
 	if [ "X${hostlist}" = "X" ]
 	then
-		$LOG_ERROR "Cant get hostlist for $deviceip."
+		$LOG_ERROR "cannot get hostlist for $deviceip"
 		exit 1
 	fi
 }
 
 print_hosts() {
 	for h in $hostlist ; do
-		if [ $h = $UNDEFINED_HOSTNAME ]
-		then
-			echo ""
-		else
+		[ $h != $UNDEFINED_HOSTNAME ] &&
 			echo $h
-		fi
 	done
 }
 
@@ -203,11 +205,6 @@
 	fi
 }
 
-get_device_name() {
-	ret=`cat $MY_PATH/$DEVICE_SETTINGS | grep sender | cut -d '"' -f 4`;
-	echo $ret
-}
-
 # define commands and parameters for the individual device and get device information
 case ${1} in
 gethosts|on|off|reset|status) #stonith always calls status first
@@ -228,39 +225,11 @@
 	# In this case the unique device name must be available from http://${deviceip}/system.htm
 	# in order to get that information we need to login first.
 	#
-	if [ "X${devicename}" = "X" ] #                                                         please review
-	then
-		tmp_path=`echo $deviceip | md5sum | cut -b -32` # ensure a simple unique pathname
-		MY_PATH="${MY_ROOT_PATH}/${tmp_path}"
-		test -d $MY_PATH || { mkdir $MY_PATH;  }
-		get_cookie_from_device; 
-		get_data_from_device;
-		ret=`get_device_name`;
-		if [ "X${ret}" = "X" ]
-		then
-			$LOG_INFO "devicename is undefined."
-		else
-			devicename=$ret
-			$LOG_INFO "Got new devicename $devicename from $deviceip"
-		fi
-		# (re-)link new devicename to tmp_path; devicename might exist with wrong data      please review
-		if [ "X${devicename}" != "X${tmp_path}" ]
-		then
-			cur_path=`pwd`
-			cd ${MY_ROOT_PATH}
-			test -e $devicename || { rm -f $devicename;  }
-			test -d $devicename || { rm -fr $devicename;  }
-			ln -s  ${tmp_path} ${devicename}
-			test -e ${tmp_path}/${tmp_path} || { rm -f ${tmp_path}/${tmp_path}; }
-			cd $cur_path
-			MY_PATH="${MY_ROOT_PATH}/${devicename}"
-		fi
-	else
-		MY_PATH="${MY_ROOT_PATH}/${devicename}"
-		test -d $MY_PATH || { mkdir $MY_PATH;  }
-		get_cookie_from_device; 
-		get_data_from_device;
-	fi
+	tmp_path="$deviceip" # ensure a simple unique pathname
+	MY_PATH="${MY_ROOT_PATH}/${tmp_path}"
+	test -d $MY_PATH || { mkdir $MY_PATH;  }
+	get_cookie_from_device
+	get_data_from_device
 	prepare_hostlist
 	;;
 *)
@@ -290,7 +259,6 @@
 	set_port ${host} $IPPowerOff
 	sleep 5
 	set_port ${host} $IPPowerOn
-	
 	exit 0
 	;;
 status)
@@ -300,7 +268,7 @@
 	;;
 getconfignames)
 	# return all the config names
-	for ipparam in deviceip password devicename hostlist username
+	for ipparam in deviceip username password hostlist
 	do
 		echo ${ipparam}
 	done;
@@ -315,7 +283,8 @@
 	exit 0
 	;;
 getinfo-devdescr)
-	echo -e "Power switch IP Power 9258 with 4 or 8 power outlets. \nWARNING: It is different from IP Power 9258 HP"
+	echo "Power switch IP Power 9258 with 4 or 8 power outlets."
+	echo "WARNING: It is different from IP Power 9258 HP"
 	exit 0
 	;;
 getinfo-devurl)
@@ -335,7 +304,7 @@
 </longdesc>
 </parameter>
 
-<parameter name="password" unique="1" required="1">
+<parameter name="password" unique="0" required="1">
 <content type="string" />
 <shortdesc lang="en">
 Password
@@ -345,18 +314,6 @@
 </longdesc>
 </parameter>
 
-<parameter name="devicename" unique="1" required="0">
-<content type="string" />
-<shortdesc lang="en">
-Unique name of the device
-</shortdesc>
-<longdesc lang="en">
-Define a unique name for the device.
-If you leave this field empty, we try to get the name from the device.
-Worst case we will use deviceip to generate a devicename.
-</longdesc>
-</parameter>
-
 <parameter name="hostlist" unique="1" required="0">
 <content type="string" />
 <shortdesc lang="en">
@@ -370,13 +327,13 @@
 </longdesc>
 </parameter>
 
-<parameter name="username" unique="1" required="0">
-<content type="string" />
+<parameter name="username" unique="0" required="0">
+<content type="string" default="admin"/>
 <shortdesc lang="en">
 Account Name
 </shortdesc>
 <longdesc lang="en">
-The user to log in with. Default username is admin.
+The user to log in with.
 </longdesc>
 </parameter>
 
_______________________________________________
Linux-HA mailing list
[email protected]
http://lists.linux-ha.org/mailman/listinfo/linux-ha
See also: http://linux-ha.org/ReportingProblems

Reply via email to