Page MenuHomeVyOS Platform

Switch vyos.config to libvyosconfig
Open, NormalPublic

Description

Right now vyos.config relies on cli-shell-api for all its functionality. The reasons for it are twofold. First, originally it was a quick prototype made to see if configuration scripting in Python will catch on, and that was the simplest thing to do. Second, libvyattacfg is licensed under GPLv2 only (not "or any later version"), so all code that links to it must be under GPLv2 and nothing else. Calling an external program, however, is an accepted way to work around that issue (FSF agrees it's a legally clean).

That way we could make a Python library that could be published under LGPLv2+ so that it doesn't limit the license choice for authors of third party scripts and addons, and works reasonable well. However, the more code we rewrite in Python, the more noticeable its performance limitation become. At least one subprocesses is spawned every time a function is called, and cli-shell-api isn't exactly fast either.

For example, this scripts takes 22 seconds to run on VyOS 1.2.3:

#!/usr/bin/env python3
import vyos.config

c = vyos.config.Config()
n = 0
while (n <= 1000):
    v = c.return_value("system host-name")
    n += 1

At the same time, as @zsdc rightfully pointed out lately, now that we have a fully functional parser for the config files, and it has been used for migration scripts with great success, we can as well parse the output of cli-shell-api showCfg when a vyos.config.Config() object is initialized and then use libvyosconfig calls for reading values from it. From a quick test, a similar loop takes only a couple of seconds to run using that approach, an order of magnitude faster.

This will also allow some previously impossible things, such as listing all childeren of any node (tag or not).

Details

Difficulty level
Unknown (require assessment)
Version
-
Why the issue appeared?
Will be filled on close
Is it a breaking change?
Behavior change