0

I am working on a parse for verifying configs for wlan controllers and I thought I had something. I usually use show commands but all I have available are the configs in a text format.

I have some configs that have either or of these lines. They are pulled and saved with putty.

VLAN........................ 
..................... 900      



VLAN............................................. 900 

Code I am using is rather simple

from ciscoconfparse import CiscoConfParse

parse = CiscoConfParse('config.txt', syntax='ios')

vlan = parse.find_objects(r'^VLAN')
#print(vlan)
vlan_id = vlan[0]
print(" VLAN: {0}".format(vlan_id.text))

if in the config it is one line I can trim it up and get the vlan id, but if it is in two lines I do not get the vlan id.

With this in the config I do not get a vlan id

VLAN........................ 
..................... 900    

This I do

VLAN............................................. 900 

I am looking for a way just to get the vlan id on either way it is formatted in the conig.

Thank you

  • This is more a problem with how you're retrieving the file over putty than how you're parsing it. The parsing is fine; the _retrieval_ is broken. Make sure the terminal width is correctly set, as one potential place to start. – Charles Duffy Nov 08 '21 at 22:40
  • (and how to get Cisco IOS to give you the data in its desired form is more a [Server Fault](https://serverfault.com/) question than a Stack Overflow one). – Charles Duffy Nov 08 '21 at 22:41
  • @CharlesDuffy I agree that the terminal width associated with a given session could be the issue. But the OP could use a regular expression to parse any config files already extracted. e.g., (VLAN)(.*\n.*)(\d{1,6})|(VLAN)(.*)(\d{1,6}) – Life is complex Nov 08 '21 at 22:50
  • @CharlesDuffy, his parser line says `syntax="ios"`, but the output is actually not from IOS. – Mike Pennington Nov 09 '21 at 02:26

0 Answers0