09-06-2020 08:30 PM
Hello,
Could you please have a look below issue ?
No matter I use Router.Ospf or router.Opsf or Router.ospf or router.ospf. It always has issue.
May I know how I could get router.ospf object ?
Thanks a lot!
from ydk.models.cisco_ios_xe import Cisco_IOS_XE_native as xe_native
def config_native(native):
ospf = native.Router.Ospf()
ospf.id = 172
ospf.router_id = "172.16.255.1"
ospf.passive_interface.interface = "Loopback0"
native = xe_native.Native()
config_native(native)
AttributeError: type object 'Router' has no attribute 'Ospf'
jzhang@YDK64:~/Documents/YDK-PY-Samples/ydk-py-samples$
def config_native(native):
"""Add config data to native object."""
# OSPF process
ospf = native.router.ospf()
ospf.id = 172
ospf.router_id = "172.16.255.1"
AttributeError: type object 'Router' has no attribute 'ospf'
Solved! Go to Solution.
09-09-2020 03:50 PM - edited 09-15-2020 10:35 AM
Hi Jacky
Unfortunately your script erroneously uses model API - container 'router' includes list 'ospf'. You should have something like this:
def config_native(native):
ospf = xe_native.Native.Router.Ospf()
ospf.id = 172
ospf.router_id = "172.16.255.1"
ospf.passive_interface.interface = "Loopback0"
native.router.ospf.append(ospf) # missed this line to add 'ospf' to the list
09-09-2020 03:50 PM - edited 09-15-2020 10:35 AM
Hi Jacky
Unfortunately your script erroneously uses model API - container 'router' includes list 'ospf'. You should have something like this:
def config_native(native):
ospf = xe_native.Native.Router.Ospf()
ospf.id = 172
ospf.router_id = "172.16.255.1"
ospf.passive_interface.interface = "Loopback0"
native.router.ospf.append(ospf) # missed this line to add 'ospf' to the list
09-15-2020 01:13 AM
Hello Yan,
I hope you are doing well.
I am sorry to test and reply to you a bit later. Because I am busy with my personal things.
It still indicates error message "AttributeError: type object 'Router' has no attribute 'Ospf'"
Could you please have a look below coding and error message ?
Thanks a lot
from ydk.models.cisco_ios_xe import Cisco_IOS_XE_native as xe_native
def config_native(native):
ospf = native.Router.Ospf()
ospf.id = 172
ospf.router.id = "172.16.255.1"
ospf.passive_interface.interface = "Loopback0"
native.router.ospf.append(ospf)
if __name__ == "__main__":
# create codec provider
provider = CodecServiceProvider(type="xml")
codec = CodecService()
native = xe_native.Native()
config_native(native)
print(codec.encode(provider, native))
-native-router-ospf-20-ydk.py
Traceback (most recent call last):
File "/home/jzhang/Documents/YDK-PY-Samples/ydk-py-samples/projects/my_coding/IOS-XE/cd-encode-xe-native-router-ospf-20-ydk.py", line 45, in <module>
config_native(native)
File "/home/jzhang/Documents/YDK-PY-Samples/ydk-py-samples/projects/my_coding/IOS-XE/cd-encode-xe-native-router-ospf-20-ydk.py", line 24, in config_native
ospf = native.Router.Ospf()
AttributeError: type object 'Router' has no attribute 'Ospf'
jzhang@YDK64:~/Documents/YDK-PY-Samples/ydk-py-samples$
09-15-2020 10:34 AM
Sorry, my bad! It should be:
def config_native(native):
ospf = xe_native.Native.Router.Ospf()
ospf.id = 172
ospf.router_id = "172.16.255.1"
ospf.passive_interface.interface = "Loopback0"
native.router.ospf.append(ospf) # missed this line to add 'ospf' to the list
09-21-2020 07:06 PM
Hi Yan,
Thank you for your help.
I did testing but it still show AttributeError: type object . I will paste coding and result later.
Do you think there is a bug for YDK OSPF ?
09-15-2020 01:09 AM
Hello Yan.
Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: