Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- import subprocess
- import os
- '''
- Очистка системы от таргетов,лунов,прикрученных к ним устройств, lvm-ов,raid-ов и bcache
- '''
- def main():
- clear_scst()
- clear_bcache_backing_device()
- clear_lvm()
- clear_raids()
- clear_bcache_caching_device()
- def clear_raids():
- raids = str(subprocess.check_output('cat /proc/mdstat', shell=True))
- cock = raids.find('md')
- my_raids = raids[cock:]
- new_raids = my_raids.split('[U' or '[_')
- for string in new_raids:
- md = re.findall(r'(md\d+)', string)
- os.system('mdadm -S /dev/' + ''.join(md))
- raid = re.findall(r'(\w+\[\d+\])', my_raids)
- names = re.findall(r'[a-zA-Z]+', ''.join(raid))
- for name in names:
- sname = ''.join(name)
- os.system('mdadm --zero-superblock /dev/' + sname)
- def clear_lvm():
- lvms = str(subprocess.check_output('pvdisplay', shell=True))
- new_lvms = lvms.split('--- Physical volume ---')
- for lvm in new_lvms:
- #pv_name = re.findall(r'/\w+/\w+',lvm) # заготовка для парсинга лунов
- VG_name=lvm.find('VG Name')
- PV_size = lvm.find('PV Size')
- my_lvm = lvm[VG_name:PV_size]
- lvm_name=re.findall(r'(\w+\\n)', ''.join(my_lvm))
- slvm = ''.join(lvm_name).strip('\\n')
- os.system('lvremove '+slvm)
- os.system('vgremove '+slvm)
- def clear_scst():
- #targets = str(subprocess.check_output('scstadmin -list_target', shell=True))
- #targets = 'Driver Target -------------------------------------- iscsi iqn.2015-05.iscsi.lan:tgt copy_manager copy_manager_tgt '
- #target_name = re.findall(r'iqn\.\d+\-\d+\.(\w+.)*\:(\w+|\d+|\.|\-)+',targets) # заготовка для парсинга имён таргетов
- os.system('service scst restart')
- def clear_bcache_backing_device():
- all_devices_for_parse = str(subprocess.check_output('lsblk', shell=True))
- backing_devices = set(re.findall(r'bcache\d+', all_devices_for_parse))
- for backing_device in backing_devices:
- os.system('echo 1 > /sys/block/'+backing_device+'/bcache/stop')
- lvms = set(re.findall(r'\w+-lv\d+', all_devices_for_parse))
- for lvm in lvms:
- new_lvm = lvm.replace('-', '/')
- os.system('wipefs -a /dev/'+new_lvm)
- def clear_bcache_caching_device():
- all_devices_for_parse = str(subprocess.check_output('lsblk', shell=True))
- block_names=['sda', 'sdb', 'sdc', 'sdd', 'vdd', 'vdc', 'vdb']
- for block_name in block_names:
- print(block_name)
- csetuuid = str(subprocess.check_output('bcache-super-show /dev/'+block_name+' | grep cset.uuid | cut -c 12-48', shell=True))[2:-3]
- print(csetuuid)
- os.system('echo 1 > /sys/fs/bcache/'+csetuuid+'/stop')
- os.system('wipefs -a /dev/'+block_name)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement