def getflashinfo(self): flag = 0 (tmpret,output) = saferun('lspci 2>/dev/null') for line in output: if line.find('Mass storage') >=0 and line.find('Altera') >= 0: flag = 2 elif line.find('Mass storage') >=0 and line.find('Xilinx') >= 0: flag = 3 (ret, output) = saferun('lsmod | grep ssd_adv') if ret == 0 and output != '' : self.exist = 1 self.flashinfo['manu'] = 'HuaWei' self.flashinfo['model'] = 'NULL' self.flashinfo['mediatype'] = 'NULL' self.flashinfo['size'] = 'NULL' self.flashinfo['devicename'] = 'NULL' self.flashinfo['generation'] = 'NULL' self.flashinfo['version'] = 'NULL' if flag == 2: (ret, output) = saferun('%s -a'% gparas.ssdtool) if ret != 0: configinfo_log.logtofile('get_config_info:ssd_label error!') return self.flashinfo['generation'] = '2g' elif flag == 3: (ret, output) = saferun('%s -a'% gparas.ssdtool_3g) if ret != 0: configinfo_log.logtofile('get_config_info:ssd_label_3g error!') return self.flashinfo['generation'] = '3g' if ret == 0 and output != '': for line in output : if line.find('Name') >= 0: #self.flashinfo['model'] = line.split(':')[1].strip() self.flashinfo['model'] = safe_split(line,':',1).strip() elif line.find('Size') >= 0: #self.flashinfo['size'] = line.split(':')[1].strip() self.flashinfo['size'] = safe_split(line,':',1).strip() elif line.find('Type') >= 0: #self.flashinfo['mediatype'] = line.split(':')[1].strip() self.flashinfo['mediatype'] = safe_split(line,':',1).strip() elif line.find('Devices') >= 0: #self.flashinfo['devicename'] = '_'.join(line.split(':')[1].split()) self.flashinfo['devicename'] = '_'.join(safe_split(line,':',1).split()) elif line.find('Controller FPGA VER')>=0 or line.find('Controller VER')>=0: tmp_str = safe_split(line,':',1).strip() if isinstance(tmp_str,str): tmp_int = int(tmp_str) if flag == 2: if tmp_int >30: self.flashinfo['version'] = '34NM' else: self.flashinfo['version'] = '50NM' elif flag == 3: if tmp_int >100: self.flashinfo['version'] = '25NM' else: self.flashinfo['version'] = '34NM'
def getconf(self): index = 0 # start with cpu1 cpu2 .... (tmpret, output) = saferun('%s -t processor'%gparas.dmidecode) for line in output: line = line.strip() if not line : continue if line.find('DMI type') > 0: index += 1 self.conf[index] = {} self.conf[index]['Temp'] = 0 self.conf[index]['Manu'] = 'NULL' self.conf[index]['Mode'] = 'NULL' self.conf[index]['Frequency'] = 'NULL' self.conf[index]['Corepercpu'] = 'NULL' elif line.startswith('Manufacturer') : #self.conf[index]['Manu'] = line.split(':')[1].strip() self.conf[index]['Manu'] = safe_split(line,':',1).strip() elif line.startswith('Version') : #self.conf[index]['Mode'] = '_'.join( line.split(':')[1].split() ) self.conf[index]['Mode'] = '_'.join( safe_split(line, ":", 1).split() ) elif line.startswith('Current Speed') : #self.conf[index]['Frequency'] = line.split(':')[1].strip() self.conf[index]['Frequency'] = safe_split(line, ":", 1).strip() elif line.startswith('Core Count') : #self.conf[index]['Corepercpu'] = line.split(':')[1].strip() self.conf[index]['Corepercpu'] = safe_split(line, ":", 1).strip() else: pass ## add for temperature read (tmpret, output) = saferun('%s 2> /dev/null'%gparas.readtemperature) if tmpret == 0: for line in output: if not line: continue try: cpunum, temp = line.split(':') cpunum = cpunum.strip() temp = temp.strip() index = int(cpunum) + 1 except ValueError: log.logtofile("Read temperature error!") if index <= self.num: try: temperature = int(temp) except ValueError: temperature = 0 if temperature >= 0: self.conf[index]['Temp'] = temperature else: self.conf[index]['Temp'] = 0 else: log.logtofile("The information of dmidecode and readtemperature is not consistency!") else: for line in output: line = line.strip() log.logtofile(line)
def _change_mcelogconf(self): # Change Mcelog configure file to the correct path lines = open( gparas.mcelogconf, 'r' ).readlines() fix = 0 for ind in range( len(lines) ): if lines[ind].startswith('logfile'): #if gparas.mcelogfall != lines[ind].split('=')[1].strip(): if gparas.mcelogfall != safe_split(lines[ind], '=', 1).strip(): fix = 1 lines[ind] = 'logfile = %s'%gparas.mcelogfall elif lines[ind].startswith('directory'): #if gparas.mcelogtrig != lines[ind].split('=')[1].strip(): if gparas.mcelogtrig != safe_split(lines[ind], '=', 1).strip(): fix = 1 lines[ind] = 'directory = %s' %gparas.mcelogtrig if fix == 1: open( gparas.mcelogconf,'w').writelines(lines)
def getpdinfo(self): Kversion = 0 # In 2.6.9,there may be some wrong # ??? (tmpret, kernel) = saferun('uname -r') for line in kernel: if line.find('2.6.32') >= 0: Kversion = 1 break (ret, output) = saferun('ls /dev/sd[a-z] | sort -u') if output != '': for line in output: line = line.strip() if not line : continue if line.startswith('/dev'): self.pdnum += 1 self.pdinfo[self.pdnum] = {} self.pdinfo[self.pdnum]['name'] = line self.pdinfo[self.pdnum]['model'] = 'NULL' self.pdinfo[self.pdnum]['sn'] = 'NULL' self.pdinfo[self.pdnum]['size'] = 'NULL' self.pdinfo[self.pdnum]['temperature'] = -1 if Kversion == 1: (tmpret, smart) = saferun('%s -i %s'%(gparas.smarttool,line)) if tmpret != 0: configinfo_log.logtofile('get_config_info:smartctrl tool error!') self.hbanum = 0 self.pdnum = 0 return for inline in smart: inline = inline.strip() if inline.startswith('Device Model:'): #self.pdinfo[self.pdnum]['model'] = inline.split(':')[1].strip() self.pdinfo[self.pdnum]['model'] = safe_split(inline,':',1).strip() elif inline.startswith('Serial Number:'): #self.pdinfo[self.pdnum]['sn'] = inline.split(':')[1].strip() self.pdinfo[self.pdnum]['sn'] = safe_split(inline,':',1).strip() elif inline.startswith('User Capacity:'): #self.pdinfo[self.pdnum]['size'] = inline.split(':')[1].strip() self.pdinfo[self.pdnum]['size'] = safe_split(inline,':',1).strip() """
def get_info(self): # Decide on the machine list support,just decide vm on this (ret, hout) = saferun('%s -t system' % gparas.dmidecode) if ret != 0: return ('NULL', 'vm') else: for line in hout: line = line.strip() if line.startswith('Manufacturer'): #self.machinfo['Vendor'] = line.split(": ")[1] self.machinfo['Vendor'] = safe_split(line, ": ", 1) elif line.startswith('Product Name'): #self.machinfo['Model'] = '_'.join( line.split(': ')[1].split() ) self.machinfo['Model'] = '_'.join( safe_split(line, ": ", 1).split()) elif line.startswith('Serial Number'): #self.machinfo['Sn'] = line.split(': ')[1] self.machinfo['Sn'] = safe_split(line, ": ", 1) return (self.machinfo['Vendor'].lower(), self.machinfo['Model'].lower())
def getcardinfo(self): if os.path.exists('/proc/mpt/summary'): (ret, output) = saferun('cat /proc/mpt/summary') else: (ret, output) = saferun('lspci 2>/dev/null| grep -i scsi') if output != '': for line in output: line = line.strip() if not line : continue if line.startswith('ioc') or line.find('LSI') >= 0 : self.hbanum += 1 self.hbainfo[self.hbanum] = {} if line.find('LSI') > 0: self.hbainfo[self.hbanum]['Manu'] = 'lsi' #self.hbainfo[self.hbanum]['Model'] = line.split(':')[1].split(',')[0] tmp_str = safe_split(line,':',1) self.hbainfo[self.hbanum]['Model'] = safe_split(tmp_str,',',0) else: self.hbainfo['Manu'] = 'NULL' self.hbainfo['Mode'] = 'NULL'
def get_status(self): reboot_flag,update_flag = gparas.run_cur_time('cpu') for i in range( self.cpuinfo['CpuNumber'] ): self.cpuinfo[i+1]['CacheErr'] = 'OK' if os.path.isfile(gparas.cmstatus): f = file(gparas.cmstatus) # meminfo = cPickle.load(f) # cpuinfo = cPickle.load(f) # logfileline = cPickle.load(f) # f.close() # for i in range( self.meminfo['DimmNumber'] ): # self.meminfo[i+1]['UE'] = meminfo[i+1]['UE'] # self.meminfo[i+1]['CE'] = meminfo[i+1]['CE'] # for i in range( self.cpuinfo['CpuNumber'] ): # self.cpuinfo[i+1]['CacheErr'] = cpuinfo[i+1]['CacheErr'] # self.logfileline = logfileline#caorui # else: # for i in range( self.cpuinfo['CpuNumber'] ): # self.cpuinfo[i+1]['CacheErr'] = 'OK' try: ceinfo = cPickle.load(f) cacheinfo = cPickle.load(f) logfileline = cPickle.load(f) f.close() cesn = [] for item in ceinfo.keys(): if ceinfo[item][0] != 0: cesn.append(ceinfo[item][1]) snvalid = 1 for i in range(self.meminfo['DimmNumber']-1): if self.meminfo[i+1]['UE'] != 'OK': continue for j in range(i+1, self.meminfo['DimmNumber']): if self.meminfo[j+1]['UE'] != 'OK': continue if self.meminfo[i+1]['SN'] == self.meminfo[j+1]['SN']: snvalid = 0 #if self.platform == ('hp','dl380'): if snvalid == 0: if reboot_flag != 1 and update_flag != 1: for i in range(self.meminfo['DimmNumber']): for item in ceinfo.keys(): if ceinfo[item][0] != 0 and self.meminfo[i+1]['locator'] == item: self.meminfo[i+1]['CE'] = ceinfo[item][0] else: for i in range(self.meminfo['DimmNumber']): for item in ceinfo.keys(): if ceinfo[item][0] != 0 and self.meminfo[i+1]['SN'] == ceinfo[item][1]: self.meminfo[i+1]['CE'] = ceinfo[item][0] if reboot_flag != 1 and update_flag != 1: for i in range( self.cpuinfo['CpuNumber'] ): self.cpuinfo[i+1]['CacheErr'] = cacheinfo[i] except: cpumemlog.logtofile('Read cmstatus error.', 1, 'CPU') """ Parse the latest log to get the current status """ #if not os.path.isfile(gparas.mcelogfile): #return True if self.platform not in [('ibm','x3650m5'), ('dell','r730'), ('sg','i630'),('sm','2u5')]: #(tmpret,tmp_file) = saferun("cat " + gparas.mcelogfall + " | wc -l ", 2 ,cpumemlog)#caorui #lineno = tmp_file[0] tmpfile = open(gparas.mcelogfall, 'r').readlines() lineno = len(tmpfile) #lineno = tmp_file.read().rstrip()#caorui try: parallax = lineno - int(self.logfileline)#caorui except: parallax = 0 saferun("tail -"+ str(parallax) + " " + gparas.mcelogfall + " > " + gparas.mcelogfile)#caorui self.logfileline = lineno#caorui log_file = open( gparas.mcelogfile ) while True: line = log_file.readline() if not line: break if "Trigger: " in line: if "CPU" in line: # tmp_line0 = line.split("CPU") # tmp_line1 = tmp_line0[1].split(" ") # cpu_number = tmp_line1[1] # tmp_line1 = safe_split(line, "CPU", 1) tmp_line1 = safe_split(line, "socket", 1) cpu_number = safe_split(tmp_line1, " ", 1) status = "Too Much Cache Err Exceed Threshold" try: self.cpuinfo[int(cpu_number)+1]['CacheErr'] = status except: return else: if "Uncorrected" in line or "uncorrected" in line: # tmp_line0 = line.split(" ") # count = tmp_line0[-3] count = safe_split(line, " ", -3) line = log_file.readline() if "?" in line: continue if "Location" in line: # tmp_line1 = line.split("SOCKET:") # tmp_socket = tmp_line1[1].split(" ") # socket = tmp_socket[0] tmp_socket = safe_split(line, "SOCKET:", 1) socket = safe_split(tmp_socket, " ", 0) # tmp_line2 = line.split("CHANNEL:") # tmp_channel = tmp_line2[1].split(" ") # channel = tmp_channel[0] tmp_channel = safe_split(line, "CHANNEL:", 1) channel = safe_split(tmp_channel, " ", 0) # tmp_line3 = line.split("DIMM:") # tmp_dimm = tmp_line3[1].split(" ") # dimm = tmp_dimm[0] tmp_dimm = safe_split(line, "DIMM:", 1) dimm = safe_split(tmp_dimm, " ", 0) location = socket + "/" + channel + "/" + dimm item = self._lookup_relation(location,self.platform) if item == "NULL": #print "the physical dimm %s (UE: %s) is not existed." %(location, count) cpumemlog.logtofile('the physical dimm %s (UE: %s) is not existed.' %(location, count), 1, 'CPU') else: #self.meminfo[item]['UE'] = count + " UEs" self.meminfo[item]['UE'] = 'This dimm has uce error' else: tmp_line0 = line.split(" ") try: count = int(tmp_line0[-3]) except: count = 0 if count >= 500: line = log_file.readline() if "?" in line: continue if "Location" in line: # tmp_line1 = line.split("SOCKET:") # tmp_socket = tmp_line1[1].split(" ") # socket = tmp_socket[0] tmp_socket = safe_split(line, "SOCKET:", 1) socket = safe_split(tmp_socket, " ", 0) # tmp_line2 = line.split("CHANNEL:") # tmp_channel = tmp_line2[1].split(" ") # channel = tmp_channel[0] tmp_channel = safe_split(line, "CHANNEL:", 1) channel = safe_split(tmp_channel, " ", 0) # tmp_line3 = line.split("DIMM:") # tmp_dimm = tmp_line3[1].split(" ") # dimm = tmp_dimm[0] tmp_dimm = safe_split(line, "DIMM:", 1) dimm = safe_split(tmp_dimm, " ", 0) location = socket + "/" + channel + "/" + dimm item = self._lookup_relation(location,self.platform) if item == "NULL": #print "the physical dimm %s (CE: %d) is not existed." %(location, count) cpumemlog.logtofile('the physical dimm %s (CE: %d) is not existed.' %(location, count), 1, 'CPU') else: self.meminfo[item]['CE'] = count #os.system("cat %s >> %s" %(gparas.mcelogfile,gparas.mcelogfall) ) #os.remove( gparas.mcelogfile ) log_file.close()
def getmeminfo(self, monitorflag): #Get the DIMM info by dmidecode(SMBIOS) (ret, hout) = saferun('%s -t memory' % gparas.dmidecode) # dimflag: DMI type is 17 or not; dimnum: the number of dimm; mem_valid: the information of dimm is valid or not dimflag = 0 dimnum = 0 mem_valid = 0 for line in hout: if not line: continue line = line.strip() if line.find('DMI type 17') >= 0: dimflag = 1 dimnum += 1 # Append the last dimm info to meminfo if mem_valid == 1: self.goodmeminfo.append(dimm_info) elif mem_valid == 2: dimm_info['UE'] = 'uce err' dimm_info['CE'] = 0 self.badmeminfo_dmi.append(dimm_info) # Init the dimm info for better output in abnomal situation dimm_info = { 'locator': 'NULL', 'Speed': 'NULL', 'Cap': 'NULL', 'Type': 'NULL', 'SN': 'NULL', 'Model': 'NULL', 'l_loc': 'NULL', 'UE': 'OK', 'CE': 0 } mem_valid = 0 continue # Analyze the dimm information only when the section is type 17 if dimflag == 1: # Break the analysis when the "Data width" or "Size" is invalid if line.startswith('Data Width'): try: size = int(line.split()[2]) except ValueError: dimflag = 0 dimnum -= 1 continue if size < 32: dimflag = 0 dimnum -= 1 elif line.startswith('Size'): try: size = int(line.split()[1]) except ValueError: dimflag = 0 dimnum -= 1 continue mem_valid = 1 dimm_info['Cap'] = size / 1024 elif line.startswith('Locator'): dimmlocator = safe_split(line, ": ", 1) dimmkeys = dimmlocator.split(" ") if len(dimmkeys) >= 1: dimmlocator = dimmkeys[0].strip() for i in range(1, len(dimmkeys)): dimmlocator = dimmlocator + '_' + dimmkeys[ i].strip() dimm_info['locator'] = dimmlocator #print dimmlocator #dimm_info['locator'] = line.split(": ")[1] elif line.startswith('Speed'): try: size = int(line.split()[1]) except ValueError: if mem_valid == 0: dimflag = 0 dimnum -= 1 continue dimm_info['Speed'] = size if mem_valid == 0: mem_valid = 2 elif line.startswith('Manufacturer'): try: dimm_info['Type'] = line.split()[1] except IndexError: continue elif line.startswith('Serial Number'): try: dimm_info['SN'] = line.split()[2] except IndexError: continue elif line.startswith('Part'): try: dimm_info['Model'] = line.split()[2] except IndexError: dimflag = 0 dimflag = 0 # Append the last dimm info to meminfo if mem_valid == 1: self.goodmeminfo.append(dimm_info) elif mem_valid == 2: dimm_info['UE'] = 'uce err' dimm_info['CE'] = 0 self.badmeminfo_dmi.append(dimm_info) (ret, hout) = saferun('free') for line in hout: if not line: continue line = line.strip() if line.startswith('Mem'): try: os_cap = int(line.split()[1]) except ValueError: os_cap = 0 self.meminfo['Os_Cap'] = (os_cap / 1024 / 1024 / 4 + 1) * 4 (ret, hout) = saferun('%s -t processor' % gparas.dmidecode) cpu_num = 0 for line in hout: if not line: continue line = line.strip() if line.startswith('Manufacturer'): #self.cpuinfo['Vendor'] = '_'.join( line.split(':')[1].split() ) self.cpuinfo['Vendor'] = '_'.join( safe_split(line, ":", 1).split()) elif line.startswith('Version'): #self.cpuinfo['Model'] = '_'.join( line.split(':')[1].split() ) self.cpuinfo['Model'] = '_'.join( safe_split(line, ":", 1).split()) elif line.startswith('Core Count'): #self.cpuinfo['Corepercpu'] = line.split(':')[1].strip() self.cpuinfo['Corepercpu'] = safe_split(line, ":", 1).strip() cpu_num += 1 self.cpuinfo['CpuNumber'] = cpu_num for i in range(cpu_num): self.cpuinfo[i + 1] = {} #Finish the dmidecode(SMBIOS) infomation Parse #DimmNumber is the Good memory number detected by dmidecode #Append the Bad Memory info to the Good ones #BadDimmNumber is the Bad memory number detected by dmidecode if monitorflag == 'false' or self.platvalid == 'false' or len( self.goodmeminfo) < 1: self.meminfo['Cap'] = 0 self.meminfo['DimmNumber'] = len(self.goodmeminfo) for i in range(self.meminfo['DimmNumber']): self.meminfo[i + 1] = self.goodmeminfo[i] self.meminfo['Cap'] += self.goodmeminfo[i]['Cap'] for i in range(len(self.goodmeminfo)): self.meminfo[i + 1] = self.goodmeminfo[i] return self.cpuinfo, self.meminfo #Could not get DIMM and CPU status if the machine is not supported # if self.platform[0] == 'unknow' or self.platform[1] == 'unknow': # #Fill the meminfo structure # self.meminfo['Cap'] = 0 # self.meminfo['DimmNumber'] = len(self.goodmeminfo) # for i in range( self.meminfo['DimmNumber'] ): # self.meminfo[i+1] = self.goodmeminfo[i] # self.meminfo[i+1]['Status'] = 'NULL' # self.meminfo['Cap'] += self.goodmeminfo[i]['Cap'] # for i in range( self.cpuinfo['CpuNumber'] ): # self.cpuinfo[i+1]['Status'] = 'NULL' # return self.cpuinfo, self.meminfo self.dimm_check() #Fill the Good Dimm Info self.meminfo['Cap'] = 0 self.meminfo['DimmNumber'] = len(self.goodmeminfo) for i in range(self.meminfo['DimmNumber']): self.meminfo[i + 1] = self.goodmeminfo[i] self.meminfo[i + 1]['UE'] = 'OK' self.meminfo[i + 1]['CE'] = 0 self.meminfo['Cap'] += self.goodmeminfo[i]['Cap'] #Append Bad Dimm Info to Good Dimm Info # self.badmeminfo = [] # if self.goodmeminfo_b: # self.meminfo['BadDimmNumber'] += len(self.goodmeminfo_b) # for meminfo in self.goodmeminfo_b: # meminfo['UE'] = 'has uce error' # self.badmeminfo.append(meminfo) if self.dimm_bad_diff: self.meminfo['BadDimmNumber'] += len(self.dimm_bad_diff) for l_loc in self.dimm_bad_diff: badmeminfo = { 'locator': 'NULL', 'Speed': 'NULL', 'Cap': 'NULL', 'Type': 'NULL', 'SN': 'NULL', 'Model': 'NULL', 'l_loc': 'NULL', 'UE': 'OK', 'CE': 0 } badmeminfo['locator'] = machine_map[self.platform][l_loc] badmeminfo['UE'] = 'uce err' badmeminfo['CE'] = 0 self.badmeminfo.append(badmeminfo) if self.badmeminfo_dmi: for i in self.badmeminfo_dmi: flag = 0 for loc in self.badmeminfo: #if i['locator'] == loc['locator']: if i['locator'].find( loc['locator']) >= 0 or loc['locator'].find( i['locator']) >= 0: flag = 1 break if flag == 0: self.meminfo['BadDimmNumber'] += 1 self.badmeminfo.append(i) if self.badmeminfo: ind = self.meminfo['DimmNumber'] for i in range(len(self.badmeminfo)): self.meminfo[ind + i + 1] = self.badmeminfo[i] return self.cpuinfo, self.meminfo
def __init__(self): self.meminfo = {} self.badmeminfo = [] self.badmeminfo_dmi = [] self.goodmeminfo = [] self.cpuinfo = {} self.dimm_diff = [] self.logfileline = 0 self.machinfo = machinfo() self.platform = self.machinfo.get_platform() self.platvalid = self.machinfo.check_platform_support('cpu') self.meminfo['BadDimmNumber'] = 0 savememinfo = [] if not os.path.isfile(gparas.allmemfile) or os.path.getsize( gparas.allmemfile) == 0: # Save manu and model of the memory (ret, hout) = saferun('%s -t memory' % gparas.dmidecode) # dimflag: DMI type is 17 or not; dimnum: the number of dimm; mem_valid: the information of dimm is valid or not dimflag = 0 dimnum = 0 mem_valid = 0 for line in hout: if not line: continue line = line.strip() if line.find('DMI type 17') >= 0: dimflag = 1 dimnum += 1 # Append the last dimm info to meminfo if mem_valid == 1: savememinfo.append(dimm_info) # Init the dimm info for better output in abnomal situation dimm_info = { 'locator': 'NULL', 'Type': 'NULL', 'Model': 'NULL' } mem_valid = 0 continue # Analyze the dimm information only when the section is type 17 if dimflag == 1: # Break the analysis when the "Data width" or "Size" is invalid if line.startswith('Locator'): #dimmlocator = line.split(": ")[1] dimmlocator = safe_split(line, ": ", 1) dimmkeys = dimmlocator.split(" ") if len(dimmkeys) >= 1: dimmlocator = dimmkeys[0].strip() for i in range(1, len(dimmkeys)): dimmlocator = dimmlocator + '_' + dimmkeys[ i].strip() dimm_info['locator'] = dimmlocator #print dimmlocator #dimm_info['locator'] = line.split(": ")[1] mem_valid = 1 elif line.startswith('Manufacturer'): try: dimm_info['Type'] = line.split()[1] except IndexError: continue elif line.startswith('Part'): try: dimm_info['Model'] = line.split()[2] except IndexError: dimflag = 0 dimflag = 0 # Append the last dimm info to meminfo if mem_valid == 1: savememinfo.append(dimm_info) f = file(gparas.allmemfile, 'w') cPickle.dump(savememinfo, f) f.close()
def getpdinfo(self): #For every Physical disk, we get information about: #Slot,model,sn,interface,size if self.raidinfo['manu'] != 'hba' and self.raidinfo['manu'] == 'pmc': index = 0 count = 0 #this is for self.ldinfo[index]['pdnum'] (ret, output) = saferun('%s ctrl slot=%s pd all show detail 2>/dev/null' % (gparas.pmctool,self.raidinfo['slot'])) if ret != 0: configinfo_log.logtofile('get_config_info:hpacucli tool error!') self.raidinfo['ldnum'] = 0 self.raidinfo['pdnum'] = 0 for line in output: line = line.strip() if line.startswith('physicaldrive'): index += 1 self.pdinfo[index] = {} #self.pdinfo[index]['slot'] = line.split()[1].strip() self.pdinfo[index]['slot'] = safe_split(line,'',1).strip() #count = int(self.pdinfo[index]['slot'].split(':')[1]) # This is the every ld's pd port id count = int(safe_split(self.pdinfo[index]['slot'],':',1)) self.ldinfo[count]['pdnum'] += 1 #self.pdinfo[index]['slot'] = self.pdinfo[index]['slot'].split(':')[2].strip() # revalue it self.pdinfo[index]['slot'] = safe_split(self.pdinfo[index]['slot'],':',2).strip() # manu:HP is correct or not ? self.pdinfo[index]['manuinfo'] = 'HP' self.pdinfo[index]['model'] = 'NULL' self.pdinfo[index]['media'] = 'NULL' self.pdinfo[index]['interface'] = 'NULL' self.pdinfo[index]['size'] = 'NULL' self.pdinfo[index]['sn'] = 'NULL' self.pdinfo[index]['temperature'] = -1 elif line.startswith('Model'): #self.pdinfo[index]['model'] = '_'.join(line.split(':')[1].split()) #self.pdinfo[index]['model'] = '_'.join(safe_split(line,':',1).split()) try: self.pdinfo[index]['model'] = safe_split(line,': ',1)[8:].strip() except: self.pdinfo[index]['model'] = '_'.join(safe_split(line,':',1).split()) elif line.startswith('Interface Type'): #self.pdinfo[index]['interface'] = line.split(':')[1].strip() self.pdinfo[index]['interface'] = safe_split(line,':',1).strip() elif line.startswith('Size'): #self.pdinfo[index]['size'] = line.split(':')[1].strip() self.pdinfo[index]['size'] = safe_split(line,':',1).strip() elif line.startswith('Serial Number'): self.pdinfo[index]['sn'] = line.split(':')[1].strip() elif line.startswith('Current Drive Temperature') or line.startswith('Current Temperature'): try : #temp = int(line.split(':')[1].split()[0].strip()) tmp_str = safe_split(line,':',1) temp = int(safe_split(tmp_str,'',0).strip()) except: temp = -1 self.pdinfo[index]['temperature'] = temp elif self.raidinfo['manu'] != 'hba' and self.raidinfo['manu'] == 'lsi': index = 0 (ret,output) = saferun('%s -pdlist -aall -NoLog 2>/dev/null' %gparas.lsitool) if ret != 0: configinfo_log.logtofile('get_config_info:megacli tool error!') self.raidinfo['ldnum'] = 0 self.raidinfo['pdnum'] = 0 return for line in output: line = line.strip() if line.startswith('Enclosure Device ID'): index += 1 self.pdinfo[index] = {} self.pdinfo[index]['manuinfo'] = 'NULL' self.pdinfo[index]['model'] = 'NULL' self.pdinfo[index]['media'] = 'NULL' self.pdinfo[index]['interface'] = 'NULL' self.pdinfo[index]['size'] = 'NULL' self.pdinfo[index]['sn'] = 'NULL' self.pdinfo[index]['temperature'] = -1 elif line.startswith('Slot Number'): #self.pdinfo[index]['slot'] = line.split(':')[1].strip() self.pdinfo[index]['slot'] = safe_split(line,':',1).strip() elif line.startswith('PD Type'): #self.pdinfo[index]['interface'] = line.split(':')[1].strip() self.pdinfo[index]['interface'] = safe_split(line,':',1).strip() elif line.startswith('Media Type'): #self.pdinfo[index]['media'] = '_'.join(line.split(':')[1].split()) tmp_str = safe_split(line,':',1) self.pdinfo[index]['media'] = '_'.join(tmp_str.split()) if self.pdinfo[index]['media'] == "Solid_State_Device": if inquary.find("INTEL") >= 0: self.pdinfo[index]['manuinfo'] = "Intel" else: self.pdinfo[index]['manuinfo'] = "NULL" elif line.startswith('Raw Size'): #self.pdinfo[index]['size'] = line.split(':')[1].split()[0] + line.split(':')[1].split()[1] tmp_str = safe_split(line,':',1) self.pdinfo[index]['size'] = safe_split(tmp_str,'',0) + safe_split(tmp_str,'',1) elif line.startswith('Inquiry Data'): #inquary = line.split(': ')[1] inquary = safe_split(line,': ',1) if self.pdinfo[index]['interface'] == "SATA": try: self.pdinfo[index]['model'] = inquary[20:60:1].strip() self.pdinfo[index]['sn'] = inquary[0:20:1].strip() except: self.pdinfo[index]['model'] = "NULL" self.pdinfo[index]['sn'] = "NULL" elif self.pdinfo[index]['interface'] == "SAS": try : self.pdinfo[index]['manuinfo'] = inquary[0:8:1].strip() self.pdinfo[index]['model'] = inquary[8:24:1].strip() #sn only get 8 bytes #in fact sn is 12 bytes ???? self.pdinfo[index]['sn'] = inquary[28:36:1].strip() except: self.pdinfo[index]['manuinfo'] = "NULL" self.pdinfo[index]['model'] = "NULL" self.pdinfo[index]['sn'] = "NULL" elif line.startswith('Drive Temperature'): try: #temp = int(line.split(':')[1].split('C')[0].strip()) tmp_str = safe_split(line,':',1) temp = int(safe_split(tmp_str,'C',0).strip()) except: temp = -1 self.pdinfo[index]['temperature'] = temp
def getldinfo(self): # For every vitual disk, we get information about: # Size, raidlevel,mountpoint(not supported by Megacli) if self.raidinfo['manu'] != 'hba' and self.raidinfo['manu'] == 'pmc': index = 0 (ret, output) = saferun('%s ctrl slot=%s ld all show detail 2>/dev/null' % (gparas.pmctool,self.raidinfo['slot'])) if ret != 0: configinfo_log.logtofile('get_config_info:hpacucli tool error!') self.raidinfo['ldnum'] = 0 self.raidinfo['pdnum'] = 0 return for line in output: line = line.strip() if line.startswith('Logical Drive:'): index += 1 self.ldinfo[index] = {} self.ldinfo[index]['size'] = 'NULL' self.ldinfo[index]['level'] = 'NULL' self.ldinfo[index]['diskname'] = 'NULL' self.ldinfo[index]['pdnum'] = 0 # This is count in next function if line.startswith('Size:'): #self.ldinfo[index]['size'] = line.split(':')[1].strip() self.ldinfo[index]['size'] = safe_split(line,':',1).strip() elif line.startswith('Fault Tolerance:'): #self.ldinfo[index]['level'] = line.split(':')[1].strip() self.ldinfo[index]['level'] = safe_split(line,':',1).strip() elif line.startswith('Disk Name'): #self.ldinfo[index]['diskname'] = line.split(':')[1].strip() self.ldinfo[index]['diskname'] = safe_split(line,':',1).strip() elif line.startswith('Mount Points:'): #self.ldinfo[index]['mnt'] = line.split(':')[1].strip() self.ldinfo[index]['mnt'] = safe_split(line,':',1).strip() elif self.raidinfo['manu'] != 'hba' and self.raidinfo['manu'] == 'lsi': index = 0 (ret, output) = saferun('%s -LDInfo -lall -aAll 2>/dev/null'%gparas.lsitool) if ret != 0: configinfo_log.logtofile('get_config_info:megacli tool error!') self.raidinfo['ldnum'] = 0 self.raidinfo['pdnum'] = 0 return for line in output: line =line.strip() if line.startswith('Virtual Drive') or line.startswith('Virtual Disk'): index += 1 self.ldinfo[index] = {} #self.ldinfo[index]['num'] = int(line.split(':')[1].split()[0].strip()) tmp_str = safe_split(line,':',1).strip() self.ldinfo[index]['num'] = int(safe_split(tmp_str,'',0).strip()) self.ldinfo[index]['size'] = 'NULL' self.ldinfo[index]['level'] = 'NULL' self.ldinfo[index]['mnt'] = 'NULL' elif line.startswith('RAID Level'): #self.ldinfo[index]['level'] = line.split(':')[1].strip() self.ldinfo[index]['level'] = safe_split(line,':',1).strip() elif line.startswith('Size'): #self.ldinfo[index]['size'] = line.split(':')[1].strip() self.ldinfo[index]['size'] = safe_split(line,':',1).strip() for i in range(1,index): (ret, output) = saferun('%s -LdPdInfo -a%d | grep "Enclosure Device ID" | wc -l'%(gparas.lsitool,self.ldinfo[i]['num'])) if ret != 0: configinfo_log.logtofile('get_config_info:megacli tool error!') self.raidinfo['ldnum'] = 0 self.raidinfo['pdnum'] = 0 return self.ldinfo[i]['pdnum'] = int(output[0])
def getraidinfo(self): self.raidinfo['sn'] = 'NULL' self.raidinfo['slot'] = 'NULL' self.raidinfo['ldnum'] = 0 self.raidinfo['pdnum'] = 0 if self.raidinfo['manu'] != 'hba' and self.raidinfo['manu'] == 'pmc': (ret, output) = saferun('%s ctrl all show detail 2>/dev/null' %gparas.pmctool) if ret != 0: configinfo_log.logtofile('get_config_info:hpacucli tool error!') return for line in output: line = line.strip() if line.startswith('Slot'): #self.raidinfo['slot'] = line.split(':')[1].strip() self.raidinfo['slot'] = safe_split(line,':',1).strip() elif line.startswith('Serial Number:'): #self.raidinfo['sn'] = line.split(':')[1].strip() self.raidinfo['sn'] = safe_split(line,':',1).strip() (ret, output) = saferun('%s ctrl slot=%s ld all show detail | grep -i "logical drive label" | wc -l ' % (gparas.pmctool,self.raidinfo['slot'])) if ret != 0: configinfo_log.logtofile('get_config_info:hpacucli tool error!') return if output: try : number = int(output[0]) except : number = 0 self.raidinfo['ldnum'] = number (ret, output) = saferun('%s ctrl slot=%s pd all show detail | grep -i "physicaldrive" | wc -l ' % (gparas.pmctool,self.raidinfo['slot'])) if ret != 0: configinfo_log.logtofile('get_config_info:hpacucli tool error!') return if output: try : number = int(output[0]) except : number = 0 self.raidinfo['pdnum'] = number elif self.raidinfo['manu'] != 'hba' and self.raidinfo['manu'] == 'lsi': (ret, output) = saferun('%s -LDGetNum -aAll 2>/dev/null | grep -iv "exit code"'%gparas.lsitool) if ret != 0: configinfo_log.logtofile('get_config_info:megacli tool error!') return for line in output: line = line.strip() if not line : continue else: try : #num = int(line.split(':')[1].strip()) num = int(safe_split(line,':',1).strip()) except : num = 0 if num : self.raidinfo['ldnum'] += num (ret, output) = saferun('%s -PDGetNum -aAll | grep -iv "exit code"'%gparas.lsitool) if ret != 0: configinfo_log.logtofile('get_config_info:megacli tool error!') return for line in output: line = line.strip() if not line : continue else: try : #num = int(line.split(':')[1].strip()) num = int(safe_split(line,':',1).strip()) except: num = 0 if num : self.raidinfo['pdnum'] += int(num)