cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
485
Views
0
Helpful
2
Replies

using YDK unable to get output from cisco NCS5500 router

HI ,

Using YDK  , unable to get operational data from Cisco NCS 5500 router .

Error output

---------------

  File "test7.py", line 29, in <module>

    print("cpu util" is " +str(Cpu_util.total_cpu_one_minute))

AttributeError: 'YList' object has no attribute 'total_cpu_one_minute'

cpu util Script

--------------------

from ydk.services import CRUDService,CodecService

from ydk.providers import NetconfServiceProvider,CodecServiceProvider

from ydk.models.cisco_ios_xr import Cisco_IOS_XR_shellutil_oper \

as xr_shellutil_oper

from ydk.models.cisco_ios_xr import Cisco_IOS_XR_wdsysmon_fd_oper \

as xr_wd_oper

from datetime import timedelta

if __name__ == "__main__":

    """Main execution path"""

# create NETCONF session

provider = NetconfServiceProvider(address="192.168.30.167",

                                  username="fabtool",

                                  password="NatRas@321",

                                  protocol="ssh")

# create CRUD service

crud = CRUDService()

# create system time object

system_time = xr_wd_oper.SystemMonitoring.CpuUtilization()

print system_time.total_cpu_one_minute

Cpu_util= crud.read(provider, system_time,only_config=False)

print("Cpu util is " +str(Cpu_util.total_cpu_one_minute))

Kindly do the needful for resolution.

Thanks

Jay

1 ACCEPTED SOLUTION

Accepted Solutions
einarnn
Cisco Employee

Jay,

When you query the system monitoring subtree, the result you get back is not a simple scalar value. If you look at the YANG tree for the schema:

module: Cisco-IOS-XR-wdsysmon-fd-oper

+--ro system-monitoring

+--ro cpu-utilization*

+--ro node-name xr:Node-id

+--ro total-cpu-one-minute? uint32

+--ro total-cpu-five-minute? uint32

+--ro total-cpu-fifteen-minute? uint32

+--ro process-cpu*

+--ro process-name? string

+--ro process-id? uint32

+--ro process-cpu-one-minute? uint32

+--ro process-cpu-five-minute? uint32

+--ro process-cpu-fifteen-minute? uint32

This means that your print statement:

print("Cpu util is " +str(Cpu_util.total_cpu_one_minute))

…is just wrong. The error message ("AttributeError: 'YList' object has no attribute ‘total_cpu_one_minute’”) is also pointing this out to you. The CPU utilisation is a list entries, keyed by the node_name. Please try iterating over the return data. For example:

for c in Cpu_util:

print(‘Node %s one-minute CPU utilization is %d’ % (c.node_name, c.total_cpu_one_minute))

I haven’t tested this code, so it may not be 100% correct!

Cheers,

Einar

View solution in original post

2 REPLIES 2
einarnn
Cisco Employee

Jay,

When you query the system monitoring subtree, the result you get back is not a simple scalar value. If you look at the YANG tree for the schema:

module: Cisco-IOS-XR-wdsysmon-fd-oper

+--ro system-monitoring

+--ro cpu-utilization*

+--ro node-name xr:Node-id

+--ro total-cpu-one-minute? uint32

+--ro total-cpu-five-minute? uint32

+--ro total-cpu-fifteen-minute? uint32

+--ro process-cpu*

+--ro process-name? string

+--ro process-id? uint32

+--ro process-cpu-one-minute? uint32

+--ro process-cpu-five-minute? uint32

+--ro process-cpu-fifteen-minute? uint32

This means that your print statement:

print("Cpu util is " +str(Cpu_util.total_cpu_one_minute))

…is just wrong. The error message ("AttributeError: 'YList' object has no attribute ‘total_cpu_one_minute’”) is also pointing this out to you. The CPU utilisation is a list entries, keyed by the node_name. Please try iterating over the return data. For example:

for c in Cpu_util:

print(‘Node %s one-minute CPU utilization is %d’ % (c.node_name, c.total_cpu_one_minute))

I haven’t tested this code, so it may not be 100% correct!

Cheers,

Einar

View solution in original post

To add to Einar's response, you want to look at the documentation for the model.  In particular, you'll see that 'cpu_utilization' is a list and 'node_name' acts as key:

https://goo.gl/LJMZGQ

HTH.

Content for Community-Ad