CiscoDevNet / ydk-py-samples

Sample apps for YDK-Py
Other
101 stars 87 forks source link

BGP sample nc-create-config-bgp-10-ydk.py #76

Closed NathanDotTo closed 7 years ago

NathanDotTo commented 7 years ago

https://github.com/CiscoDevNet/ydk-py-samples/blob/master/samples/basic/crud/ydk/models/bgp/nc-create-config-bgp-10-ydk.py

Hi

I get this when running the sample:

python nc-create-config-bgp-10-ydk.py Traceback (most recent call last): File "nc-create-config-bgp-10-ydk.py", line 36, in from ydk.models.bgp import bgp as oc_bgp ImportError: No module named bgp

I then tried:

from ydk.models.openconfig import bgp as oc_bgp

But:

from ydk.models.openconfig import bgp as oc_bgp

ImportError: No module named openconfig

Regards

Nathan

NathanDotTo commented 7 years ago

I have, I think, installed the openconfig models like this:

cisco@cisco:~/git/ydk-py/openconfig$ sudo pip install dist/ydk-*.tar.gz The directory '/home/cisco/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. The directory '/home/cisco/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. Processing ./dist/ydk-models-openconfig-0.1.1.tar.gz Requirement already satisfied (use --upgrade to upgrade): ydk-models-openconfig==0.1.1 from file:///home/cisco/git/ydk-py/openconfig/dist/ydk-models-openconfig-0.1.1.tar.gz in /usr/local/lib/python2.7/dist-packages/ydk_models_openconfig-0.1.1-py2.7.egg Requirement already satisfied (use --upgrade to upgrade): ecdsa==0.13 in /home/cisco/.local/lib/python2.7/site-packages (from ydk-models-openconfig==0.1.1) Requirement already satisfied (use --upgrade to upgrade): enum34==1.1.3 in /usr/local/lib/python2.7/dist-packages (from ydk-models-openconfig==0.1.1) Requirement already satisfied (use --upgrade to upgrade): lxml==3.4.4 in /usr/local/lib/python2.7/dist-packages (from ydk-models-openconfig==0.1.1) Requirement already satisfied (use --upgrade to upgrade): paramiko==1.15.2 in /usr/local/lib/python2.7/dist-packages (from ydk-models-openconfig==0.1.1) Requirement already satisfied (use --upgrade to upgrade): pyang==1.6 in /usr/local/lib/python2.7/dist-packages (from ydk-models-openconfig==0.1.1) Requirement already satisfied (use --upgrade to upgrade): pycrypto==2.6.1 in /home/cisco/.local/lib/python2.7/site-packages (from ydk-models-openconfig==0.1.1) Requirement already satisfied (use --upgrade to upgrade): Twisted>=16.0.0 in /usr/local/lib/python2.7/dist-packages (from ydk-models-openconfig==0.1.1) Requirement already satisfied (use --upgrade to upgrade): protobuf==3.0.0b2.post2 in /usr/local/lib/python2.7/dist-packages (from ydk-models-openconfig==0.1.1) Requirement already satisfied (use --upgrade to upgrade): ncclient>=0.4.7 in /usr/local/lib/python2.7/dist-packages/ncclient-0.5.2-py2.7.egg (from ydk-models-openconfig==0.1.1) Requirement already satisfied (use --upgrade to upgrade): ydk>=0.5.1 in /usr/local/lib/python2.7/dist-packages/ydk-0.5.1-py2.7.egg (from ydk-models-openconfig==0.1.1) Requirement already satisfied (use --upgrade to upgrade): ydk-models-ietf>=0.1.1 in /usr/local/lib/python2.7/dist-packages/ydk_models_ietf-0.1.1-py2.7.egg (from ydk-models-openconfig==0.1.1) Requirement already satisfied (use --upgrade to upgrade): zope.interface>=3.6.0 in /usr/local/lib/python2.7/dist-packages (from Twisted>=16.0.0->ydk-models-openconfig==0.1.1) Requirement already satisfied (use --upgrade to upgrade): six>=1.9 in /usr/lib/python2.7/dist-packages (from protobuf==3.0.0b2.post2->ydk-models-openconfig==0.1.1) Requirement already satisfied (use --upgrade to upgrade): setuptools in /usr/local/lib/python2.7/dist-packages (from protobuf==3.0.0b2.post2->ydk-models-openconfig==0.1.1)

NathanDotTo commented 7 years ago

Also, the openconfig model appears to be in the sys.path, see below.

python Python 2.7.11+ (default, Apr 17 2016, 14:00:29) [GCC 5.3.1 20160413] on linux2 Type "help", "copyright", "credits" or "license" for more information.

import sys print(sys.path) ['', '/usr/local/lib/python2.7/dist-packages/arya-1.1.5-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/acitoolkit-0.3.1-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/ipaddr-2.1.11-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/jsonschema-2.5.1-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/py_radix-0.9.6-py2.7-linux-x86_64.egg', '/usr/local/lib/python2.7/dist-packages/tabulate-0.7.5-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/PyMySQL-0.7.6-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/Flask-0.11.1-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/Flask_Cors-3.0.0-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/Flask_WTF-0.12-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/Flask_Bootstrap-3.3.6.0-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/Flask_Admin-1.4.2-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/Flask_SQLAlchemy-2.1-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/Flask_HTTPAuth-3.2.0-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/websocket_client-0.37.0-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/functools32-3.2.3.post2-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/click-6.6-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/itsdangerous-0.24-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/Werkzeug-0.11.10-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/WTForms-2.1-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/visitor-0.1.3-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/dominate-2.2.1-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/SQLAlchemy-1.1.0b3-py2.7-linux-x86_64.egg', '/usr/local/lib/python2.7/dist-packages/gitdb-0.6.4-py2.7-linux-x86_64.egg', '/usr/local/lib/python2.7/dist-packages/smmap-0.9.0-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/acicobra-1.3_2i-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/acimodel-1.3_2i-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/ydk-0.5.1-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/ydk_models_ietf-0.1.1-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/ncclient-0.5.2-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/ydk_models_openconfig-0.1.1-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/ydk_models_cisco_ios_xr-6.1.1-py2.7.egg', '/home/cisco/git/code_files', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/home/cisco/.local/lib/python2.7/site-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/gtk-2.0']

111pontes commented 7 years ago

Samples apps in master branch currently require YDK 0.4.2. Should be mentioned in the README. Refactored samples that support model bundles (YDK 0.5.0 and later) are under development. They should be pushed to master in a couple of days. You can find the commit for the refactored OC-BGP apps at https://github.com/111pontes/ydk-py-samples/commit/50de351111caefa73d77ce0559fe150e6614d7ef Note that apps matching -10- are boilerplates. They open a NETCONF session, but issue no RPCs. Apps matching -[2-9][0-9]- are custom apps that issue RPCs towards the target device. Notation is explained in the README for basic apps. Let me know if you have any issues.

NathanDotTo commented 7 years ago

Santiago

Thank you for following up.

My code now has:

from ydk.models.openconfig import openconfig_bgp as oc_bgp

I also had to reinstall my YDK models after deleting everything that had been installed previously. Something was messed up.

111pontes commented 7 years ago

All sample apps in master now require YDK 0.5.0. The OC-BGP sample apps have been updated too. Note that changes in https://github.com/CiscoDevNet/ydk-py-samples/commit/ff447ae4e789581678d4176389e88c58b15986de may not work on some devices. Those issues are outside the scope of YDK.