Advertisement
TShiva

Удаление существующих raid-ов и lvm-ов

Mar 24th, 2017
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.16 KB | None | 0 0
  1. import re
  2. import subprocess
  3. import os
  4.  
  5. def main():
  6.     clear_raids()
  7.     clear_lvm()
  8.  
  9. def clear_raids():
  10.     raids = str(subprocess.check_output('cat /proc/mdstat', shell=True))
  11.     cock = raids.find('md')
  12.     my_raids = raids[cock:]
  13.     new_raids = my_raids.split('[U' or '[_')
  14.     for string in new_raids:
  15.         md = re.findall(r'(md\d+)', string)
  16.         os.system('mdadm -S /dev/' + ''.join(md))
  17.     raid = re.findall(r'(\w+\[\d+\])', my_raids)
  18.     names = re.findall(r'[a-zA-Z]+', ''.join(raid))
  19.     for name in names:
  20.         sname = ''.join(name)
  21.         os.system('mdadm --zero-superblock /dev/' + sname)
  22. def clear_lvm():
  23.  
  24.     lvms = str(subprocess.check_output('pvdisplay', shell=True))
  25.     new_lvms = lvms.split('--- Physical volume ---')
  26.     for lvm in new_lvms:
  27.         #pv_name = re.findall(r'/\w+/\w+',lvm)
  28.         VG_name=lvm.find('VG Name')
  29.         PV_size = lvm.find('PV Size')
  30.         my_lvm = lvm[VG_name:PV_size]
  31.         lvm_name=re.findall(r'(\w+\\n)', ''.join(my_lvm))
  32.         slvm = ''.join(lvm_name).strip('\\n')
  33.         os.system('lvremove '+slvm)
  34.         os.system('vgremove '+slvm)
  35.  
  36.  
  37. if __name__ == '__main__':
  38.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement