move nodelist.kid headers into node_template.kid to remove redundancy.
[monitor.git] / pcucontrol / models / IPAL.py
index 75668db..8929946 100644 (file)
@@ -17,11 +17,14 @@ class IPAL(PCUControl):
 
                try:
                        # TODO: make sleep backoff, before stopping.
-                       time.sleep(4)
+                       time.sleep(8)
                        ret = s.recv(count, socket.MSG_DONTWAIT)
                except socket.error, e:
                        if e[0] == errno.EAGAIN:
-                               raise Exception(e[1])
+                               #raise Exception(e[1])
+                               raise ExceptionNotFound(e[1])
+                       elif e[0] == errno.ETIMEDOUT:
+                               raise ExceptionTimeout(e[1])
                        else:
                                # TODO: not other exceptions.
                                raise Exception(e)
@@ -46,13 +49,14 @@ class IPAL(PCUControl):
                self.transport.open(self.host)
                ## XXX Some iPals require you to hit Enter a few times first
                self.transport.ifThenSend("Password >", "\r\n\r\n", ExceptionNotFound)
+               self.transport.ifThenSend("Password >", "\r\n\r\n", ExceptionNotFound)
                # Login
                self.transport.ifThenSend("Password >", self.password, ExceptionPassword)
                self.transport.write("\r\n\r\n")
                if not dryrun: # P# - Pulse relay
                        print "node_port %s" % node_port
                        self.transport.ifThenSend("Enter >", 
-                                                       "P7", # % node_port, 
+                                                       "P%s"%node_port, 
                                                        ExceptionNotFound)
                        print "send newlines"
                        self.transport.write("\r\n\r\n")
@@ -78,7 +82,9 @@ class IPAL(PCUControl):
                        s.close()
                        if e[0] == errno.ECONNREFUSED:
                                # cannot connect to remote host
-                               raise Exception(e[1])
+                               raise ExceptionNotFound(e[1])
+                       elif e[0] == errno.ETIMEDOUT:
+                               raise ExceptionTimeout(e[1])
                        else:
                                # TODO: what other conditions are there?
                                raise Exception(e)
@@ -90,7 +96,7 @@ class IPAL(PCUControl):
                print "Current status is '%s'" % ret
 
                if ret == '':
-                       raise Exception("Status returned 'another session already open' %s : %s" % (node_port, ret))
+                       raise Exception("Status returned 'another session already open' on %s %s : %s" % (self.host, node_port, ret))
                                
                if node_port < len(ret):
                        status = ret[node_port]
@@ -100,10 +106,12 @@ class IPAL(PCUControl):
                        elif status == '0':
                                # down
                                power_on = False
+                       elif status == '6':
+                               raise ExceptionPort("IPAL reported 'Cable Error' on %s socket %s : %s" % (self.host, node_port, ret))
                        else:
-                               raise Exception("Unknown status for PCU socket %s : %s" % (node_port, ret))
+                               raise Exception("Unknown status for PCU %s socket %s : %s" % (self.host, node_port, ret))
                else:
-                       raise Exception("Mismatch between configured port and PCU status: %s %s" % (node_port, ret))
+                       raise Exception("Mismatch between configured port and PCU %s status: %s %s" % (self.host, node_port, ret))
                        
 
                if not dryrun:
@@ -128,10 +136,12 @@ class IPAL(PCUControl):
                                elif status == '0':
                                        # down
                                        power_on = False
+                               elif status == '6':
+                                       raise ExceptionPort("IPAL reported 'Cable Error' on %s socket %s : %s" % (self.host, node_port, ret))
                                else:
-                                       raise Exception("Unknown status for PCU socket %s : %s" % (node_port, ret))
+                                       raise Exception("Unknown status for PCU %s socket %s : %s" % (self.host, node_port, ret))
                        else:
-                               raise Exception("Mismatch between configured port and PCU status: %s %s" % (node_port, ret))
+                               raise Exception("Mismatch between configured port and PCU %s status: %s %s" % (self.host, node_port, ret))
 
                        if power_on:
                                return 0