Fixed up riloe.in and patch (see attached files)

Anyone with python knowledge, feel free to improve.

Sure hope this works on older iLO versions, since I could only test it
on recent ones.



On 2/12/07, Tijl Van den Broeck <[EMAIL PROTECTED]> wrote:
Also sorry for delay as well :-) Family emergency last few weeks.

Ehm.. well the documentation and examples from HP about communication
to the iLO is all in perl.
And let's say that my python is possibly worse than perl :-) Apart
from that I'm willing to try and convert it to python. As I've noticed
something else, using perl implies that you need openssl modules
installed for perl so python would be a more user friendly option.

Attachment: riloe.in
Description: Binary data

--- riloe.in	2006-12-27 15:44:43.000000000 +0100
+++ riloe.in	2007-02-12 15:26:16.000000000 +0100
@@ -5,6 +5,8 @@
 # Copyright (c) 2004 Alain St-Denis <[EMAIL PROTECTED]>
 #
 # Modified by Alan Robertson <[EMAIL PROTECTED]> for STONITH external compatibility.
+# Extended and merged by Tijl Van den broeck <[EMAIL PROTECTED]>
+#  with ilo-v2 script from Guy Coates
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -29,9 +31,15 @@
 
 argv = sys.argv
 
-#   If device name is not set,	We assume the device name for node 
-#   X.foo.bar.com is X-rm and is accessible as a local (non-FQDN) 
-#   DNS name.
+# Environment variables
+# REALHOST (host that we are responsible for)
+# ILOHOST (hostname of the ilo)
+# ILOUSER (username for ilo login)
+# ILOPASS (password for the ilo)
+# CAN_RESET (does the ILO in question support RESET commands)
+# POWERDOWN_METHOD (also version dependant, atm possible options: 1 or 2)
+
+
 try:
         cmd = argv[1]
 except IndexError:
@@ -39,29 +47,26 @@
         sys.exit(1)
 
 try:
-        password = os.environ['RI_PASSWORD']
-        os.environ['RI_PASSWORD'] = "********"
+        ilohost = os.environ['ILOHOST']
+        ilouser = os.environ['ILOUSER']
+        ilopass = os.environ['ILOPASS']
+        realhost = os.environ['REALHOST']
+        reset_ok = os.environ['CAN_RESET']
+        power_method = os.environ['POWERDOWN_METHOD']
+        #	Some old RILOE devices don't support the reset command
+        #	This variable is 1 if it does.
+        if reset_ok == '':
+          reset_ok = None
         anypass=1
 except KeyError:
-        password = ""
+        ilopass = ""
         anypass=0
 
-loginname = os.environ.get('RO_LOGIN', "Administrator")		
-rihost = os.environ.get('RI_HOSTRI', "")
-host = os.environ.get('RI_HOST', "<unconfigured>")
-if rihost == "" and host != "<unconfigured>":
-        rihost = host.split('.')[0]+'-rm'
-
-#	Some old RILOE devices don't support the reset command
-#	This variable is 1 if it does.
-try:
-        reset_ok = os.environ["RI_CAN_RESET"]
-        if reset_ok == '':
-                reset_ok = None
-except KeyError:
-        reset_ok = None
-login = [ '<RIBCL VERSION="1.2">',
-          '<LOGIN USER_LOGIN="' + loginname + '" PASSWORD="' + password + '">' ]
+login = [ '<RIBCL VERSION="2.0">',
+          '<LOGIN USER_LOGIN="'
+    + ilouser + 
+    '" PASSWORD="'
+	  + ilopass + '">' ]
 
 
 logout = [ '</LOGIN>', '</RIBCL>' ]
@@ -71,11 +76,15 @@
            '</SERVER_INFO>' ]
 
 
+
 reset = [ '<SERVER_INFO MODE="write">', '<RESET_SERVER/>', '</SERVER_INFO>' ]
 
 
