@tony-yin
2017-09-29T14:19:09.000000Z
字数 1845
阅读 908
Magicloud
Script
clean_disks.py
python clean_disks.py [disk_name1, disk_name2 ...]
python clean_disks.py
sdb
的分区
python clean_disks.py sdb
sdb
和sdc
的分区
python clean_disks.py sdb sdc
import sys
from mcs3.command import do_cmd
def clean_disk(disk_name):
print 'disk: {} clean start ...'.format(disk_name)
do_cmd('sgdisk -Zog /dev/{}'.format(disk_name))
print 'disk: {} clean done ...'.format(disk_name)
mount_info = do_cmd('mount')
sys_disk_name = mount_info[5:8]
if len(sys.argv) > 1:
disks = sys.argv[1:]
for disk_name in disks:
if disk_name == sys_disk_name:
print '{} is system disk, can\'t be clean!'.format(disk_name)
else:
clean_disk(disk_name)
else:
all_disks = do_cmd('lsblk').splitlines()
for disk in all_disks:
if (disk.startswith('sd')):
disk_name = disk.split()[0]
if disk_name != sys_disk_name:
clean_disk(disk_name)
create_partitions.py
python create_partitions.py size num [disk_name1, disk_name2 ...]
, size
为分区大小,num
为分区数sdb
和sdc
分别都创建两个大小为100G
的分区
python create_partitions.py 100G 2 sdb sdc
10G
的分区
python create_partitions.py 10G 3
sdc
创建四个大小为1T
的分区
python create_partitions.py 1024G 4 sdc
import sys
from mcs3.command import do_cmd
size = sys.argv[1]
num = sys.argv[2]
mount_info = do_cmd('mount')
sys_disk_name = mount_info[5:8]
def parted_disks(num, size, disk):
for i in range(int(num)):
do_cmd('sgdisk -n {}:0:+{} /dev/{}'.format(i+1, size, disk))
print 'disk {} partition {} done ...'.format(disk, i+1)
if len(sys.argv) > 3:
disks = sys.argv[3:]
for disk in disks:
if disk == sys_disk_name:
print '{} is system disk, can\'t be parted!'.format(disk)
else:
parted_disks(num, size, disk)
else:
all_disks = do_cmd('lsblk').splitlines()
for disk in all_disks:
if (disk.startswith('sd')):
disk_name = disk.split()[0]
if disk_name != sys_disk_name:
parted_disks(num, size, disk)