- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
def show_vlans(self):
"""Magic people/Voodoo people. All code in this func should be refactored/rewrited."""
self.read_very_eager()#flush
output=self.wr_cmd_sh('sho vlan')
time.sleep(.1)
vlans={}
vlan=''
for string in output:
if re.search(r"VID[\s]*:",string):
vlan=string[re.search(r"[\d]+",string).start():re.search(r"[\d]+",string).end()]
vlans[vlan]={'Member':[], 'Tagged':[], 'Untagged':[]}
if re.search(r"Member Port[s]*[\s]*:[\s]*[\d]+[[-]*[\d]*]*",string):
if '-' in string[re.search(r"[\d]+[[-]*[\d]*]*",string).start():re.search(r"[\d]+[[-]*[\d]*]*",string).end()]:
for port in xrange(int(string[re.search(r"[\d]+[[-]*[\d]+]*",string).start():re.search(r"[\d]+[[-]*[\d]+]*",string).end()].split('-')[0]),int(string[re.search(r"[\d]+[[-]*[\d]+]*",string).start():re.search(r"[\d]+[[-]*[\d]+]*",string).end()].split('-')[1])+1):
vlans[vlan]['Member'].append(port)
else:
vlans[vlan]['Member'].append(string[re.search(r"[\d]+[[-]*[\d]*]*",string).start():re.search(r"[\d]+[[-]*[\d]*]*",string).end()])
if re.search(r"Current Tagged Port[s]*[\s]*:[\s]*[\d]+[[-]*[\d]*]*",string):
if '-' in string[re.search(r"[\d]+[[-]*[\d]*]*",string).start():re.search(r"[\d]+[[-]*[\d]*]*",string).end()]:
for port in xrange(int(string[re.search(r"[\d]+[[-]*[\d]+]*",string).start():re.search(r"[\d]+[[-]*[\d]+]*",string).end()].split('-')[0]),int(string[re.search(r"[\d]+[[-]*[\d]+]*",string).start():re.search(r"[\d]+[[-]*[\d]+]*",string).end()].split('-')[1])+1):
vlans[vlan]['Tagged'].append(port)
else:
vlans[vlan]['Tagged'].append(string[re.search(r"[\d]+[[-]*[\d]*]*",string).start():re.search(r"[\d]+[[-]*[\d]*]*",string).end()])
if re.search(r"Current Untagged Port[s]*[\s]*:[\s]*[\d]+[[-]*[\d]*]*",string):
if '-' in string[re.search(r"[\d]+[[-]*[\d]*]*",string).start():re.search(r"[\d]+[[-]*[\d]*]*",string).end()]:
for port in xrange(int(string[re.search(r"[\d]+[[-]*[\d]+]*",string).start():re.search(r"[\d]+[[-]*[\d]+]*",string).end()].split('-')[0]),int(string[re.search(r"[\d]+[[-]*[\d]+]*",string).start():re.search(r"[\d]+[[-]*[\d]+]*",string).end()].split('-')[1])+1):
vlans[vlan]['Untagged'].append(port)
else:
vlans[vlan]['Untagged'].append(string[re.search(r"[\d]+[[-]*[\d]*]*",string).start():re.search(r"[\d]+[[-]*[\d]*]*",string).end()])
if vlans=={}:
vlans=self.show_vlans()
#####
return vlans
Императивненько) регекспотренировка при отсутствии group() да и вообще...
Комментарии (0) RSS
Добавить комментарий