def set_power_state(self, state): """ Set power state to passed state """ attempts = 0 while attempts < 5: try: ipmi_object = self.initialize_ipmi_session() ipmi_object.set_power(state) break except IpmiException as iex: logger.error("Error sending command: %s" % str(iex)) logger.warning( "IPMI command failed, retrying after 15 seconds...") sleep(15) attempts = attempts + 1
def initialize_ipmi_session(self): """ Initialize command object with IPMI details """ attempts = 0 while attempts < 5: try: ipmi_object = command.Command(self.ipmi_ip, self.user_id, self.password) except IpmiException as e: print(e.args[0]) logger.warning( "IPMI command failed, retrying after 15 seconds...") sleep(15) attempts = attempts + 1 continue return ipmi_object
def set_power_state(self, state): """ Set power state to passed state """ attempts = 0 ipmi_object = None while attempts < 5: try: ipmi_object = self.initialize_ipmi_session() response = ipmi_object.set_power(state) status = True break except IpmiException as iex: logger.error("Error sending command: %s" % str(iex)) logger.warning( "IPMI command failed, retrying after 15 seconds...") if ipmi_object: ipmi_object.ipmi_session.logout() sleep(15) attempts = attempts + 1 status = False return response, status