cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
253
Views
5
Helpful
4
Replies
Highlighted
Beginner

Issues retrieving XR interface information

Hi!
I am trying to retrieve information from a cisco XR device.
I want the information on the interfaces. 

 

The code i am running:

service = NetconfService()
provider = NetconfServiceProvider(address=ip_address,
                                  username=user_name,
                                  password=password)

model = test.InterfaceProperties.DataNodes.DataNode.SystemView.Interfaces.Interface()
interfaceFilter = test.InterfaceProperties.DataNodes.DataNode.SystemView.Interfaces.Interface.interface

interfaceFilter.interface_name = "Gi0/0/0/1" 
model.interface.append(interfaceFilter)

interface = service.get(provider=provider, read_filter=interfaceFilter)
print(interface)

The output i am getting:

interfaceFilter = test.InterfaceProperties.DataNodes.DataNode.SystemView.Interfaces.Interface.interface
AttributeError: type object 'Interface' has no attribute 'interface'

Imports:

import ydk.models.cisco_ios_xr.Cisco_IOS_XR_ifmgr_oper as test
from ydk.services.netconf_service import NetconfService
from ydk.providers.netconf_provider import NetconfServiceProvider

May one of you be so kind as to give me any hints on how I can proceed to get around this issue?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

To better understand data hierarchy you could try to get properties for all interfaces. Here is my example for CiscoDevNet XR sandbox:

#!/usr/bin/env python
import ydk.models.cisco_ios_xr.Cisco_IOS_XR_ifmgr_oper as test
from ydk.services.netconf_service import NetconfService
from ydk.providers.netconf_provider import NetconfServiceProvider

import logging

log_ydk = logging.getLogger('ydk')
log_ydk.setLevel(logging.INFO)
handler = logging.StreamHandler()
log_ydk.addHandler(handler)

if __name__ == "__main__":
service = NetconfService()
provider = NetconfServiceProvider(address="sbx-iosxr-mgmt.cisco.com",
port=10000,
username="admin",
password="C1sco12345")
all_ifcs = test.InterfaceProperties()
service.get(provider, all_ifcs)

I am getting the following (truncated due to long output):

ygorelik$ ./xr_interface_properties.py 
Path where models are to be downloaded: /Users/ygorelik/.ydk/sbx-iosxr-mgmt.cisco.com
Connected to sbx-iosxr-mgmt.cisco.com on port 10000 using ssh with timeout of -1
Executing 'get' RPC on [Cisco-IOS-XR-ifmgr-oper:interface-properties]
============= 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-properties xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-oper"/></filter>
</get>
</rpc>
============= Received RPC from device =============

<?xml version="1.0"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="4">
<data>
<interface-properties xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-oper">
<data-nodes>
<data-node>
<data-node-name>0/RP0/CPU0</data-node-name>
<locationviews>
<locationview>
<locationview-name>0/0/CPU0</locationview-name>
<interfaces>
<interface>
<interface>
<interface-name>GigabitEthernet0/0/0/0</interface-name>
<interface>GigabitEthernet0/0/0/0</interface>
<type>IFT_GETHERNET</type>
<state>im-state-admin-down</state>
<actual-state>im-state-admin-down</actual-state>
<line-state>im-state-admin-down</line-state>
<actual-line-state>im-state-admin-down</actual-line-state>
<encapsulation>ether</encapsulation>
<encapsulation-type-string>ARPA</encapsulation-type-string>
<mtu>1514</mtu>
<sub-interface-mtu-overhead>0</sub-interface-mtu-overhead>
<l2-transport>false</l2-transport>
<bandwidth>1000000</bandwidth>
</interface>
<interface>
<interface-name>GigabitEthernet0/0/0/1</interface-name>
<interface>GigabitEthernet0/0/0/1</interface>
<type>IFT_GETHERNET</type>
<state>im-state-admin-down</state>
<actual-state>im-state-admin-down</actual-state>
<line-state>im-state-admin-down</line-state>
<actual-line-state>im-state-admin-down</actual-line-state>
<encapsulation>ether</encapsulation>
<encapsulation-type-string>ARPA</encapsulation-type-string>
<mtu>1514</mtu>
<sub-interface-mtu-overhead>0</sub-interface-mtu-overhead>
<l2-transport>false</l2-transport>
<bandwidth>1000000</bandwidth>
</interface>
</interfaces>
</locationview>
<locationview>
<locationview-name>0/0/CPU0</locationview-name>
</locationview>
</locationviews>
</data-node>
</data-nodes>
</interface-properties>
</data>
</rpc-reply>

Important to note that data-node, locationview and interface are list elements and have to be handled properly!

Also, the get filter building must always start from the top level container!

Here is an example for getting properties of specific interface:

#!/usr/bin/env python
import ydk.models.cisco_ios_xr.Cisco_IOS_XR_ifmgr_oper as test
from ydk.services.netconf_service import NetconfService
from ydk.providers.netconf_provider import NetconfServiceProvider

import logging

log_ydk = logging.getLogger('ydk')
log_ydk.setLevel(logging.INFO)
handler = logging.StreamHandler()
log_ydk.addHandler(handler)

if __name__ == "__main__":
service = NetconfService()
provider = NetconfServiceProvider(address="sbx-iosxr-mgmt.cisco.com",
port=10000,
username="admin",
password="C1sco12345")
all_ifcs = test.InterfaceProperties()
my_data_node = test.InterfaceProperties.DataNodes.DataNode()
my_data_node.data_node_name = '0/RP0/CPU0'
all_ifcs.data_nodes.data_node.append(my_data_node)

my_locationview = test.InterfaceProperties.DataNodes.DataNode.Locationviews.Locationview()
my_locationview.locationview_name = '0/RP0/CPU0'
my_data_node.locationviews.locationview.append(my_locationview)

my_ifc = test.InterfaceProperties.DataNodes.DataNode.Locationviews.Locationview.Interfaces.Interface()
my_ifc.interface_name = 'GigabitEthernet0/0/0/0'
my_locationview.interfaces.interface.append(my_ifc)

my_ifc_props = service.get(provider, my_ifc)

And results:

Path where models are to be downloaded: /Users/ygorelik/.ydk/sbx-iosxr-mgmt.cisco.com
Connected to sbx-iosxr-mgmt.cisco.com on port 10000 using ssh with timeout of -1
Executing 'get' RPC on [Cisco-IOS-XR-ifmgr-oper:interface-properties]
============= 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-properties xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-oper">
<data-nodes>
<data-node>
<data-node-name>0/RP0/CPU0</data-node-name>
<locationviews>
<locationview>
<locationview-name>0/RP0/CPU0</locationview-name>
<interfaces>
<interface>
<interface-name>GigabitEthernet0/0/0/0</interface-name>
</interface>
</interfaces>
</locationview>
</locationviews>
</data-node>
</data-nodes>
</interface-properties></filter>
</get>
</rpc>
============= 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-properties xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-oper">
<data-nodes>
<data-node>
<data-node-name>0/RP0/CPU0</data-node-name>
<locationviews>
<locationview>
<locationview-name>0/RP0/CPU0</locationview-name>
<interfaces>
<interface>
<interface-name>GigabitEthernet0/0/0/0</interface-name>
<interface>GigabitEthernet0/0/0/0</interface>
<type>IFT_GETHERNET</type>
<state>im-state-admin-down</state>
<actual-state>im-state-admin-down</actual-state>
<line-state>im-state-admin-down</line-state>
<actual-line-state>im-state-admin-down</actual-line-state>
<encapsulation>ether</encapsulation>
<encapsulation-type-string>ARPA</encapsulation-type-string>
<mtu>1514</mtu>
<sub-interface-mtu-overhead>0</sub-interface-mtu-overhead>
<l2-transport>false</l2-transport>
<bandwidth>1000000</bandwidth>
</interface>
</interfaces>
</locationview>
</locationviews>
</data-node>
</data-nodes>
</interface-properties>
</data>
</rpc-reply>

 I hope that helps to understand the basics of building models.

Yan Gorelik
YDK Solutions

View solution in original post

4 REPLIES 4
Highlighted
Participant

These 2 lines do not correspond to the Model API:

model = test.InterfaceProperties.DataNodes.DataNode.SystemView.Interfaces.Interface()
interfaceFilter = test.InterfaceProperties.DataNodes.DataNode.SystemView.Interfaces.Interface.interface

