Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.40 KB | None | 0 0
  1. #!/usr/bin/python
  2. import re
  3.  
  4. RAID_HW = 0
  5. RAID_SW = 1
  6. MDSTAT_PATH   = "/Users/jgabriel/Documents/Python/files_res/mdstat"
  7.  
  8. def get_soft_raid_map():
  9.     saida = []
  10.     deviceinfo = []
  11.     raid_device = raid_type = raid_status = None
  12.     for line in open(MDSTAT_PATH, "r"):
  13.         line = line.strip()
  14.         if len(line) == 0:
  15.             continue
  16.         parts = line.split()
  17.         if  re.search('blocks',line):
  18.             raid_status = parts[-1]
  19.             deviceinfo.append(raid_status)
  20.             continue
  21.         if re.search('active',line):
  22.             raid_device = "/dev/" + parts[0]
  23.             raid_type = parts[3]
  24.             deviceinfo.append(raid_device)
  25.             deviceinfo.append(raid_type)
  26.             saida.append(deviceinfo)
  27.             deviceinfo = []
  28.     return saida
  29.  
  30. def qual_eh_o_raid():
  31.     for jao in open(MDSTAT_PATH, "r"):
  32.         jao = jao.strip()
  33.         if len(jao) == 0:
  34.             continue
  35.         if re.search('raid', jao):
  36.             return RAID_SW
  37.         else:
  38.             return RAID_HW
  39. if __name__ == '__main__':
  40.     print get_soft_raid_map()
  41. #    raid_type = qual_eh_o_raid()
  42. #    if raid_type == RAID_HW:
  43. #        print "hardware raid detected."
  44. #    else:
  45. #        print "software raid detected."
  46. #        for device, tipo, status in get_soft_raid_map():
  47. #            print "device=(%s), tipo=(%s), status(%s)" % (device, tipo, status)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement