标签:多路径 for path com 路径 dal date run 命令
#coding=utf8
def get_physical_disk():
import re
code, res = run_cmd("fdisk -l | egrep ‘Disk /dev/sd| Disk /dev/vd| Disk /dev/hd‘")
result = {}
if code:
return data_format(‘物理磁盘个数及大小‘, ‘异常‘, 1)
for i in res.split(‘\n‘):
result.update({i.split()[1].strip(‘:‘).split(‘/‘)[-1]: ‘{} {}‘.format(i.split()[1],i.split()[2])})
disks = {}
#multipath多路径
code, res = run_cmd("multipath -ll | grep ‘(‘ | awk ‘{ print $1}‘")
if code or not res:
disks=result
else:
for i in res.split(‘\n‘):
disk_name=‘/dev/mapper/‘+i
code,res=run_cmd(‘fdisk -l {}‘.format(disk_name))
for j in res.split(‘\n‘):
if j.startswith(‘Disk {}:‘.format(disk_name)):
vol=‘{} {}‘.format(j.split()[2],j.split()[3])
break
disks.update({disk_name:vol})
code, res = run_cmd(‘multipath -ll‘)
for j in res.split(‘\n‘):
p1 = r"- (\d+):(\d+):(\d+):(\d+) (\S+)"
pattern1 = re.compile(p1).findall(j)
if pattern1:
disk_name=pattern1[0][4]
disks.update({‘/dev/‘+disk_name:result.get(disk_name,‘N/A‘)})
#powerpath多路径
code, res = run_cmd("emcpadm getusedpseudos")
if code or not res:
print ‘无emcpadm系统命令‘
else:
for i in res.split(‘\n‘)[3:]:
disk_name = ‘/dev/‘ + i.split()[0].strip()
code, res = run_cmd(‘fdisk -l {}‘.format(disk_name))
for j in res.split(‘\n‘):
if j.startswith(‘Disk {}:‘.format(disk_name)):
vol = ‘{} {}‘.format(j.split()[2], j.split()[3])
break
disks.update({disk_name: vol})
code, res = run_cmd("powermt display dev=all")
if code:
print ‘无powermt系统命令‘
else:
flag=0
for j in res.split(‘\n‘):
if flag==2:
disk_name = j.split()[2]
disks.update({‘/dev/‘ + disk_name: result.get(disk_name, ‘N/A‘)})
if ‘====‘ in j:
flag+=1
#HDLM多路径
code, res = run_cmd("dlnkmgr view -lu")
if code or not res:
print ‘无dlnkmgr系统命令‘
else:
flag=0
for i in res.split(‘\n‘):
if flag==1:
disk_name = ‘/dev/‘ + i.split()[1].strip()
code, res = run_cmd(‘fdisk -l {}‘.format(disk_name))
for j in res.split(‘\n‘):
if j.startswith(‘Disk {}:‘.format(disk_name)):
vol = ‘{} {}‘.format(j.split()[2], j.split()[3])
break
disks.update({disk_name: vol})
if ‘iLU‘ in i and ‘HDevName‘ in i:
flag=1
#sddpcm多路径
results = []
for k, v in disks.items():
results.append(‘{}_{}‘.format(k, v))
return data_format(‘物理磁盘个数及大小‘, ‘\n‘.join(results), 0)
标签:多路径 for path com 路径 dal date run 命令
原文地址:https://www.cnblogs.com/slqt/p/9778226.html