-off = [ '<SERVER_INFO MODE = "write">', '<SET_HOST_POWER HOST_POWER  = "N"/>',
+if power_method == '1':
+  off = [ '<SERVER_INFO MODE = "write">', '<SET_HOST_POWER HOST_POWER  = "N"/>',
           '</SERVER_INFO>' ]
+elif power_method == '2':
+  off = [ '<SERVER_INFO MODE="write">', '<HOLD_PWR_BTN/>', '</SERVER_INFO>' ]
 
 
 on = [ '<SERVER_INFO MODE = "write">', '<SET_HOST_POWER HOST_POWER  = "Y"/>',
@@ -85,50 +94,58 @@
 todo = { 'reset':reset, 'on':on, 'off':off, 'status':status }
 
 xmlinfo = '''<parameters>
-<parameter name="RI_HOST" unique="1">
-<content type="string" />
-<shortdesc lang="en">
-Host
-</shortdesc>
-<longdesc lang="en">
-The host that the STONITH device controls
-</longdesc>
-</parameter>
-<parameter name="RI_HOSTRI" unique="1">
-<content type="string" />
-<shortdesc lang="en">
-Host riLo device
-</shortdesc>
-<longdesc lang="en">
-The address of the STONITH device 
-</longdesc>
-</parameter>
-<parameter name="RI_LOGIN" unique="1">
-<content type="string" />
-<shortdesc lang="en">
-Login accout
-</shortdesc>
-<longdesc lang="en">
-The login accout for control the STONITH device
-</longdesc>
-</parameter>
-<parameter name="RI_PASSWORD" unique="1">
-<content type="string" />
-<shortdesc lang="en">
-Login password
-</shortdesc>
-<longdesc lang="en">
-The password for login into the STONITH device
-</longdesc>
-</parameter>
+ <parameter name="REALHOST" unique=1>
+  <content type="string"/>
+  <shortdesc lang="en">hostname</shortdesc>
+  <longdesc lang=en>
+   The hostname that the ilo controls
+  </longdesc>
+ </parameter>
+<parameter name="ILOHOST" unique=1>
+  <content type="string"/>
+  <shortdesc lang="en">ilohostname</shortdesc>
+  <longdesc lang=en>
+   The hostname of the ilo device
+  </longdesc>
+ </parameter>
+<parameter name="ILOUSER" unique=1>
+  <content type="string"/>
+  <shortdesc lang="en">ilousername</shortdesc>
+  <longdesc lang=en>
+   The user for connecting to the ilo device
+  </longdesc>
+ </parameter>
+<parameter name="ILOPASS" unique=1>
+  <content type="string"/>
+  <shortdesc lang="en">password</shortdesc>
+  <longdesc lang=en>
+   The password for the ilo device user
+  </longdesc>
+ </parameter>
+</parameters>
+<parameter name="CAN_RESET" unique=1>
+  <content type="string"/>
+  <shortdesc lang="en">can_reset</shortdesc>
+  <longdesc lang=en>
+   Can the ilo issue resets (hint: older ones cannot)
+  </longdesc>
+ </parameter>
+</parameters>
+<parameter name="POWERDOWN_METHOD" unique=1>
+  <content type="string"/>
+  <shortdesc lang="en">powerdown_method</shortdesc>
+  <longdesc lang=en>
+   The method to powerdown the host in question (use 1 or 2)
+  </longdesc>
+ </parameter>
 </parameters>'''
 
 info = {
         'getinfo-devid':	'RILOE',
-        'getinfo-devname':	'riloe ' + rihost,
+        'getinfo-devname':	'riloe ' + ilohost,
         'getinfo-devdescr':	'COMPAQ RILOE STONITH device',
         'getinfo-devurl':	'http://www.hp.com/',
-        'gethosts':			host,
+	      'gethosts':	 realhost,
         'getinfo-xml':		xmlinfo
 }
 
@@ -139,7 +156,7 @@
         None
 
 if cmd == 'getconfignames':
-        for arg in ['RI_HOST', 'RI_HOSTRI', 'RI_LOGIN', 'RI_PASSWORD']:
+        for arg in ['ILOUSER', 'ILOPASS', 'ILOHOST', 'REALHOST', 'CAN_RESET', 'POWERDOWN_METHOD']:
             print arg
         sys.exit(0)
 
@@ -147,11 +164,11 @@
 #	All remaining commands need host and password to succeed...
 #
 
-if host == '<unconfigured>':
-        print "Missing 'RI_HOST' environment variable"
+if ilohost == '<unconfigured>':
+        print "Missing 'ILOHOST' environment variable"
         sys.exit(1)
 if not anypass:
-        print "Missing 'RI_PASSWORD' environment variable"
+        print "Missing 'ILOPASS' environment variable"
         sys.exit(1)
 
 acmds=[]
@@ -171,7 +188,7 @@
 try:
         for cmds in acmds:
 
-                c=HTTPSConnection(rihost)
+                c=HTTPSConnection(ilohost)
                 c.send('<?xml version="1.0"?>\r\n')
                 c.sock.recv(1024)
 
@@ -180,17 +197,16 @@
                         c.send(line+'\r\n')
                         c.sock.recv(1024)
 
-
                 c.close()
                 sleep(1)
 
 
 except socket.gaierror, msg:
-        print "ERROR: " + str(msg) + ": " + rihost
+        print "ERROR: " + str(msg) + ": " + ilohost
         sys.exit(1)
 except socket.sslerror, msg:
-        print "ERROR: " + str(msg) + "for " + rihost
+        print "ERROR: " + str(msg) + "for " + ilohost
         sys.exit(1)
 except socket.error, msg:
-        print "ERROR: " + str(msg) + "talking to " + rihost
+        print "ERROR: " + str(msg) + "talking to " + ilohost
         sys.exit(1)
_______________________________________________________
Linux-HA-Dev: [email protected]
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/

Reply via email to