Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- RAID_TYPE_HARDWARE = 0
- RAID_TYPE_SOFTWARE = 1
- RAID_MDSTAT_PATH = "/Users/jgabriel/Documents/Python/files_res/mdstat"
- def get_soft_raid_map():
- output = []
- raid_device, raid_type, raid_status = None
- for line in open(RAID_MDSTAT_PATH, "r"):
- if len(line) == 0:
- continue
- if line.match('Personalities'):
- continue
- line = line.strip()
- parts = line.split()
- if line.match('blocks'):
- raid_status = parts[-1]
- output.append([raid_device, raid_type, raid_status])
- else:
- raid_device = "/dev/" + parts[0]
- raid_type = parts[3]
- raid_status = None
- return output
- def get_raid_type():
- firstline = open(RAID_MDSTAT_PATH, "r").read().strip()
- if firstline.match('[raid'):
- return RAID_TYPE_SOFTWARE
- else:
- return RAID_TYPE_HARDWARE
- if __name__ == '__main__':
- raid_type = get_raid_type()
- if raid_type == RAID_TYPE_HARDWARE:
- print "hardware raid detected."
- else:
- print "software raid detected."
- for device, tipo, status in get_soft_raid_map():
- print "device=(%s), tipo=(%s), status=(%s)" % (device, tipo, status)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement