cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2455
Views
5
Helpful
2
Replies

AttributeError: 'NoneType' object has no attribute 'description'

SimonJohansen
Level 1
Level 1

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:

http://ydk.cisco.com/py/docs/gen_doc_dfe42d73c3f4f1961e486d4f23a11f136f62317a.html#ydk.models.cisco_ios_xr.Cisco_IOS_XR_ifmgr_cfg.InterfaceConfigurations.InterfaceConfiguration

 

Do you mind pointing me in the direction of my mistake? 

 

Kind regards,

Simon Johansen

1 Accepted Solution

Accepted Solutions

yangorelik
Spotlight
Spotlight

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)
Yan Gorelik
YDK Solutions

View solution in original post

2 Replies 2

yangorelik
Spotlight
Spotlight

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)
Yan Gorelik
YDK Solutions

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