Please work with documentation, IOS XR Model API, and hundreds of examples on the web.  

Yan Gorelik
YDK Solutions
Highlighted

Good morning yangorelik!

Thank you so much for a reply

 

I am trying to work with the documentation, but i find it rather limiting and hard to work with. But maybe you have a different documentation than I got.

I am using this one:
http://ydk.cisco.com/py/docs/gen_doc_7f55e5ce98f5bdaba72a929253ec0ac5291b646a.html#ydk.models.cisco_ios_xr.Cisco_IOS_XR_ifmgr_oper.InterfaceProperties.DataNodes.DataNode.SystemView.Interfaces.Interface

 

I have also tried to search the web for examples but i found none that mached my case. 
Perhaps you could provide a link to one of your examples? I would be grateful

 

I am sorry for been such a rookie, I appreciate the time you use for answering me

Kind regards,
Simon Johansen

Highlighted

To better understand data hierarchy you could try to get properties for all interfaces. Here is my example for CiscoDevNet XR sandbox:

#!/usr/bin/env python
import ydk.models.cisco_ios_xr.Cisco_IOS_XR_ifmgr_oper as test
from ydk.services.netconf_service import NetconfService
from ydk.providers.netconf_provider import NetconfServiceProvider

import logging

log_ydk = logging.getLogger('ydk')
log_ydk.setLevel(logging.INFO)
handler = logging.StreamHandler()
log_ydk.addHandler(handler)

if __name__ == "__main__":
service = NetconfService()
provider = NetconfServiceProvider(address="sbx-iosxr-mgmt.cisco.com",
port=10000,
username="admin",
password="C1sco12345")
all_ifcs = test.InterfaceProperties()
service.get(provider, all_ifcs)

I am getting the following (truncated due to long output):

ygorelik$ ./xr_interface_properties.py 
Path where models are to be downloaded: /Users/ygorelik/.ydk/sbx-iosxr-mgmt.cisco.com
Connected to sbx-iosxr-mgmt.cisco.com on port 10000 using ssh with timeout of -1
Executing 'get' RPC on [Cisco-IOS-XR-ifmgr-oper:interface-properties]
============= 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-properties xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-oper"/></filter>
</get>
</rpc>
============= Received RPC from device =============

<?xml version="1.0"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="4">
<data>
<interface-properties xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-oper">
<data-nodes>
<data-node>
<data-node-name>0/RP0/CPU0</data-node-name>
<locationviews>
<locationview>
<locationview-name>0/0/CPU0</locationview-name>
<interfaces>
<interface>
<interface>
<interface-name>GigabitEthernet0/0/0/0</interface-name>
<interface>GigabitEthernet0/0/0/0</interface>
<type>IFT_GETHERNET</type>
<state>im-state-admin-down</state>
<actual-state>im-state-admin-down</actual-state>
<line-state>im-state-admin-down</line-state>
<actual-line-state>im-state-admin-down</actual-line-state>
<encapsulation>ether</encapsulation>
<encapsulation-type-string>ARPA</encapsulation-type-string>
<mtu>1514</mtu>
<sub-interface-mtu-overhead>0</sub-interface-mtu-overhead>
<l2-transport>false</l2-transport>
<bandwidth>1000000</bandwidth>
</interface>
<interface>
<interface-name>GigabitEthernet0/0/0/1</interface-name>
<interface>GigabitEthernet0/0/0/1</interface>
<type>IFT_GETHERNET</type>
<state>im-state-admin-down</state>
<actual-state>im-state-admin-down</actual-state>
<line-state>im-state-admin-down</line-state>
<actual-line-state>im-state-admin-down</actual-line-state>
<encapsulation>ether</encapsulation>
<encapsulation-type-string>ARPA</encapsulation-type-string>
<mtu>1514</mtu>
<sub-interface-mtu-overhead>0</sub-interface-mtu-overhead>
<l2-transport>false</l2-transport>
<bandwidth>1000000</bandwidth>
</interface>
</interfaces>
</locationview>
<locationview>
<locationview-name>0/0/CPU0</locationview-name>
</locationview>
</locationviews>
</data-node>
</data-nodes>
</interface-properties>
</data>
</rpc-reply>

