0

当我尝试将配置推送到运行 IOS XR 软件版本 5.3.4 的 ASR9K 时出现错误。有效载荷打印出来没有任何问题,并被 Python 正确解释。问题是当我将它发送到路由器时,由于某种原因它不喜欢它。

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")

################### 错误############################ 追溯(最近一次通话最后):文件“/Users/user/PycharmProjects/pythonProject/venv/netconf_config.py”,第 38 行,响应 = netconf_connection.edit_config(netconf_payload, target="running") 文件“/Users/user/ PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/ncclient/manager.py",第 246 行,在执行 return cls(self.session, File"/Users/user/PycharmProjects/pythonProject/venv/lib/ python3.9/site-packages/ncclient/operations/edit.py",第 65 行,请求中的 node.append(validated_element(config, ("config",qualify("config")))) 文件 "/Users/user /PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/ncclient/xml.py”,第 150 行,在 valid_element ele = to_ele(x) 文件中“/Users/user/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/ncclient/xml_.py”,第 129 行,在 to_ele 中返回 x if etree.iselement(x) else etree.fromstring(x.encode ('UTF-8'), parser=_get_parser(huge_tree)) 文件“src/lxml/etree.pyx”,第 3237 行,在 lxml.etree.fromstring 文件“src/lxml/parser.pxi”,第 1896 行,在lxml.etree._parseMemoryDocument 文件“src/lxml/parser.pxi”,第 1784 行,在 lxml.etree._parseDoc 文件“src/lxml/parser.pxi”,第 1141 行,在 lxml.etree._BaseParser._parseDoc 文件“src /lxml/parser.pxi”,第 615 行,在 lxml.etree._ParserContext._handleParseResultDoc 文件中“src/lxml/parser.pxi”,第 725 行,在 lxml.etree._handleParseResult 文件中“src/lxml/parser.pxi”,第 654 行,在 lxml.etree._raiseParseError 文件“”中,第 1 行 lxml.etree.XMLSyntaxError:需要开始标记,未找到“<”,第 1 行,第 1 列

#############有效负载#############################

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>
4

0 回答 0