- """
- There are three cases:
- 1) the pcu_record passed below includes port_status from an
- external probe.
- 2) the external probe failed, and the values are empty
- 3) this call is made independent of port_status.
-
- In the first case, the first open port is used.
- In the third case, the ports are tried in sequence.
-
- In this way, the port_status value serves only as an optimization,
- because closed ports are avoided. The supported_ports value should
- order ports by their preferred usage.
- """
-
- supported_ports = []
-
- def __init__(self, plc_pcu_record, verbose, ignored=None):
- PCUModel.__init__(self, plc_pcu_record)
- PCURecord.__init__(self, plc_pcu_record)
-
- def reboot(self, node_port, dryrun):
-
- port_list = []
- # There are two sources of potential ports. Those that are open and
- # those that are part of the PCU's supported_ports.
- # I think we should start with supported_ports and then filter that
- # by the open ports.
-
- port_list = self.supported_ports
-
- if hasattr(self, 'port_status') and self.port_status:
- # get out the open ports
- port_list = filter(lambda x: self.port_status[x] == "open" , self.port_status.keys())
- port_list = [ int(x) for x in port_list ]
- # take only the open ports that are supported_ports
- port_list = filter(lambda x: x in self.supported_ports, port_list)
- if port_list == []:
- raise ExceptionPort("No Open Port: No transport from open ports")
-
- print port_list
-
- ret = "No implementation for open ports on selected PCU model"
- for port in port_list:
- if port not in Transport.porttypemap:
- continue
-
- type = Transport.porttypemap[port]
- self.transport = Transport(type, verbose)
-
- print "checking for run_%s" % type
- if hasattr(self, "run_%s" % type):
- print "found run_%s" % type
- fxn = getattr(self, "run_%s" % type)
- ret = self.catcherror(fxn, node_port, dryrun)
- if ret == 0: # NOTE: success!, so stop
- break
- else:
- continue
-
- return ret
-
- def run(self, node_port, dryrun):
- """ This function is to be defined by the specific PCU instance. """
- raise Exception("This function is not implemented")
- pass
-
- #def reboot(self, node_port, dryrun):
-
- def catcherror(self, function, node_port, dryrun):
- try:
- return function(node_port, dryrun)
- except ExceptionNotFound, err:
- return "error: " + str(err)
- except ExceptionPassword, err:
- return "Password exception: " + str(err)
- except ExceptionTimeout, err:
- return "Timeout exception: " + str(err)
- except ExceptionUsername, err:
- return "No username prompt: " + str(err)
- except ExceptionSequence, err:
- return "Sequence error: " + str(err)
- except ExceptionPrompt, err:
- return "Prompt exception: " + str(err)
- except ExceptionNoTransport, err:
- return "No Transport: " + str(err)
- except ExceptionPort, err:
- return "No ports exception: " + str(err)
- except socket.error, err:
- return "socket error: timeout: " + str(err)
- except urllib2.HTTPError, err:
- return "HTTPError: " + str(err)
- except urllib2.URLError, err:
- return "URLError: " + str(err)
- except EOFError, err:
- self.transport.close()
- import traceback
- traceback.print_exc()
- return "EOF connection reset" + str(err)
- except Exception, err:
- #from monitor.common import email_exception
- #email_exception(self.host)
- raise Exception(err)
+ """
+ There are three cases:
+ 1) the pcu_record passed below includes port_status from an
+ external probe.
+ 2) the external probe failed, and the values are empty
+ 3) this call is made independent of port_status.
+
+ In the first case, the first open port is used.
+ In the third case, the ports are tried in sequence.
+
+ In this way, the port_status value serves only as an optimization,
+ because closed ports are avoided. The supported_ports value should
+ order ports by their preferred usage.
+ """
+
+ supported_ports = []
+
+ def __init__(self, plc_pcu_record, verbose, ignored=None):
+ PCUModel.__init__(self, plc_pcu_record)
+ PCURecord.__init__(self, plc_pcu_record)
+
+ def reboot(self, node_port, dryrun):
+
+ port_list = []
+ # There are two sources of potential ports. Those that are open and
+ # those that are part of the PCU's supported_ports.
+ # I think we should start with supported_ports and then filter that
+ # by the open ports.
+
+ port_list = self.supported_ports
+
+ if hasattr(self, 'port_status') and self.port_status:
+ # get out the open ports
+ port_list = filter(lambda x: self.port_status[x] == "open" , self.port_status.keys())
+ port_list = [ int(x) for x in port_list ]
+ # take only the open ports that are supported_ports
+ port_list = filter(lambda x: x in self.supported_ports, port_list)
+ if port_list == []:
+ raise ExceptionPort("No Open Port: No transport from open ports")
+
+ print port_list
+
+ ret = "No implementation for open ports on selected PCU model"
+ for port in port_list:
+ if port not in Transport.porttypemap:
+ continue
+
+ type = Transport.porttypemap[port]
+ self.transport = Transport(type, verbose)
+
+ print "checking for run_%s" % type
+ if hasattr(self, "run_%s" % type):
+ print "found run_%s" % type
+ fxn = getattr(self, "run_%s" % type)
+ ret = self.catcherror(fxn, node_port, dryrun)
+ if ret == 0: # NOTE: success!, so stop
+ break
+ else:
+ continue
+
+ return ret
+
+ def run(self, node_port, dryrun):
+ """ This function is to be defined by the specific PCU instance. """
+ raise Exception("This function is not implemented")
+
+
+class BasicPCUControl(PCUModel):
+
+ """
+ This is the basic pcucontrol super class on which the classes in
+ pcucontrol/models/* are based.
+
+ Each model implements a specific 'run' function that can use any
+ mechanism available to reboot the given PCU using, hostname, password,
+ username, and dryrun.
+
+ This is best suited for nodes with built-in PCUs, iLO, AMT, DRAC, etc.
+ """
+
+ supported_ports = []
+ install_path = get_python_lib(1) + "/pcucontrol/"
+
+ def __init__(self, plc_pcu_record, ignored=None):
+ PCUModel.__init__(self, plc_pcu_record)
+
+ def run_expect_script(self, scriptname, **args):
+ locfg = command.CMD()
+
+ cmd_str = get_python_lib(1) + "/pcucontrol/models/exp/"
+ cmd = cmd_str + "%s %s %s '%s' %s %s " % (
+ scriptname, self.host, self.username,
+ self.password, args['dryrun'], args['model'])
+ cmd_out, cmd_err = locfg.run_noexcept(cmd)
+ return cmd_out.strip() + cmd_err.strip()
+
+ def reboot(self, node_port, dryrun):
+ if dryrun:
+ looking_for_fxn = 'pcu_test'
+ else:
+ looking_for_fxn = 'pcu_run'
+
+ # verify that the function exists.
+ if not hasattr(self, looking_for_fxn):
+ raise Exception("This model (%s) does not implement %s" % (self.model, looking_for_fxn))
+
+ print "found function %s in model %s" % (looking_for_fxn, self.model)
+ reboot_fxn = getattr(self, looking_for_fxn)
+ ret = self.catcherror(reboot_fxn, node_port)
+
+ return ret
+
+ def run(self, node_port, dryrun):
+ """ This function is to be defined by the specific PCU instance. """
+ raise Exception("This function is not implemented")
+