Important to note that data-node, locationview and interface are list elements and have to be handled properly!

Also, the get filter building must always start from the top level container!

Here is an example for getting properties of specific interface:

#!/usr/bin/env python
import ydk.models.cisco_ios_xr.Cisco_IOS_XR_ifmgr_oper as test
from ydk.services.netconf_service import NetconfService
from ydk.providers.netconf_provider import NetconfServiceProvider

import logging

log_ydk = logging.getLogger('ydk')
log_ydk.setLevel(logging.INFO)
handler = logging.StreamHandler()
log_ydk.addHandler(handler)

if __name__ == "__main__":
service = NetconfService()
provider = NetconfServiceProvider(address="sbx-iosxr-mgmt.cisco.com",
port=10000,
username="admin",
password="C1sco12345")
all_ifcs = test.InterfaceProperties()
my_data_node = test.InterfaceProperties.DataNodes.DataNode()
my_data_node.data_node_name = '0/RP0/CPU0'
all_ifcs.data_nodes.data_node.append(my_data_node)

my_locationview = test.InterfaceProperties.DataNodes.DataNode.Locationviews.Locationview()
my_locationview.locationview_name = '0/RP0/CPU0'
my_data_node.locationviews.locationview.append(my_locationview)

my_ifc = test.InterfaceProperties.DataNodes.DataNode.Locationviews.Locationview.Interfaces.Interface()
my_ifc.interface_name = 'GigabitEthernet0/0/0/0'
my_locationview.interfaces.interface.append(my_ifc)

my_ifc_props = service.get(provider, my_ifc)

And results:

Path where models are to be downloaded: /Users/ygorelik/.ydk/sbx-iosxr-mgmt.cisco.com
Connected to sbx-iosxr-mgmt.cisco.com on port 10000 using ssh with timeout of -1
Executing 'get' RPC on [Cisco-IOS-XR-ifmgr-oper:interface-properties]
============= 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-properties xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-oper">
<data-nodes>
<data-node>
<data-node-name>0/RP0/CPU0</data-node-name>
<locationviews>
<locationview>
<locationview-name>0/RP0/CPU0</locationview-name>
<interfaces>
<interface>
<interface-name>GigabitEthernet0/0/0/0</interface-name>
</interface>
</interfaces>
</locationview>
</locationviews>
</data-node>
</data-nodes>
</interface-properties></filter>
</get>
</rpc>
============= 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-properties xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-oper">
<data-nodes>
<data-node>
<data-node-name>0/RP0/CPU0</data-node-name>
<locationviews>
<locationview>
<locationview-name>0/RP0/CPU0</locationview-name>
<interfaces>
<interface>
<interface-name>GigabitEthernet0/0/0/0</interface-name>
<interface>GigabitEthernet0/0/0/0</interface>
<type>IFT_GETHERNET</type>
<state>im-state-admin-down</state>
<actual-state>im-state-admin-down</actual-state>
<line-state>im-state-admin-down</line-state>
<actual-line-state>im-state-admin-down</actual-line-state>
<encapsulation>ether</encapsulation>
<encapsulation-type-string>ARPA</encapsulation-type-string>
<mtu>1514</mtu>
<sub-interface-mtu-overhead>0</sub-interface-mtu-overhead>
<l2-transport>false</l2-transport>
<bandwidth>1000000</bandwidth>
</interface>
</interfaces>
</locationview>
</locationviews>
</data-node>
</data-nodes>
</interface-properties>
</data>
</rpc-reply>

 I hope that helps to understand the basics of building models.

Yan Gorelik
YDK Solutions

View solution in original post

Highlighted

Good day yangorelik!


Thank you so much for such a detailed answer

 

Your solution worked.
I encountered two issues after implementing your example:

 

The first was to find the "data_node_name". But the IT had the answer.
My data_node_name was: "0/RSP0/CPU0"


The second was that you use non-capital letters when appending and some words are snake case.
When you add models to variabels you use camel case. 

 

Still think the doc and guide in itself is not descriptive enough, but with your helped it went rather fast. Thank you again

 

Hope you get a lovely day,

Best regards,

Simon Johansen

This widget could not be displayed.