#coding=utf8
import subprocess
# 执行命令
def _run_cmd(cmd, wait=False):
prc = subprocess.Popen(args=cmd, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, shell=True)
if wait:
prc.wait()
return prc
# 获得执行命令后的标准输出
def _get_output(cmd):
prc = _run_cmd(cmd)
lines = prc.stdout.readlines()
if not lines:
lines = prc.stderr.readlines()
return lines
def add_disk(disk=None,**kwargs):
path=None
if not disk:
for i in range('a','z'):
res = _get_output('export LANG=en_US;fdisk -l /dev/sd{}|grep "Disk identifier:"'.format(i))
print res
if 'Disk identifier: 0x00000000' in ''.join(res):
path = '/dev/sd{}'.format(i)
break
print path
if not path:
path=disk
if not path:
print path + '磁盘扩展失败'
return
with open('/tmp/add_disk.sh
','w') as f:
f.write('fdisk {} <<EOF n p 1 w EOF'.format(path))
_run_cmd('sh /tmp/add_disk.sh
', wait=True)
res = _get_output('export LANG=en_US;fdisk -l {}|grep "Disk identifier:"'.format(path))[0]
if res!='Disk identifier: 0x00000000':
print path + '磁盘扩展成功!'
return
if __name__=='__main__':
print paths
print ''.join(paths)
path_list=''.join(paths).split(';')
for path in path_list:
add_disk(path)
#asm_conf(user=user_v, group=group_v, disk=disk_v)
import subprocess
# 执行命令
def _run_cmd(cmd, wait=False):
prc = subprocess.Popen(args=cmd, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, shell=True)
if wait:
prc.wait()
return prc
# 获得执行命令后的标准输出
def _get_output(cmd):
prc = _run_cmd(cmd)
lines = prc.stdout.readlines()
if not lines:
lines = prc.stderr.readlines()
return lines
def add_disk(disk=None,**kwargs):
path=None
if not disk:
for i in range('a','z'):
res = _get_output('export LANG=en_US;fdisk -l /dev/sd{}|grep "Disk identifier:"'.format(i))
print res
if 'Disk identifier: 0x00000000' in ''.join(res):
path = '/dev/sd{}'.format(i)
break
print path
if not path:
path=disk
if not path:
print path + '磁盘扩展失败'
return
with open('/tmp/add_disk.sh
','w') as f:
f.write('fdisk {} <<EOF n p 1 w EOF'.format(path))
_run_cmd('sh /tmp/add_disk.sh
', wait=True)
res = _get_output('export LANG=en_US;fdisk -l {}|grep "Disk identifier:"'.format(path))[0]
if res!='Disk identifier: 0x00000000':
print path + '磁盘扩展成功!'
return
if __name__=='__main__':
print paths
print ''.join(paths)
path_list=''.join(paths).split(';')
for path in path_list:
add_disk(path)
#asm_conf(user=user_v, group=group_v, disk=disk_v)