# HG changeset patch
# User javier@citrico-linux
# Date 1259587621 0
# Node ID 6f17b8bf016a17f47dacd343df1c20d8841a7aa0
# Parent  f509339c8f7474c96d3ca6532d2d184443440cc5
Introduce localizable raise conditions to the iLO power on script
Signed-off-by:Javier.Alvarez-Valle@citrix.com

diff -r f509339c8f74 -r 6f17b8bf016a scripts/poweron/iLO.py
--- a/scripts/poweron/iLO.py	Fri Nov 27 23:00:18 2009 +0000
+++ b/scripts/poweron/iLO.py	Mon Nov 30 13:27:01 2009 +0000
@@ -1,50 +1,62 @@
-import sys,M2Crypto 
-
-def getXmlWithLogin(user, password):
-    
-    inputFile=open("/etc/xapi.d/plugins/iLOPowerON.xml",'r')
-    try:
-        result= inputFile.read().replace('user',user).replace('password',password)
-    finally:
-        inputFile.close()
-    return result
-
-
-def iLO(power_on_ip, user, password):
-  
-        xmlWithlogin=getXmlWithLogin(user,password)+'\r\n'      
-    
-        ''' Send and receive '''
-        ctx = M2Crypto.SSL.Context()
-        ctx.set_session_timeout(500)
-        s = M2Crypto.SSL.Connection(ctx)
-        totalmsg=''
-        try:
-            s.connect((power_on_ip,443))
-            written=s.sendall(xmlWithlogin)
-            msg=s.read()
-            totalmsg=msg
-            while(len(msg)):
-                msg=s.read()
-                totalmsg+=msg
-        finally:
-            s.close()
-            '''Check that the server replies with no authentication error'''
-            if len(totalmsg)>0 and totalmsg.find('STATUS="0x000A"')==-1:
-                return str(True)
-            else:
-                return str(False)
-    
-def main():
-    if len(sys.argv)<3:
-        exit(0)
-    ip=sys.argv[1]
-    user=sys.argv[2]
-    password=sys.argv[3]
-    print iLO(ip,user,password)
-   
-
-
-
-if __name__ == "__main__":
-    main()
\ No newline at end of file
+import sys,M2Crypto, XenAPI, XenAPIPlugin
+
+
+class ILO_CONNECTION_ERROR(Exception):
+    """Base Exception class for all transfer plugin errors."""
+    def __init__(self, *args):
+        Exception.__init__(self, *args)
+		
+class ILO_POWERON_FAILED(Exception):
+    """Base Exception class for all transfer plugin errors."""
+    def __init__(self, *args):
+        Exception.__init__(self, *args)
+
+
+def getXmlWithLogin(user, password):
+    
+    inputFile=open("/etc/xapi.d/plugins/iLOPowerON.xml",'r')
+    try:
+        result= inputFile.read().replace('user',user).replace('password',password)
+    finally:
+        inputFile.close()
+    return result
+
+
+def iLO(power_on_ip, user, password):
+	xmlWithlogin=getXmlWithLogin(user,password)+'\r\n'      
+	
+	''' Send and receive '''
+	ctx = M2Crypto.SSL.Context()
+	ctx.set_session_timeout(500)
+	s = M2Crypto.SSL.Connection(ctx)
+	totalmsg=''
+	try:
+		s.connect((power_on_ip,443))
+		written=s.sendall(xmlWithlogin)
+		msg=s.read()
+		totalmsg=msg
+		while(len(msg)):
+			msg=s.read()
+			totalmsg+=msg
+	except:
+		s.close()
+		raise ILO_CONNECTION_ERROR()
+	'''Check that the server replies with no authentication error'''
+	if len(totalmsg)>0 and totalmsg.find('STATUS="0x000A"')==-1:
+		return str(True)
+	else:
+		raise ILO_POWERON_FAILED()
+    
+def main():
+    if len(sys.argv)<3:
+        exit(0)
+    ip=sys.argv[1]
+    user=sys.argv[2]
+    password=sys.argv[3]
+    print iLO(ip,user,password)
+   
+
+
+
+if __name__ == "__main__":
+    main()
