Advertisement
Guest User

Untitled

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