akarneliuk / pygnmi

The pure Python implementation of the gNMI client.
https://training.karneliuk.com
BSD 3-Clause "New" or "Revised" License
129 stars 44 forks source link

Nokia: minor mgmt_core: Unknown element #9

Closed laimaretto closed 3 years ago

laimaretto commented 3 years ago

Hi there! First of all, thanks for this library: it looks awesome!

You know I've been trying what I think is the simplest example, as you show in the main page of the project:

# modules
from pygnmi.client import gNMIclient, telemetryParser

# variables
host =    {
        "ip_address": "192.168.122.12",
        "nos": "nokia-sros",
        "port": 57400,
        "username": "admin",
        "password": "admin",
    }

paths = ['openconfig-interfaces:show router interface']

with gNMIclient(
        target   = (host['ip_address'],host['port']), 
        username = host['username'],
        password = host['password'],
        insecure = True
        ) as gc:
    result = gc.get(path=paths)

After that, I get an error:

Host: 192.168.122.12:57400
Error: MINOR: MGMT_CORE #2201: /show router interface - Unknown element
CRITICAL:root:Host: 192.168.122.12:57400, Error: MINOR: MGMT_CORE #2201: /show router interface - Unknown element
ERROR:root:Internal Python error in the inspect module.
Below is the traceback from this internal error.

In the router I do have grpc enabled, and so gnmi.

A:rtr2# show system grpc       
===============================================================================
gRPC Server
===============================================================================
Administrative State      : Enabled
Operational State         : Up

Supported services
-------------------------------------------------------------------------------
gNMI Version              : 0.4.0
RibApi Version            : 1.0.0

Nevertheless my guess is there is something wrong either with the path variable of some configuration missing in the router. All I want to do is to get the list of interfaces as you can see in the path variable.

Could you help me with this? Thanks!!

Lucas

akarneliuk commented 3 years ago

Hello @laimaretto ,

Thanks for your kind response. Your path is not accurate, i am afraid.

By it looks, you are trying to poll info about routing interfaces, but that doesn't match any YANG modules.

Do you have interfaces configured using openconfig models? In Nokia SR OS it must be explicitly configured.

Best, Anton

laimaretto commented 3 years ago

Hi @akarneliuk, thanks for the reply.

Ok, I see ... as per your comment I should check the openconfig and/or YANG configuration inside the router ... didn't do it nor don't know how to do it ...

But let me check that out first ... I'm might come back here with some other doubts ... ;-)

Regards!

Lucas

akarneliuk commented 3 years ago

Yep, basically, it could be that Nokia native models are used, we would need to tweak the path either. Best, Anton

akarneliuk commented 3 years ago

Hello @laimaretto ,

did you have a chance to check the Nokia config?

Best, Anton

laimaretto commented 3 years ago

Hi @akarneliuk , so I basically was following this link from NoKia on how to enable YANG models and also the model-driven. There are three kind of YANG models that I can enable with my release 16.0.

*[gl:configure]
A:admin@rtr2# tree flat | match yang                                                
system management-interface yang-modules
system management-interface yang-modules base-r13-modules
system management-interface yang-modules nokia-combined-modules
system management-interface yang-modules nokia-modules
system management-interface yang-modules openconfig-modules

So this is the configuration that I have enabled:

    system {
        name "rtr2"
        grpc {
            admin-state enable
            allow-unsecure-connection
            rib-api {
                admin-state enable
            }
        }
        management-interface {
            configuration-mode model-driven
            yang-modules {
                base-r13-modules true
                nokia-modules true
                openconfig-modules true
                nokia-combined-modules true
            }
        }

However, after setting paths = ["gl:configure router Base interface system"] and ...

with gNMIclient(
        target   = (host['ip_address'],host['port']), 
        username = host['username'],
        password = host['password'],
        insecure = True
        ) as gc:
    result = gc.get(path=paths)

... all I get is...

Host: 192.168.122.12:57400
Error: MINOR: MGMT_CORE #2201: /configure router Base interface system - Unknown element
CRITICAL:root:Host: 192.168.122.12:57400, Error: MINOR: MGMT_CORE #2201: /configure router Base interface system - Unknown element
ERROR:root:Internal Python error in the inspect module.

Which is weird since I can get that information from within the console, as follows:

*[gl:configure router "Base" interface "system"]
A:admin@rtr2# info
    ipv4 {
        primary {
            address 172.16.0.12
            prefix-length 32
        }
    }

For sure is something I'm missing, either on enabling some configuration within the router, or something with the declaration of the path variable ...

Any hint from your side will be of help ...

Thanks!

Lucas

akarneliuk commented 3 years ago

Hey @laimaretto ,

Yeah, your path should follow YANG module, not the CLI. In the Nokia native modules you should have /nokia-conf:configure/router[router-name=Base]/interface[interface-name=system].

Here is the example:

$ cat gnmi_get.py 
#!/usr/bin/env python

# Modules
from pygnmi.client import gNMIclient

# Variables
host = {"ip_address": "10.0.0.1", "port": 57400}

# Body
if __name__ == "__main__":
    paths = ['/nokia-conf:configure/router[router-name=Base]/interface[interface-name=system]']

    with gNMIclient(target=(host["ip_address"], host["port"]), username="***",
                    password="***", insecure=True) as gc:
        result = gc.get(path=paths, encoding='json')

    print(f"{host['ip_address']}: {result}\n\n")

And result:

10.0.0.1: {'notification': [{'timestamp': 1619463746816959227, 'update': [{'path': 'configure/router[router-name=Base]/interface[interface-name=system]', 'val': {'interface-name': 'system', 'admin-state': 'enable', 'ipv4': {'bfd': {'admin-state': 'enable', 'transmit-interval': 100, 'receive': 100, 'multiplier': 3, 'type': 'cpm-np'}, 'primary': {'address': '10.10.10.10', 'prefix-length': 32}}, 'ipv6': {'bfd': {'admin-state': 'enable', 'transmit-interval': 100, 'receive': 100, 'multiplier': 3, 'type': 'cpm-np'}, 'address': [{'ipv6-address': 'fc00:10:10:10::10', 'prefix-length': 128}]}}}]}]}

Make sure you download the latest version of pygnmi we published yesterday.

Best, Anton

akarneliuk commented 3 years ago

Hey @laimaretto ,

We haven't heard from you for a bit and provide the example. Please, re-open the issue or open the new one if further assistance is needed.

Best, Anton