Programmatic config modification

340 views
Skip to first unread message

Ian Barrere

unread,
Apr 24, 2024, 10:36:15 PMApr 24
to sonicproject
Hello,

What method do most people use for managing the config of their SONiC devices? It seems that REST and gNMI require some additional steps to get going (exposing additional YANG models, etc), so I'm wondering if there's a more suitable "out of the box" method that people are using, like interacting directly with the redis database, for example.

If possible I would like to hear some real world use cases to help guide me on how best to integrate our SONiC switches into our automation system.

Thanks,
Ian

Taavi Ansper

unread,
May 15, 2024, 9:43:54 AMMay 15
to sonicproject
I am trying to configure the switches via gnmi. I tried to use different ansible modules from dellemc.ansible-collection to communicate via cli or httapi and nokia.grpc one to communicate with gnmi (As it should be vendor agnostic), there is still another community one, that I haven't tried, but because the list of features does not seem to be too long, I haven't tested it yet.


Currently the best I have found is GNMI via nornir and pygnmi.

1. nornir for automation
2. nornir_ansible (plugin) - ansible as my inventory (As we have everything else in ansible.)
3. nornir_pygnmi (rather simple plugin for nornir to connect to hosts via pygnmi lib)
4. ???
5. kind of profit

I have not used pure python in a while and it feels refreshing to do things I can not do in ansible as fast and quickly, as I can in python. It is also much faster than normal ansible.

The caveats are, that all of the models do not yet seem to be in the sonic build and I am getting weird errors when updating some parts of the models. I am currently modifying config-db:/CONFIB_DB/localhost

Best Wishes,
Taavi

Ian Barrere

unread,
May 15, 2024, 10:12:41 AMMay 15
to Taavi Ansper, sonicproject
Thanks, Taavi. This is good information.

You are a bit ahead of me, as I have not even managed to get gNMI working yet. However, I have written a lightweight network automation stack in Python which also uses pygnmi (I will release it open source later this year) that I’m using with our other hosts (a mix of NX-OS and IOS-XR) to good effect so far, so I would really like to get our SONiC switches managed with that as well.

Do you recall the approximate steps you used to get gNMI working? I can run get calls toward my gear, but set seems to be disabled, and the list of models supported out of the box is very small (interfaces, and a few other things).

Best,
Ian

--
You received this message because you are subscribed to a topic in the Google Groups "sonicproject" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sonicproject/xaivs-d8U-U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sonicproject...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonicproject/e04d87bd-874d-479f-b588-3e6b3746122en%40googlegroups.com.

Taavi Ansper

unread,
May 15, 2024, 11:51:17 AMMay 15
to sonicproject
Hey

So far I am also testing SONiC as an virtual appliance. E.g. sonic-vs on a gns3 platform. One of the features I wanted was ICCPD(MCLAG), so I compiled it from the source, per sonic-buildimage instructions. I found out that for set to work with pygnmi and json_ietf something called translib write needed to be enabled -> https://github.com/sonic-net/sonic-buildimage/blob/31f2c7c09142197d32fbc36aa20bc765db00d53e/rules/config#L163

By default translib write is disabled in the image that is built for everybody.

I am currently building a new version from the latest master commit, as I have a feeling that just last week new stuff regarding the YANG models was merged, but I need to verify it.

Best wishes,
Taavi

Taavi Ansper

unread,
May 16, 2024, 3:32:40 AMMay 16
to sonicproject
Nvm

It still seems to have the same problems. I have pointed them out here: https://github.com/sonic-net/sonic-gnmi/issues/238

I am using the config-db model. And I have run into this issue with both SYSLOG_SERVER and NTP_SERVER. I can imagine there are more of these. It actually does insert the data, but it cannot finish the operation as it wishes. I have also configured some stuff using openconfig-interfaces, and that seems to work nicely. E.g. I have removed default IP from interfaces and changed MTU from 9100 to 1500.

Taavi Ansper

unread,
May 16, 2024, 4:09:04 AMMay 16
to sonicproject

But what do we need to do to make them available in the 'get-compatibilities' part of the GNMI interface? Currently, there is some talk about 'it will be done in the future' or what not, but maybe somebody can point this out, so the community can help aswell, or atleast try to?

Best wishes,
Taavi

On Wednesday, May 15, 2024 at 6:51:17 PM UTC+3 Taavi Ansper wrote:

Ian Barrere

unread,
May 16, 2024, 10:47:17 AMMay 16
to Taavi Ansper, sonicproject
I actually asked this same question some months ago here: https://groups.google.com/g/sonicproject/c/txLcm3Uvc7s/m/Gh2L0tTcAAAJ?utm_medium=email&utm_source=footer, and Sachin mentioned that you can update the import.mk file to build a new image with the models you chose. I haven’t figured out how to do that yet though.


Taavi Ansper

unread,
May 20, 2024, 8:07:12 AMMay 20
to sonicproject
I tried to update the import.mk file when using sonic-buildimage, but when using gnmi with 'get_capabilities', the list remains the same. 


{ 'gnmi_version': '0.7.0',
  'supported_encodings': ['json', 'json_ietf', 'proto'],
  'supported_models': [ { 'name': 'openconfig-acl',
                          'organization': 'OpenConfig working group',
                          'version': '1.0.2'},
                        { 'name': 'openconfig-acl',
                          'organization': 'OpenConfig working group',
                          'version': ''},
                        { 'name': 'openconfig-sampling-sflow',
                          'organization': 'OpenConfig working group',
                          'version': ''},
                        { 'name': 'openconfig-interfaces',
                          'organization': 'OpenConfig working group',
                          'version': ''},
                        { 'name': 'openconfig-lldp',
                          'organization': 'OpenConfig working group',
                          'version': '1.0.2'},
                        { 'name': 'openconfig-platform',
                          'organization': 'OpenConfig working group',
                          'version': '1.0.2'},
                        { 'name': 'openconfig-system',
                          'organization': 'OpenConfig working group',
                          'version': '1.0.2'},
                        { 'name': 'ietf-yang-library',
                          'organization': 'IETF NETCONF (Network '
                                          'Configuration) Working Group',
                          'version': '2016-06-21'},
                        { 'name': 'sonic-db',
                          'organization': 'SONiC',
                          'version': '0.1.0'}]
}

From your previous post I noticed Jeff Yin seems knowledgable on the topic, maybe he could point us, what is currently possible and what is not?

I tried to use the sonic-db model that is at revision 0.1.0. I do not know, where the model files for that are or if they are updated. I can update some data via sonic-db model, but it is buggy. E.g. NTP_SERVER conf is set, but i get an error message back, even though it does set the config. I have created an issue aswell: https://github.com/sonic-net/sonic-gnmi/issues/238

openconfig-interfaces seems to work aswell. Others not-so-much. openconfig-acl responds, but returns an empty dict always.

Also try to use encoding 'json_ietf'. Encoding json returned weird errors aswell. And proto seems something lower level and I do not know what is the format for configuring that way.

sonic-db:CONFIG_DB/VLAN and sonic-db:CONFIB_DB/PORTCHANNEL  seem to missing also.


But the next question for me is, why are they there are and where they used ? For me the models in that directory feel like 'docs' or design, or whatever. Some of the models that we can actually use via GNMI are located here: https://github.com/sonic-net/sonic-mgmt-common/blob/master/models/yang/README.md

Does this mean the sonic-mgmt-common is the part where they are implemented from the docs?

Taavi Ansper

unread,
May 20, 2024, 8:09:44 AMMay 20
to sonicproject
I think sonic-db:CONFIG_DB is not part of the YANG thing... therefor it is not in that directory...

Taavi Ansper

unread,
May 20, 2024, 8:26:09 AMMay 20
to sonicproject
So what I am feeling is going on is that the sonic YANG models specified in the sonic-buildimage repo are meant for intercommunication between config CLI and so on. But these models do not help out our little gnmi tool. Currently the sonic-db:CONFIG_DB is doesn't seem to get any love and issues there bound to remain in their current state. But we have a new hope coming in form of openconfig yang models, which are slowly being implemented and added, as also specified in your previous post, by Jeff.

Taavi Ansper

unread,
May 20, 2024, 8:36:32 AMMay 20
to sonicproject
The error message I am getting seems to come from here: https://github.com/sonic-net/sonic-utilities/blob/master/config/main.py#L1482

Taavi Ansper

unread,
May 20, 2024, 8:54:35 AMMay 20
to sonicproject
When getting sonic-db:CONFIG_DB/localhost/VLAN the result seems to be like this unfortunately aswell...

details = "Failed to find CONFIG_DB VLAN <nil> []"
Reply all
Reply to author
Forward
0 new messages