akarneliuk / pygnmi

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

Need help with replace method of Set operation. #115

Closed theabhishekghosh closed 1 year ago

theabhishekghosh commented 1 year ago

Trying to use replace method on the set op but getting syntax error:

Device is a Juniper PTX10001 running 22.3R1-S2.2-EVO with the following config:

lab@ptx10001-36mr# show openconfig-interfaces:interfaces interface et-0/0/1
config { type iana-interface-type; description "Test Interface"; }

replace.py file contents:

replace = [ ( "interfaces/interface[name=et-0/0/1]", { 'config' : {'type': 'iana-interface-type' , 'description': 'Test Interface-changed'} } ) ]

set_replace.py config :

!/usr/bin/env python

Modules

from pygnmi.client import gNMIclient

Variables

from inventory import hosts from replace import *

Body

if name == "main": paths = ['interfaces'] for host in hosts: with gNMIclient(target=(host["ip_address"], host["port"]), username=host["username"], password=host["password"], insecure=True) as gc: result = gc.get(path=paths) m = replace result = gc.set(replace=m)

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

===========

Keeps on giving syntax error, expecting "@";"

/home/abhishek/PycharmProjects/pythonProject/venv/bin/python /home/abhishek/PycharmProjects/pythonProject/set_replace.py GRPC ERROR Host: 10.219.38.146:50051, Error: syntax error, expecting "@"; Traceback (most recent call last): File "/home/abhishek/.local/lib/python3.8/site-packages/pygnmi/client.py", line 563, in set gnmi_message_response = self.stub.Set(gnmi_message_request, metadata=self.metadata) File "/home/abhishek/PycharmProjects/pythonProject/venv/lib/python3.8/site-packages/grpc/_channel.py", line 1030, in call return _end_unary_response_blocking(state, call, False, None) File "/home/abhishek/PycharmProjects/pythonProject/venv/lib/python3.8/site-packages/grpc/_channel.py", line 910, in _end_unary_response_blocking raise _InactiveRpcError(state) # pytype: disable=not-instantiable grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with: status = StatusCode.INVALID_ARGUMENT details = "syntax error, expecting "@";" debug_error_string = "UNKNOWN:Error received from peer ipv4:10.219.38.146:50051 {grpc_message:"syntax error, expecting \"@\";", grpc_status:3, created_time:"2023-04-06T23:11:04.4925047+05:30"}"

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/abhishek/PycharmProjects/pythonProject/set_replace.py", line 18, in result = gc.set(replace=m) File "/home/abhishek/.local/lib/python3.8/site-packages/pygnmi/client.py", line 621, in set raise gNMIException(f"GRPC ERROR Host: {self.__target_path}, Error: {err.details()}", err) pygnmi.client.gNMIException: GRPC ERROR Host: 10.219.38.146:50051, Error: syntax error, expecting "@";

Process finished with exit code 1

theabhishekghosh commented 1 year ago

This was a path issue. Fixed by changing the path in replace.py file.

    replace= [                      (                          "interfaces/interface[name=et-0/0/1]" ,                          {                              'name': 'et-0/0/1' , 'config' : {'type': 'iana-interface-type' , 'description': 'Test Interface-changed'}                          }                      )                    ]