testing local clone hook

This commit is contained in:
brent s 2017-10-10 21:19:31 -04:00
parent 8add03fadb
commit 7bc6ea3408

42
storage/mdadm/status.py Executable file
View File

@ -0,0 +1,42 @@
#!/usr/bin/env python3

import mdstat # apacman -S python-mdstat
import os
import subprocess

# also requires parted to be installed

def getMdstat():
mds = {}
with open(os.devnull, 'w') as DEVNULL:
_devlines = subprocess.run(['mdadm',
'--detail',
'--scan'],
stderr = DEVNULL,
stdout = subprocess.PIPE).stdout.decode('utf-8')
for m in _devlines.split():
l = m.split()
dev = os.path.split(l[1])[-1]
mds[dev] = {'device': l[1].strip(),
'metadata': l[2].split('=')[1].strip(),
'host': l[3].split('=')[1].split(':')[0].strip(),
'name': l[3].split('=')[1].split(':')[1].strip(),
'uuid': l[4].split('=')[1].strip()}
_md = mdstat.parse()['devices'][dev]
mds[dev]['status'] = ('active' if _md['active'] else 'inactive')
mds[dev]['members'] = _md['disks']
if _md['resync']:
mds[dev]['status'] = _md['resync']
# TODO: I STOPPED HERE

def userChk():
# Needs to be run as root/with sudo, because we need to use mdadm --detail --scan etc.
if os.geteuid() != 0:
raise PermissionError('This script must be run with root privileges.')

def main():
userChk()
getMdstat()

if __name__ == '__main__':
main()