10-01-2020 01:57 AM - edited 10-01-2020 01:58 AM
Hello again fellow developers!
I come to you yet again in distress and in need of an answer.
I am trying to use the model under to retrieve interface information:
import ydk.models.cisco_ios_xr.Cisco_IOS_XR_ifmgr_cfg as ifmgr_cfg
The code:
model = ifmgr_cfg.InterfaceConfigurations() intconf = ifmgr_cfg.InterfaceConfigurations.InterfaceConfiguration() intconf.interface_name = "TenGigE0/0/0/11.910240030" model.interface_configuration.append(intconf) interface = NetconfService().get(provider=getProvider(), read_filter=intconf) print(interface.description)
Log output:
2020-10-01 08:02:53,323 - ydk - INFO - Executing 'get' RPC on [Cisco-IOS-XR-ifmgr-cfg:interface-configurations] 2020-10-01 08:02:53,341 - ydk - INFO - ============= Sending RPC to device ============= <rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"><get xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> <filter><interface-configurations xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg"> <interface-configuration> <interface-name>TenGigE0/0/0/11.910240030</interface-name> </interface-configuration> </interface-configurations></filter> </get> </rpc> 2020-10-01 08:02:53,577 - ydk - INFO - ============= Received RPC from device ============= <?xml version="1.0"?> <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1"> <data> <interface-configurations xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg"> <interface-configuration> <active>act</active> <interface-name>TenGigE0/0/0/11.910240030</interface-name> <interface-mode-non-physical>l2-transport</interface-mode-non-physical> <description>MAN-CPE:FRD-ASR920-Firdavegen5-LAB:Port24</description> <ethernet-service xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-l2-eth-infra-cfg"> <encapsulation> <outer-tag-type>match-dot1q</outer-tag-type> <outer-range1-low>1024</outer-range1-low> <exact/> </encapsulation> <rewrite> <rewrite-type>pop1</rewrite-type> </rewrite> </ethernet-service> <mtus> <mtu> <owner>sub_vlan</owner> <mtu>1522</mtu> </mtu> </mtus> </interface-configuration> </interface-configurations> </data> </rpc-reply>
My result:
AttributeError: 'NoneType' object has no attribute 'description'
I am following the doc from here:
Do you mind pointing me in the direction of my mistake?
Kind regards,
Simon Johansen
Solved! Go to Solution.
10-01-2020 10:21 AM
Hi Simon
The issue here is that list element interface-configuration has two keys: active and interface-name.
container interface-configurations {
description
"interface configurations";
list interface-configuration {
key "active interface-name";
description
"The configuration for an interface";
Based on the device output you should have:
model = ifmgr_cfg.InterfaceConfigurations() intconf = ifmgr_cfg.InterfaceConfigurations.InterfaceConfiguration() intconf.interface_name = "TenGigE0/0/0/11.910240030"
intconf.active = 'act' model.interface_configuration.append(intconf) interface = NetconfService().get(provider=getProvider(), read_filter=intconf) print(interface.description)
10-01-2020 10:21 AM
Hi Simon
The issue here is that list element interface-configuration has two keys: active and interface-name.
container interface-configurations {
description
"interface configurations";
list interface-configuration {
key "active interface-name";
description
"The configuration for an interface";
Based on the device output you should have:
model = ifmgr_cfg.InterfaceConfigurations() intconf = ifmgr_cfg.InterfaceConfigurations.InterfaceConfiguration() intconf.interface_name = "TenGigE0/0/0/11.910240030"
intconf.active = 'act' model.interface_configuration.append(intconf) interface = NetconfService().get(provider=getProvider(), read_filter=intconf) print(interface.description)
10-01-2020 11:43 PM
Good morning Yangorelik!
Yet again you come to my rescue, thank you so much
The solution you provided worked right away.
Hope you have a good day,
Kind regards,
Simon Johansen
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: