03-24-2017 07:48 AM
Hi,
as my first try with YDK, I'm trying to read configuration of the static routes (something I have been doing with ncclient). The code is simple:
log = logging.getLogger('ydk')
log.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
log.addHandler(ch)
provider = NetconfServiceProvider(address=HOST, port=PORT, username=USER, password=PASS, protocol=PROTO)
crud = CRUDService()
router_static = Cisco_IOS_XR_ip_static_cfg.RouterStatic()
crud.read(provider,router_static)
print ("Printing static routes:\n")
for vrf_prefix in router_static.default_vrf.address_family.vrfipv4.vrf_unicast.vrf_prefixes.vrf_prefix:
print(vrf_prefix.prefix + "/" + vrf_prefix.prefix_length)
print ("Done.\n")
However, nothing happens although log shows that config has been read from the router:
**************************************************************************
C:\Users\dvulovic\AppData\Local\Programs\Python\Python35\python.exe C:/Users/dvulovic/PycharmProjects/YDK/YDK-test.py
NetconfServiceProvider connected to 10.62.38.90:830 using ssh
READ operation initiated
<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="urn:uuid:8537d64e-7ceb-4295-93b4-51404b183cbe">
<get>
<filter type="subtree">
<router-static xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ip-static-cfg"/>
</filter>
</get>
</rpc>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="urn:uuid:8537d64e-7ceb-4295-93b4-51404b183cbe">
<data>
<router-static xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ip-static-cfg">
<default-vrf>
<address-family>
<vrfipv4>
<vrf-unicast>
<vrf-prefixes>
<vrf-prefix>
<prefix>0.0.0.0</prefix>
<prefix-length>0</prefix-length>
<vrf-route>
<vrf-next-hop-table>
<vrf-next-hop-next-hop-address>
<next-hop-address>10.254.0.1</next-hop-address>
</vrf-next-hop-next-hop-address>
</vrf-next-hop-table>
</vrf-route>
</vrf-prefix>
<vrf-prefix>
<prefix>9.9.9.9</prefix>
<prefix-length>32</prefix-length>
<vrf-route>
<vrf-next-hop-table>
<vrf-next-hop-next-hop-address>
<next-hop-address>10.62.38.88</next-hop-address>
</vrf-next-hop-next-hop-address>
<vrf-next-hop-next-hop-address>
<next-hop-address>10.62.38.89</next-hop-address>
</vrf-next-hop-next-hop-address>
</vrf-next-hop-table>
</vrf-route>
</vrf-prefix>
<vrf-prefix>
<prefix>10.62.38.88</prefix>
<prefix-length>32</prefix-length>
<vrf-route>
<vrf-next-hop-table>
<vrf-next-hop-next-hop-address>
<next-hop-address>10.254.0.1</next-hop-address>
</vrf-next-hop-next-hop-address>
</vrf-next-hop-table>
</vrf-route>
</vrf-prefix>
<vrf-prefix>
<prefix>10.62.38.89</prefix>
<prefix-length>32</prefix-length>
<vrf-route>
<vrf-next-hop-table>
<vrf-next-hop-next-hop-address>
<next-hop-address>10.254.0.1</next-hop-address>
</vrf-next-hop-next-hop-address>
</vrf-next-hop-table>
</vrf-route>
</vrf-prefix>
<vrf-prefix>
<prefix>11.11.11.11</prefix>
<prefix-length>32</prefix-length>
<vrf-route>
<vrf-next-hop-table>
<vrf-next-hop-next-hop-address>
<next-hop-address>10.62.38.88</next-hop-address>
</vrf-next-hop-next-hop-address>
<vrf-next-hop-next-hop-address>
<next-hop-address>10.62.38.89</next-hop-address>
</vrf-next-hop-next-hop-address>
</vrf-next-hop-table>
</vrf-route>
</vrf-prefix>
</vrf-prefixes>
</vrf-unicast>
</vrfipv4>
</address-family>
</default-vrf>
</router-static>
</data>
</rpc-reply>
READ operation completed
Printing static routes:
Done.
NetconfServiceProvider disconnected from 10.62.38.90:830 using ssh
Process finished with exit code 0
**************************************************************************
Any ideas?
Can the problem be the fact I'm not using lxml 3.4.4 but 3.7.2 ?
Thanks in advance,
Djordje
03-24-2017 08:40 AM
Hi,
~/ > pip list|grep lxml
lxml (3.7.3)
I upgraded my lxml to 3.7.3 and the below script is working fine for me. Not sure why you're seeing this issue
from ydk.models.cisco_ios_xr import Cisco_IOS_XR_ip_static_cfg
import logging
log = logging.getLogger('ydk')
log.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
log.addHandler(ch)
from ydk.providers import NetconfServiceProvider
from ydk.services import CRUDService
crud = CRUDService()
ncc = NetconfServiceProvider(address='localhost' , username='vagrant', password='vagrant', port=830)
router_static = crud.read(ncc,Cisco_IOS_XR_ip_static_cfg.RouterStatic())
for pref in router_static.default_vrf.address_family.vrfipv4.vrf_unicast.vrf_prefixes.vrf_prefix:
print ( '{}/{}'.format(pref.prefix, pref.prefix_length))
03-28-2017 02:43 PM
Can't really reproduce issue with latest YDK-Py with either version of LXML.
script works for me with clean YDK-Py 0.5.4 install.
$ pip list
Package Version
----------------------- -------
appdirs 1.4.3
asn1crypto 0.22.0
cffi 1.10.0
cryptography 1.8.1
enum34 1.1.3
idna 2.5
ipaddress 1.0.18
lxml 3.4.4
ncclient 0.5.3
packaging 16.8
paramiko 2.1.2
pip 9.0.1
pyasn1 0.2.3
pybind11 2.0.1
pycparser 2.17
pyparsing 2.2.0
setuptools 34.3.3
six 1.10.0
wheel 0.29.0
ydk 0.5.4
ydk-models-cisco-ios-xr 6.2.1
ydk-models-ietf 0.1.1
ydk-models-openconfig 0.1.2
$
$ ./nc-read-xr-ip-static-cfg-20-ydk.py ssh://xxx:xxx@yyy
Printing static routes:
0.0.0.0 / 0
Done.
$
$ pip install lxml==3.7.2
Collecting lxml==3.7.2
Downloading lxml-3.7.2-cp27-cp27mu-manylinux1_x86_64.whl (6.8MB)
100% |████████████████████████████████| 6.8MB 226kB/s
Installing collected packages: lxml
Found existing installation: lxml 3.4.4
Uninstalling lxml-3.4.4:
Successfully uninstalled lxml-3.4.4
Successfully installed lxml-3.7.2
$
$ ./nc-read-xr-ip-static-cfg-20-ydk.py ssh://xxx:xxx@yyy
Printing static routes:
0.0.0.0 / 0
Done.
$ pip list
Package Version
----------------------- -------
appdirs 1.4.3
asn1crypto 0.22.0
cffi 1.10.0
cryptography 1.8.1
enum34 1.1.3
idna 2.5
ipaddress 1.0.18
lxml 3.7.2
ncclient 0.5.3
packaging 16.8
paramiko 2.1.2
pip 9.0.1
pyasn1 0.2.3
pybind11 2.0.1
pycparser 2.17
pyparsing 2.2.0
setuptools 34.3.3
six 1.10.0
wheel 0.29.0
ydk 0.5.4
ydk-models-cisco-ios-xr 6.2.1
ydk-models-ietf 0.1.1
ydk-models-openconfig 0.1.2
$
04-02-2017 02:09 AM
Hi Santiago,
you can easily it reproduce it in the dCloud lab:
admin@controller:~$ cat dv1.py
from ydk.models.cisco_ios_xr import Cisco_IOS_XR_ip_static_cfg
from ydk.services.crud_service import CRUDService
from ydk.providers.netconf_provider import NetconfServiceProvider
import logging
HOST = '198.18.1.11'
PORT = 830
USER = 'admin'
PASS = 'admin'
PROTO = 'ssh'
log = logging.getLogger('ydk')
log.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
log.addHandler(ch)
provider = NetconfServiceProvider(address=HOST, port=PORT, username=USER, password=PASS, protocol=PROTO)
crud = CRUDService()
router_static = Cisco_IOS_XR_ip_static_cfg.RouterStatic()
crud.read(provider,router_static)
print ("Printing static routes:\n")
for vrf_prefix in router_static.default_vrf.address_family.vrfipv4.vrf_unicast.vrf_prefixes.vrf_prefix:
print(vrf_prefix.prefix + "/" + vrf_prefix.prefix_length)
print ("Done.\n")
provider.close()
admin@controller:~$ python dv1.py
NetconfServiceProvider connected to 198.18.1.11:830 using ssh
READ operation initiated
<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="urn:uuid:536a279c-e29f-11e6-bc9c-525400b7982f">
<get>
<filter type="subtree">
<router-static xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ip-static-cfg"/>
</filter>
</get>
</rpc>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="urn:uuid:536a279c-e29f-11e6-bc9c-525400b7982f">
<data>
<router-static xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ip-static-cfg">
<default-vrf>
<address-family>
<vrfipv4>
<vrf-unicast>
<vrf-prefixes>
<vrf-prefix>
<prefix>10.16.0.0</prefix>
<prefix-length>16</prefix-length>
<vrf-route>
<vrf-next-hop-table>
<vrf-next-hop-next-hop-address>
<next-hop-address>198.18.1.1</next-hop-address>
</vrf-next-hop-next-hop-address>
</vrf-next-hop-table>
</vrf-route>
</vrf-prefix>
<vrf-prefix>
<prefix>10.64.0.0</prefix>
<prefix-length>16</prefix-length>
<vrf-route>
<vrf-next-hop-table>
<vrf-next-hop-next-hop-address>
<next-hop-address>198.18.1.1</next-hop-address>
</vrf-next-hop-next-hop-address>
</vrf-next-hop-table>
</vrf-route>
</vrf-prefix>
<vrf-prefix>
<prefix>198.18.0.0</prefix>
<prefix-length>16</prefix-length>
<vrf-route>
<vrf-next-hop-table>
<vrf-next-hop-next-hop-address>
<next-hop-address>198.18.1.1</next-hop-address>
</vrf-next-hop-next-hop-address>
</vrf-next-hop-table>
</vrf-route>
</vrf-prefix>
</vrf-prefixes>
</vrf-unicast>
</vrfipv4>
</address-family>
</default-vrf>
</router-static>
</data>
</rpc-reply>
READ operation completed
Printing static routes:
Done.
NetconfServiceProvider disconnected from 198.18.1.11:830 using ssh
admin@controller:~$
Thanks,
Djordje
04-06-2017 12:19 PM
dcloud is still running 0.5.3, can you run an instance, upgrade to 0.5.4 and try to reproduce? You can upgrade using:
$ sudo pip install ydk-models-cisco-ios-xr --upgrade
password is the same as username.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide