pygnmi_call
Task plugin to manage devices over gNMI protocol.
Requires PyGNMI library to be installed:
pip install pygnmi
This task plugin is a wrapper around gNMIclient connection object
and allows to execute any of its methods supplying method name using
call attribute.
Sample code to run pygnmi_call task:
from nornir import InitNornir
from nornir_salt.plugins.tasks import pygnmi_call
nr = InitNornir(config_file="config.yaml")
# get device capabilities
capabilities = nr.run(
task=pygnmi_call,
call="capabilities"
)
# get interfaces configuration
get_output = nr.run(
task=pygnmi_call,
call="get",
path=["openconfig-interfaces:interfaces"]
)
# update interface description
update_output = nr.run(
task=pygnmi_call,
call="update",
update=[
(
"openconfig-interfaces:interfaces/interface[name=Loopback100]/config",
{"description": "Done by gNMI"}
)
]
)
# delete interface configuration
delete_output = nr.run(
task=pygnmi_call,
call="delete",
delete=[
"openconfig-interfaces:interfaces/interface[name=Loopback1234]"
]
)
# replace interface configuration
replace_output = nr.run(
task=pygnmi_call,
call="replace",
replace=[
(
"openconfig-interfaces:interfaces/interface[name=Loopback1234]/config",
{"name": "Loopback1234", "description": "New"}
)
]
)
In addition to calling gNMIclient methods, extra call functions supported
such as help, dir, delete, replace and update. Extra functions
can be invoked in the same way as gNMIclient connection object methods by passing
their name as a call attribute:
from nornir import InitNornir
from nornir_salt.plugins.tasks import pygnmi_call
nr = InitNornir(config_file="config.yaml")
available_methods = nr.run(
task=pygnmi_call,
call="dir",
)
pygnmi_call Reference
- nornir_salt.plugins.tasks.pygnmi_call.pygnmi_call(task: nornir.core.task.Task, call: str, name_arg: str = None, **kwargs) nornir.core.task.Result
Task to call one of PyGNMI
gNMIclientobject methods or one of additional helper functions.- Parameters
call – (str)
gNMIclientconnection object method to callkwargs – (dict) any
**kwargsto use with call methodname_arg – (str) used as “name” argument with call method, need it only because “name” argument used by “Nornir.run” method itself ans collides with the case when need to pass gNMI path
nameargument to this task
Special handling given to
path,delete,replaceandupdatedkwargs arguments to comply withgNMIclientrequirements:If
pathis a string, convert it to a list splitting it by,characterIf
deleteis a string, convert it to a list splitting it by,characterIf
replaceis a list, transform each list item to a tupleIf
updateis a list, transform each list item to a tuple
Additional Call Functions
delete
- nornir_salt.plugins.tasks.pygnmi_call._call_delete(connection, path: list, **kwargs)
Delete function helps to delete configuration elements matched by provided paths strings.
This function effectively takes arguments provided and uses
gNMIclientsetmethod supplying it withdeleteargument list that consists of path items strings.- Parameters
connection – (obj)
gNMIclientobjectpath – (list) path items to delete
Sample code to run
deletefunction task:from nornir import InitNornir from nornir_salt.plugins.tasks import pygnmi_call nr = InitNornir(config_file="config.yaml") output = nr.run( task=pygnmi_call, call="delete", path=["openconfig-interfaces:interfaces/interface[name=Loopback100]"] )
dir
- nornir_salt.plugins.tasks.pygnmi_call._call_dir(connection, **kwargs)
Function to return a list of
gNMIclientavailable methods/operations
help
- nornir_salt.plugins.tasks.pygnmi_call._call_help(connection, method_name: str, **kwargs)
Helper function to return docstring for requested method
- Parameters
method_name – (str) name of method or function to return docstring for
replace
- nornir_salt.plugins.tasks.pygnmi_call._call_replace(connection, path: list, **kwargs)
Replace function helps to replace configuration for elements matched by single path string.
This function effectively takes arguments provided and uses
gNMIclientsetmethod supplying it withreplaceargument list that consists of single tuple element, first item in this tuple is a provided path string with second item being a dictionary of provided**kwargscontaining configuration to be replaced.- Parameters
connection – (obj)
gNMIclientobjectpath – (list) list with single item - path to element to update config for
kwargs – (dict) configuration parameters to replace
Sample code to run
replacefunction task:from nornir import InitNornir from nornir_salt.plugins.tasks import pygnmi_call nr = InitNornir(config_file="config.yaml") output = nr.run( task=pygnmi_call, call="replace", path="openconfig-interfaces:interfaces/interface[name=Loopback100]/config", name="Loopback100", description="Loopback Description" )
update
- nornir_salt.plugins.tasks.pygnmi_call._call_update(connection, path: list, **kwargs)
Update function helps to update configuration for elements matched by single path string.
This function effectively takes arguments provided and uses
gNMIclientsetmethod supplying it withupdateargument list that consists of single tuple element, first item in this tuple is a provided path string with second item being a dictionary of provided**kwargscontaining configuration to be updated.- Parameters
connection – (obj)
gNMIclientobjectpath – (list) list with single item - path to element to update config for
kwargs – (dict) configuration parameters to update
Sample code to run
replacefunction task:from nornir import InitNornir from nornir_salt.plugins.tasks import pygnmi_call nr = InitNornir(config_file="config.yaml") output = nr.run( task=pygnmi_call, call="update", path="openconfig-interfaces:interfaces/interface[name=Loopback100]/config", description="Updated Loopback Description" )