xml error with vlan operations
EvgeniyV opened this issue · 8 comments
Hi!
I get xml error when work with Nexus7K by nxos_vlan
existing_vlans_list = nxapi_lib.get_list_of_vlans(device)
File "/usr/lib/python2.6/site-packages/pycsco/nxos/utils/nxapi_lib.py", line 105, in get_list_of_vlans
data = device.show(command)
File "/usr/lib/python2.6/site-packages/pycsco/nxos/device.py", line 98, in show
data_dict = xmltodict.parse(data[1])
File "/usr/lib/python2.6/site-packages/xmltodict.py", line 248, in parse
I checked 'show vlan' by REST request to NX_API in response i get:
<ROW_mtuinfo>
<vlanshowinfo-vlanid>1002</vlanshowinfo-vlanid>
<vlanshowinfo-media-type>unknown enum:
<2>
</vlanshowinfo-media-type>
<vlanshowinfo-vlanmode>ce-vlan</vlanshowinfo-vlanmode>
</ROW_mtuinfo>
as i understand "unknown enum:<2>" make xml invalid
so any operation with vlan get exception....
Please always include the full error. I don't see unknown enum: <2>
in your error.
Can you do these three things:
- Reproduce the same error so I can see it with all steps leading up to the error (as shown below)
- Try
device.show('show vlan')
on your device and send the output - Use my test device and try it like this:
>>> from pycsco.nxos.device import Device
>>>
>>> device = Device(ip='31.220.69.130', username='ntc', password='Networktocode123')
>>>
>>> from pycsco.nxos.utils.nxapi_lib import get_list_of_vlans
>>>
>>> get_list_of_vlans(device)
['1', '110', '120']
i mean this xml element
<vlanshowinfo-media-type>unknown enum: <2></vlanshowinfo-media-type>
where nx-api returns <2> as xml tag the pythons xml2dict modules raise error on it
Also i reproduced that in rest client with this parameters
[{"params": {"cmd": "show vlan", "version": 1.2}, "jsonrpc": "2.0", "method": "cli", "id": 1}]
get this response:
{
"jsonrpc": "2.0",
"result": {
"body": {
"TABLE_vlanbrief": {
"ROW_vlanbrief": [{
"vlanshowbr-vlanid": "13775409",
"vlanshowbr-vlanid-utf": "1",
"vlanshowbr-vlanname": "default",
"vlanshowbr-vlanstate": "active",
"vlanshowbr-shutstate": "noshutdown",
"vlanshowplist-ifidx": "port-channel1,port-channel3,Ethernet6/1"
}, {
"vlanshowbr-vlanid": "1826045148",
"vlanshowbr-vlanid-utf": "1002",
"vlanshowbr-vlanname": "fddi-default",
"vlanshowbr-vlanstate": "suspend",
"vlanshowbr-shutstate": "shutdown",
"vlanshowplist-ifidx": "port-channel1,port-channel3,Ethernet6/31"
}]
},
"TABLE_mtuinfo": {
"ROW_mtuinfo": [{
"vlanshowinfo-vlanid": "1",
"vlanshowinfo-media-type": "enet",
"vlanshowinfo-vlanmode": "ce-vlan"
}, {
"vlanshowinfo-vlanid": "1002",
"vlanshowinfo-media-type": "unknown enum:<2>",
"vlanshowinfo-vlanmode": "ce-vlan"
}]
}
}
},
"id": 1
}
i have reproduced your script - with your device i haven't any problems
but with my device i see this for get_list_of_vlans:
File "tst2.py", line 11, in <module>
print get_list_of_vlans(device)
File "/usr/lib/python2.6/site-packages/pycsco/nxos/utils/nxapi_lib.py", line 105, in get_list_of_vlans
data = device.show(command)
File "/usr/lib/python2.6/site-packages/pycsco/nxos/device.py", line 98, in show
data_dict = xmltodict.parse(data[1])
File "/usr/lib/python2.6/site-packages/xmltodict.py", line 248, in parse
parser.Parse(xml_input, True)
xml.parsers.expat.ExpatError: not well-formed (invalid token): line 306, column 47
and this for device.show('show vlan'):
Traceback (most recent call last):
File "tst2.py", line 12, in <module>
print device.show('show vlan')
File "/usr/lib/python2.6/site-packages/pycsco/nxos/device.py", line 98, in show
data_dict = xmltodict.parse(data[1])
File "/usr/lib/python2.6/site-packages/xmltodict.py", line 248, in parse
parser.Parse(xml_input, True)
xml.parsers.expat.ExpatError: not well-formed (invalid token): line 306, column 47
It looks like it's an issue with how your 7K is returning data...could be a bug in that version of OS I suppose.
Try removing VLAN 1002 - does that work? Then try adding other VLANs and see if they work.
Please Include a show run
too
I am working on version 7.2(1)D1(1)
Jason, i think the problem is in NX API
on this device when i run in terminal show vlan
command and see list of vlans :
VLAN Type Vlan-mode
---- ----- ----------
1 enet CE
25 enet CE
26 enet CE
485 enet CE
1002 fddi CE
1003 token-ring CE
1004 fddinet CE
1005 trnet CE
and as i understand the problem s in Type
of vlan if type is enet - response is good and in my case vlans 1002-1005 have different types and i think this maybe a reason why they have bad mapping like unknown enum:<2>
Correct. I can add an exception into the code for this, that way it still works.
Letting @abhinavmodi know too since he works for the 7K team at Cisco :)
Thank you @jedelman8 , @EvgeniyV - Will check this out.
also i get same problem on Nexus5K when try to call nxos_get_facts
in
TASK: [get facts] *************************************************************
failed: [10.80.3.6] => {"failed": true, "parsed": false}
Traceback (most recent call last):
File "/home/yvarfolo/.ansible/tmp/ansible-tmp-1450091820.6-96091117715363/nxos_get_facts", line 1739, in <module>
main()
File "/home/yvarfolo/.ansible/tmp/ansible-tmp-1450091820.6-96091117715363/nxos_get_facts", line 119, in main
facts = nxapi_lib.get_facts(device)
File "/usr/lib/python2.6/site-packages/pycsco/nxos/utils/nxapi_lib.py", line 2382, in get_facts
xml = device.show(command)
File "/usr/lib/python2.6/site-packages/pycsco/nxos/device.py", line 98, in show
data_dict = xmltodict.parse(data[1])
File "/usr/lib/python2.6/site-packages/xmltodict.py", line 248, in parse
parser.Parse(xml_input, True)
xml.parsers.expat.ExpatError: not well-formed (invalid token): line 297, column 31
FATAL: all hosts have already failed -- aborting
in nxapi_lib error raising on the block:
command = 'show interface status'
try:
xml = device.show(command)
result = xmltodict.parse(xml[1])
....
except:
...
So when i run show interface status
as rest request (with json format) to nx_api
i get some interfaces with the same mapping problem
{
"interface": "Ethernet2/7",
"name": "VPC Peer Link",
"state": "unknown enum:<272>",
"vlan": "trunk",
"duplex": "full",
"speed": "10G",
"type": "10Gbase-SR"
},
{
"interface": "Ethernet2/8",
"name": "VPC Peer Link",
"state": "unknown enum:<272>",
"vlan": "trunk",
"duplex": "full",
"speed": "10G",
"type": "10Gbase-SR"
},