I am getting an error when I attempt to push a config to an ASR9K running IOS XR Software, Version 5.3.4. The payload prints out without any issues and get's interpreted correctly by Python. The problem is when I send it the router, it doesn't like it for some reason.
from ncclient import manager
from jinja2 import Environment, FileSystemLoader
import os
# netconf Connection Manager
netconf_connection = manager.connect(host='10.22.108.13',
port=830,
username='admin',
password='super',
device_params={'name': 'iosxr'},
hostkey_verify=False,
look_for_keys=False)
#
netconf_data = {
"carrier_vlan": 201,
"customer_vlan": 5000,
"HUB_WAN1_PUBLIC_IP": "40.40.40.40",
"customer": "FirstNetConfTest",
"PRIMARY_TRANSIT": "41.41.41.41",
"neighbor_IP": "41.41.41.42",
"Location": "ATL"
}
template_dir = f"{os.path.dirname(os.path.abspath(__file__))}/templates"
j2_env = Environment(loader=FileSystemLoader(template_dir), trim_blocks=True)
netconf_payload = j2_env.get_template('new_config.j2').render(netconf_data)
print(netconf_payload)
response = netconf_connection.edit_config(netconf_payload, target="running")
#################### ERROR ############################ Traceback (most recent call last): File "/Users/user/PycharmProjects/pythonProject/venv/netconf_config.py", line 38, in response = netconf_connection.edit_config(netconf_payload, target="running") File "/Users/user/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/ncclient/manager.py", line 246, in execute return cls(self.session, File "/Users/user/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/ncclient/operations/edit.py", line 65, in request node.append(validated_element(config, ("config", qualify("config")))) File "/Users/user/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/ncclient/xml.py", line 150, in validated_element ele = to_ele(x) File "/Users/user/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/ncclient/xml_.py", line 129, in to_ele return x if etree.iselement(x) else etree.fromstring(x.encode('UTF-8'), parser=_get_parser(huge_tree)) File "src/lxml/etree.pyx", line 3237, in lxml.etree.fromstring File "src/lxml/parser.pxi", line 1896, in lxml.etree._parseMemoryDocument File "src/lxml/parser.pxi", line 1784, in lxml.etree._parseDoc File "src/lxml/parser.pxi", line 1141, in lxml.etree._BaseParser._parseDoc File "src/lxml/parser.pxi", line 615, in lxml.etree._ParserContext._handleParseResultDoc File "src/lxml/parser.pxi", line 725, in lxml.etree._handleParseResult File "src/lxml/parser.pxi", line 654, in lxml.etree._raiseParseError File "", line 1 lxml.etree.XMLSyntaxError: Start tag expected, '<' not found, line 1, column 1
############## PAYLOAD ###############################
XML>
<?xml version="1.0"?>
<Request>
<Set>
<Configuration>
<InterfaceConfigurationTable>
<InterfaceConfiguration>
<Naming>
<Active>act</Active>
<InterfaceName>Bundle-Ether4.2015000</InterfaceName>
</Naming>
<InterfaceModeNonPhysical>Default</InterfaceModeNonPhysical>
<Description>FirstNetConfTest</Description>
<IPV4Network>
<Addresses>
<Primary>
<Address>40.40.40.40</Address>
<Netmask>255.255.255.254</Netmask>
</Primary>
</Addresses>
</IPV4Network>
<VLANSubConfiguration>
<VLANIdentifier>
<VlanType>VLANTypeDot1q</VlanType>
<FirstTag>201</FirstTag>
<SecondTag>5000</SecondTag>
</VLANIdentifier>
</VLANSubConfiguration>
</InterfaceConfiguration>
<InterfaceConfiguration>
<Naming>
<Active>act</Active>
<InterfaceName>Bundle-Ether4.2015001</InterfaceName>
</Naming>
<InterfaceModeNonPhysical>Default</InterfaceModeNonPhysical>
<Description>FirstNetConfTest_WAN-Transit</Description>
<IPV4Network>
<Addresses>
<Primary>
<Address>41.41.41.41</Address>
<Netmask>255.255.255.254</Netmask>
</Primary>
</Addresses>
</IPV4Network>
<VLANSubConfiguration>
<VLANIdentifier>
<VlanType>VLANTypeDot1q</VlanType>
<FirstTag>201</FirstTag>
<SecondTag>5001</SecondTag>
</VLANIdentifier>
</VLANSubConfiguration>
</InterfaceConfiguration>
</InterfaceConfigurationTable>
<BGP>
<Instance>
<Naming>
<InstanceName>default</InstanceName>
</Naming>
<InstanceAS>
<Naming>
<AS>0</AS>
</Naming>
<FourByteAS>
<Naming>
<AS>11696</AS>
</Naming>
<BGPRunning>true</BGPRunning>
<DefaultVRF>
<Global>
<GlobalAFTable>
<GlobalAF>
<Naming>
<AFName>IPv4Unicast</AFName>
</Naming>
<Enable>true</Enable>
</GlobalAF>
</GlobalAFTable>
</Global>
<BGPEntity>
<NeighborTable>
<Neighbor>
<Naming>
<NeighborAddress>
<IPV4Address>41.41.41.42</IPV4Address>
</NeighborAddress>
</Naming>
<RemoteAS>
<AS_XX>0</AS_XX>
<AS_YY>65535</AS_YY>
</RemoteAS>
<NeighborAFTable>
<NeighborAF>
<Naming>
<AFName>IPv4Unicast</AFName>
</Naming>
<Activate>true</Activate>
<RoutePolicyIn>ATLFGTSDW01_HUB_IN</RoutePolicyIn>
<RoutePolicyOut>DENY-ALL</RoutePolicyOut>
<SoftReconfiguration>
<InboundSoft>true</InboundSoft>
<SoftAlways>true</SoftAlways>
</SoftReconfiguration>
</NeighborAF>
</NeighborAFTable>
</Neighbor>
</NeighborTable>
</BGPEntity>
</DefaultVRF>
</FourByteAS>
</InstanceAS>
</Instance>
</BGP>
</Configuration>
</Set>
</Request>