def get_server_info_from_oa(self, server_bay_no): """ Description:This function will return the server details for validating server hardware page Params:server_bay_no--> The bay number of server Return:Returns a dictionary with server details """ dict_server = {} output = None try: output = ha_library.execute_Remote_commands_iLO_and_return_output( self.hw_ip, self.hw_username, self.hw_password, "show server info %s" % (server_bay_no)) ha_library.closeConnection() dict_server["ip"] = self.find_value_by_oa_keyword( output, "IP Address") dict_server["uuid"] = self.find_value_by_oa_keyword(output, "UUID") dict_server["SerialNo"] = self.find_value_by_oa_keyword( output, "Serial Number") dict_server["ProductId"] = self.find_value_by_oa_keyword( output, "Part Number") dict_server["model"] = self.find_value_by_oa_keyword( output, "Product Name") dict_server["hostname"] = self.find_value_by_oa_keyword( output, "Name") if len(dict_server) != 0: return dict_server else: return False except Exception as e: logger._log_to_console_and_log_file( "Unable to read data from the server in bay %s of enclosure %s. Exception while processing information is %s" % (server_bay_no, self.hw_ip, e)) return False
def get_vc_part_number(self, interconnect_bay_number): """ Description:This function will return the Part number of VC.It doesn't handle input "ALL" for interconnect_bay_number Params:interconnect_bay_number--> The bay number of interconnect Return:Returns the part number of VC if command is executed else Error will be shown """ PartNumber = None output = None try: output = ha_library.execute_Remote_commands_iLO_and_return_output( self.hw_ip, self.hw_username, self.hw_password, "show interconnect info %s" % (interconnect_bay_number)) pos = output.find("Part Number") if pos == -1: return False start = pos + len("Part Number:") + 1 end = output.find("\n", start) PartNumber = output[start:end - 1] PartNumber.rstrip() ha_library.closeConnection() # PartNumber = self.find_value_by_oa_keyword(output, "Part Number:") if not PartNumber: logger._warn("Failed to send the command") logger._debug("output = %s" % (output)) logger._debug("result = %s" % (PartNumber)) return (False, '') else: return (True, PartNumber) except: logger._log_to_console_and_log_file("Failed to get Part NUmber") return (False, '')
def get_server_present_power_consumption(self): """ Description: Returns the Maximum power utilization of a server at that time if true else returns false Input:username,password and IP of an ILO """ output = False try: output = ha_library.execute_Remote_commands_iLO_and_return_output( self.hw_ip, self.hw_username, self.hw_password, "show /system1/oemhp_power1") ha_library.closeConnection() delimiter = '=' presentPower = self.find_value_by_key(output, "oemhp_PresentPower", delimiter) if not presentPower: output = False logger._warn("Failed to send the command") logger._debug("output = %s" % (output)) logger._debug("result = %s" % (presentPower)) raise ValueError else: output = presentPower return output except: raise Exception("Failed to get present Power Info")
def get_firmware_version_for_vc(self, interconnect_bay_number): """ Description:This function will return the Firmware version of VC.It doesn't handle input "ALL" for interconnect_bay_number Params:interconnect_bay_number--> The bay number of interconnect Return: Returns the Firmware version if command is executed else Error will be shown """ FirmVer = None try: output = ha_library.execute_Remote_commands_iLO_and_return_output( self.hw_ip, self.hw_username, self.hw_password, "show interconnect info %s" % (interconnect_bay_number)) ha_library.closeConnection() FirmVer = self.find_value_by_oa_keyword(output, "Firmware Version") if not FirmVer: output = False logger._warn("Failed to send the command") logger._debug("output = %s" % (output)) logger._debug("result = %s" % (FirmVer)) return (False, '') else: return (True, FirmVer) except: logger._log_to_console_and_log_file( "Failed to get Firmware Version") return (False, '')
def get_allowable_enclr_power_cap(self): """ Description: Returns the Allowable Enclosure Dynamic Power Cap. """ output = False try: output = ha_library.execute_Remote_commands_iLO_and_return_output( self.hw_ip, self.hw_username, self.hw_password, "show enclosure power_cap") ha_library.closeConnection() delimiter = ' ' power_cap = self.find_value_by_key( output, "Allowable Enclosure Dynamic Power Cap:", delimiter) if not power_cap: output = False logger._warn("Failed to send the command") logger._debug("output = %s" % (output)) logger._debug("result = %s" % (power_cap)) raise ValueError else: output = power_cap.split('-')[0] return output.strip() except: raise Exception("Failed to get present Power Info")
def get_server_model(self): """ Description: Returns the Model name of the server if true else returns false Input:username,password and IP of ILO """ try: output = ha_library.execute_Remote_commands_iLO_and_return_output( self.hw_ip, self.hw_username, self.hw_password, "show /system1 name") ha_library.closeConnection() ModelName = self.find_value_by_keyword(output, "name") if not ModelName: output = False logger._warn("Failed to send the command") logger._debug("output = %s" % (output)) logger._debug("result = %s" % ModelName) raise ValueError else: output = ModelName return output except: raise Exception("Failed to get Server Model Number")
def set_enclr_power_cap(self, power_cap): """ Description: sets dynamic power cap to enclosures Returns the enclosures power cap """ output = False try: output = ha_library.execute_Remote_commands_iLO_and_return_output( self.hw_ip, self.hw_username, self.hw_password, "set enclosure power_cap %s" % (power_cap)) ha_library.closeConnection() delimiter = ' ' power_cap_status = self.find_value_by_key( output, "Enclosure Dynamic Power Cap:", delimiter) if not power_cap_status: output = False logger._warn("Failed to send the command") logger._debug("output = %s" % (output)) logger._debug("result = %s" % (power_cap)) raise ValueError else: output = power_cap_status.split()[0] return output except: raise Exception("Failed to get present Power Info")
def get_vc_status(self, interconnect_bay_number): """ Description: This function will return the status of interconnect whether it is on or off.It doesn't handle input "ALL" for interconnect_bay_number Params:interconnect_bay_number--> The bay number of interconnect Return: Returns the status of interconnect if command is executed else false """ status = None try: output = ha_library.execute_Remote_commands_iLO_and_return_output( self.hw_ip, self.hw_username, self.hw_password, "show interconnect status %s" % (interconnect_bay_number)) ha_library.closeConnection() status = self.find_value_by_oa_keyword(output, "Powered") if not status: output = False logger._warn("Failed to send the command") logger._debug("output = %s" % (output)) logger._debug("result = %s" % (status)) return (False, '') else: output = status.lower() return (True, output) except: logger._log_to_console_and_log_file( "Failed to get Interconnect status") return (False, '')
def get_ilo_version_date(self): """ Description: Returns the ILO firmware version and date if true else returns false Input:Username,password and IP of ILO" """ try: output = ha_library.execute_Remote_commands_iLO_and_return_output( self.hw_ip, self.hw_username, self.hw_password, "show /map1/firmware1") ha_library.closeConnection() ILOVersion = self.find_value_by_keyword(output, "version") index = ILOVersion.rfind('p') if not index == -1: version = ILOVersion[0:index - 1] version.rstrip() else: version = ILOVersion ILODateFir = self.find_value_by_keyword(output, "date") if not ILOVersion and ILODateFir: output = False logger._warn("Failed to send the command") logger._debug("output = %s" % (output)) logger._debug("result = %s" % (version)) logger._debug("result = %s" % (ILODateFir)) raise ValueError else: output = version + " " + ILODateFir return output except: raise Exception("Failed to get ILO Version Date")
def get_port_nic_address(self): """ Description: Function to retrieve the MAC address of NIC ports Returns the address separated by comma else false """ try: output = ha_library.execute_Remote_commands_iLO_and_return_output( self.hw_ip, self.hw_username, self.hw_password, "show /system1/network1/Integrated_NICs") ha_library.closeConnection() Port1MACAddress = self.find_value_by_keyword( output, "Port1NIC_MACAddress") Port2MACAddress = self.find_value_by_keyword( output, "Port2NIC_MACAddress") if not Port1MACAddress and Port1MACAddress: output = False logger._warn("Failed to send the command") logger._debug("output = %s" % (output)) logger._debug("result = %s" % (Port1MACAddress)) logger._debug("result = %s" % (Port2MACAddress)) raise ValueError else: output = Port1MACAddress + "," + Port2MACAddress return output except: raise Exception("Unable to get pORT NIC MAC Address")
def get_rom_version_date(self): """ Description: Returns the ROM Version and date if true else returns false Input:username,password and IP of an ILO """ try: output = ha_library.execute_Remote_commands_iLO_and_return_output( self.hw_ip, self.hw_username, self.hw_password, "show /system1/firmware1") ha_library.closeConnection() ROMVersion = self.find_value_by_keyword(output, "version") ROMDateFir = self.find_value_by_keyword(output, "date") if not ROMVersion and ROMDateFir: output = False logger._warn("Failed to send the command") logger._debug("output = %s" % (output)) logger._debug("result = %s" % (ROMVersion)) logger._debug("result = %s" % (ROMDateFir)) raise ValueError else: output = ROMVersion + " " + ROMDateFir return output except: raise Exception("Failed to get ROM Version date")
def disable_enclr_power_cap(self): """ Description: This function will remove the enclosure power cap and returns the power cap status. """ output = False try: output = ha_library.execute_Remote_commands_iLO_and_return_output( self.hw_ip, self.hw_username, self.hw_password, "set enclosure power_cap off") ha_library.closeConnection() delimiter = ' ' power_cap_status = self.find_value_by_key( output, "Enclosure Dynamic Power Cap:", delimiter) if power_cap_status.strip() != "Disabled": output = False logger._warn("Failed to send the command") logger._debug("output = %s" % (output)) logger._debug("result = %s" % (power_cap_status)) raise ValueError else: output = True return output except: raise Exception("Failed to get present Power Info")
def get_enclr_power_cap(self): """ Description: Returns the enclosure power cap status. if power cap is already set this function returns power_cap value else Disabled """ output = False try: output = ha_library.execute_Remote_commands_iLO_and_return_output( self.hw_ip, self.hw_username, self.hw_password, "show enclosure power_cap") ha_library.closeConnection() delimiter = ' ' power_cap_status = self.find_value_by_key( output, "Enclosure Dynamic Power Cap:", delimiter) if not power_cap_status: output = False logger._warn("Failed to send the command") logger._debug("output = %s" % (output)) logger._debug("result = %s" % (power_cap_status)) raise ValueError else: output = power_cap_status.strip() return output except: raise Exception("Failed to get present Power Info")
def get_server_port_data(self, server_bay_no): """ Description:This function will return the server details for validating server hardware page Params:server_bay_no--> The bay number of server Return:Returns a dictionary with server port details """ output2 = None try: output2 = ha_library.execute_Remote_commands_iLO_and_return_output( self.hw_ip, self.hw_username, self.hw_password, "show server info %s" % (server_bay_no)) ha_library.closeConnection() output2 = output2.split('\n') dict_portinfo = {} i = j = 0 for line in output2: if ("FlexFabric" in line): if not ("FlexFabric Embedded Ethernet" in line): if ("FLB Adapter 1" in line.split(':')[0]): i = i + 1 dict_portinfo['slot' + str(i)] = "FlexibleLOM 1" model = line.split(':')[1].strip(' ').strip('\r') dict_portinfo['model' + str(i)] = model elif ("Mezzanine" in line): if not ("This server does not contain any mezzanine cards" in line): i = i + 1 dict_portinfo['slot' + str(i)] = line.split(':')[0].strip(' ') model = line.split(':')[1].strip(' ') dict_portinfo['model' + str(i)] = model elif "Ethernet" in line: if "LOM" in line: j = j + 1 line_cont = ((((line.strip(" ")).strip("\r") ).strip("\t")).strip(" ")).split("_") port = line_cont[0].split(":", 1) address = (re.sub('\s+', ' ', port[1]).strip()).split(" ") portno = address[0].split("-") dict_portinfo["port" + str(j)] = portno[0] dict_portinfo["address" + str(j)] = address[1] elif "Port" in line: j = j + 1 line_cont = ((((line.strip(" ")).strip("\r")).strip("\t") ).strip(" ")).split("_") port = line_cont[0].split(":", 1) portno = port[0].split(" ") dict_portinfo["port" + str(j)] = portno[1].strip() dict_portinfo["address" + str(j)] = port[1].strip() return (dict_portinfo) except Exception as e: logger._log_to_console_and_log_file( "Unable to read data from the server in bay %s of enclosure %s. Exception while processing information is %s" % (server_bay_no, self.hw_ip, e)) return ({})
def get_cpu_proc_number_name(self): """ Description: Returns the number of processors a server has and its name else false Input:Username,password and IP of ILO" """ try: FullProcNumberAndName = None output1 = ha_library.execute_Remote_commands_iLO_and_return_output( self.hw_ip, self.hw_username, self.hw_password, "show /system1 processor_number") ha_library.closeConnection() output2 = ha_library.execute_Remote_commands_iLO_and_return_output( self.hw_ip, self.hw_username, self.hw_password, "show /system1/cpu1") ha_library.closeConnection() ProcNumber = self.find_value_by_keyword(output1, "processor_number") CPUName = self.find_value_by_keyword(output2, "name") CPUForName = CPUName.replace("@", "(").rstrip() CoreNumber = self.find_value_by_keyword(output2, "number_cores") if not ProcNumber and CPUName and CoreNumber: output = False logger._warn("Failed to send the command") logger._debug("output = %s" % (output)) logger._debug("result = %s" % (ProcNumber)) logger._debug("result = %s" % (CoreNumber)) raise ValueError else: if (ProcNumber > "1"): FullProcNumberAndName = ProcNumber + " " + "processors," + \ "" + CPUForName + "/ " + CoreNumber + "-core)" else: FullProcNumberAndName = ProcNumber + " " + "processor," + \ "" + CPUForName + "/ " + CoreNumber + "-core)" return FullProcNumberAndName except: raise Exception("Failed to get CPU Processor Number and Name")
def get_server_license(self): """ This function will return the server license captured from OA """ output = False try: output = ha_library.execute_Remote_commands_iLO_and_return_output( self.hw_ip, self.hw_username, self.hw_password, "show /map1 license") ha_library.closeConnection() delimiter = '=' server_license = self.find_value_by_key(output, "license", delimiter) if not server_license: output = False logger._warn("Failed to send the command") logger._debug("output = %s" % (output)) logger._debug("result = %s" % (server_license)) raise ValueError else: output = server_license return output except: raise Exception("Failed to get ILO License")
def get_server_model_from_OA(self, server_bay_no): """ Description:This function will return the server adapter information to validate server hardware type page Params:server_bay_no--> The bay number of server Return:Returns the list with the adapter information """ output = None try: output = ha_library.execute_Remote_commands_iLO_and_return_output( self.hw_ip, self.hw_username, self.hw_password, "show server info %s" % (server_bay_no)) ha_library.closeConnection() ServerModel = self.find_value_by_oa_keyword(output, "Product Name") if not ServerModel: return False else: return ServerModel except Exception as e: logger._log_to_console_and_log_file( "Unable to read data from the server in bay %s of enclosure %s. Exception while processing information is %s" % (server_bay_no, self.hw_ip, e)) return False
def get_server_temp(self, server_bay_no): """ This function will return the current server temperature present in OA """ output = False try: output = ha_library.execute_Remote_commands_iLO_and_return_output( self.hw_ip, self.hw_username, self.hw_password, "show server Temp %s" % (server_bay_no)) ha_library.closeConnection() delimiter = ' ' SystemName = self.find_value_by_key( output, "Ambient Zone (01-Inlet Ambient)", delimiter) temp_OA = SystemName.split()[2] if not temp_OA: output = False logger._warn("Failed to send the command") logger._debug("output = %s" % (output)) logger._debug("result = %s" % (SystemName)) raise ValueError else: output = temp_OA[:-1] return output except: raise Exception("Failed to get server temperature")
def get_vc_product_name(self, interconnect_bay_number): """ Description:This function will return the Product name of VC.It doesn't handle input "ALL" for interconnect_bay_number Params:interconnect_bay_number--> The bay number of interconnect Return: Returns the product name of VC if command is executed else Error will be shown """ ProdName = None try: output = ha_library.execute_Remote_commands_iLO_and_return_output( self.hw_ip, self.hw_username, self.hw_password, "show interconnect info %s" % (interconnect_bay_number)) ha_library.closeConnection() ProdName = self.find_value_by_oa_keyword(output, "Product Name") if not ProdName: logger._warn("Failed to send the command") logger._debug("output = %s" % (output)) logger._debug("result = %s" % (ProdName)) return (False, '') else: return (True, ProdName) except: logger._log_to_console_and_log_file("Failed to get VC Name") return (False, '')
def get_serial_number(self): """ Description: Returns the serial number of an ILO if true else returns false Input:username,password and IP of ILO """ try: output = ha_library.execute_Remote_commands_iLO_and_return_output( self.hw_ip, self.hw_username, self.hw_password, "show /system1 number") ha_library.closeConnection() SerialNumber = self.find_value_by_keyword(output, "number") if not SerialNumber: output = False logger._warn("Failed to send the command") logger._debug("output = %s" % (output)) logger._debug("result = %s" % (SerialNumber)) raise ValueError else: output = SerialNumber.rstrip() return output except: raise Exception("Failed to get Server Serial Number")
def get_system_name(self): """ Description: Returns the ILO host name if true else returns false Input:username,password and IP of an ILO """ try: output = ha_library.execute_Remote_commands_iLO_and_return_output( self.hw_ip, self.hw_username, self.hw_password, "show /map1/enetport1") ha_library.closeConnection() SystemName = self.find_value_by_keyword(output, "SystemName") if not SystemName: output = False logger._warn("Failed to send the command") logger._debug("output = %s" % (output)) logger._debug("result = %s" % (SystemName)) raise ValueError else: output = SystemName return output except: raise Exception("Failed to get ILO Host Name")
def get_server_port_information(self, encname): """ Description:This function will return the server adapter information to validate server hardware type page Params:server_bay_no--> The bay number of server Return:Returns the list with the adapter information """ output2 = None try: output2 = ha_library.execute_Remote_commands_iLO_and_return_output( self.hw_ip, self.hw_username, self.hw_password, "show server info all") ha_library.closeConnection() output2 = output2.split('\n') ports_list = [] WWWN_list = [] for line in output2: if "LOM" in line and (not ("Name" in line)): line_cont = "" for word in line.strip(" ").strip("\r").strip("\t").split( " "): if word != "": if word != " ": line_cont += word.strip(" ").strip("\r").strip( "\t") + "=" line_cont.strip('=') WWWN_list = [] line_cont = line_cont.strip(" ").split("=") if "FC" in line_cont[0]: if (len(line_cont) < 6): WWWN_list.append( ("Flexible" + line_cont[2]).replace( "LOM", "LOM ")) elif (len(line_cont) > 6): WWWN_list.append( ("Flexible" + line_cont[4]).replace( "LOM", "LOM ")) else: WWWN_list.append( ("Flexible" + line_cont[3]).replace( "LOM", "LOM ")) WWWN_list.append("FC") else: if (len(line_cont) < 6): WWWN_list.append( ("Flexible" + line_cont[2]).replace( "LOM", "LOM ")) elif (len(line_cont) > 6): WWWN_list.append( ("Flexible" + line_cont[4]).replace( "LOM", "LOM ")) else: WWWN_list.append( ("Flexible" + line_cont[3]).replace( "LOM", "LOM ")) WWWN_list.append(line_cont[0]) if (len(line_cont) < 6): WWWN_list.append(line_cont[3]) elif (len(line_cont) > 6): WWWN_list.append(line_cont[5]) else: WWWN_list.append(line_cont[4]) ports_list.append(WWWN_list) # adapter_list.append(data_list) return (True, ports_list) except Exception as e: logger._log_to_console_and_log_file( "Unable to read data from the server in bay %s of enclosure %s. Exception while processing information is %s" % (encname, self.hw_ip, e)) return (False, [])
def get_server_adapter_information(self, server_bay_no, adapter_dict): """ Description:This function will return the server adapter information to validate server hardware type page Params:server_bay_no--> The bay number of server Return:Returns the list with the adapter information """ output = None try: output = ha_library.execute_Remote_commands_iLO_and_return_output( self.hw_ip, self.hw_username, self.hw_password, "show server info %s" % (server_bay_no)) ha_library.closeConnection() output = output.split('\n') model = "" adapter_list = [] for line in output: data_list = [] data_dict = { 'location': '', 'model': '', 'devicetype': '', 'speed': '', 'ports': '' } try: if ("FlexFabric" in line): if not ("FlexFabric Embedded Ethernet" in line): '''if("FLB Adapter 1" in line.split(':')[0]): data_dict['location'] = "FlexibleLOM 1" data_list.append("FlexibleLOM 1")''' model = line.split(':')[1].strip(' ').strip('\r') data_dict['model'] = model model_info = adapter_dict[model] arrinfo = model_info.split(',') data_list.append(arrinfo[0]) data_list.append(model) data_list.append(arrinfo[1]) data_list.append(arrinfo[2]) data_list.append(arrinfo[3]) if ("Mezzanine" in line): if not ("This server does not contain any mezzanine cards" in line): data_dict['location'] = line.split(':')[0].strip( ' ') model = line.split(':')[1].strip(' ') data_dict['model'] = model model_info = adapter_dict[model] arrinfo = model_info.split(',') data_list.append(arrinfo[0]) data_list.append(model) data_list.append(arrinfo[1]) data_list.append(arrinfo[2]) data_list.append(arrinfo[3]) if (data_list != []): adapter_list.append(data_list) except Exception as e: adapter_list.append(data_list) logger._warn( "Given adapter %s information is not updated in the resource file. Exception is %s" % (model, e)) return (False, []) return (True, adapter_list) except Exception as e: logger._log_to_console_and_log_file( "Unable to read data from the server in bay %s of enclosure %s. Exception while processing information is %s" % (server_bay_no, self.hw_ip, e)) return (False, [])