1、存储信息原文本文件的获得:
登录到存储,Settings-->Constitute Array-->Ports Information-->Get Configurations可将PORT信息存为文本文件(port.txt)。
2、python3源代码:
import re
import xlwt
def xlwtline(sheet,line,line_contents):
i = 0
for j in line_contents:
sheet.write(line,i,j)
i = i+1
my_wb = xlwt.Workbook()
my_sheet = my_wb.add_sheet("AMS2500-port-configration")
c_line=0
xlwtline(my_sheet, c_line, ("控制器","端口号","主机组号","主机组名","LUNS"))
c_line += 1
fn="E:/users/workspace/pytest/data/port.txt"
input_file = open(fn,"r")
contents = input_file.read()
ctl = re.findall('(?<=---- CTL(\d) ----)(.*?)(?=---- CTL)',contents+"---- CTL",re.S|re.M)
for i in ctl:
port = re.findall('(?<=---- Port(\S) ----)(.*?)(?=---- Port\S ----)',i[1]+"---- PortZ ----",re.S|re.M)
for j in port:
hostgroup=re.findall('---- HostGroupInformation ----(.*?)-- HostGroupInformationEnd',j[1],re.S|re.M)
for k in hostgroup:
hg_num = re.search('HostGroupNumber = (\d+)', k).group(1)
hg_name = re.search('HostGroupName = "(.*)"', k).group(1)
luns=re.finditer('\d+ +(\d+)', k, re.S|re.M)
hg_luns = ""
for l in luns:
hg_luns = '%s %s' % (hg_luns,l.group(1))
xlwtline(my_sheet, c_line, (i[0],j[0],hg_num,hg_name,hg_luns))
c_line += 1
my_wb.save("data/port.xls") #结果存放在该excel表中