Back on the days where ifconfig.py was a PoC how a new system for managing interfaces could be it now has eveloped to a state where its very modular, but consists out of two brains. Actually those brains are 1 + <numer of interfaces>.
The implementation of vyos.ifconfig should be altered in a way to be more object oriented. The following items should be changed:
- Every interface-{bond|bridge|ethernet|...}.py file consists out of
- one big default_config_data dictionary which is partely the same on every interface
- one step where the dictionary is actually written into the underlaying hardware (partly this is also the same on all interfaces, set_admin_state(), set_mac(), ....
The change should rather provide an extended dictionary from vyos.ifconfig class. The dictionary grows by its inheritance level, every level adds some more entries to the dictionary itself, and in the end interface-{bond|bridge|ethernet|...}.py get_config() will just call config = deepcopy(InterfaceClass(().get_dict()) and the CLI config can now be read into the dictinary which is fully understood by vyos.ifconfig.
Once the dictionary is populated and verified it cna be applied in one single call to vyos.ifconfig.InterfaceClass() and the dictionary is again passed down the inheritancy tree and all settings are applied as single source. Adding / reworking and maintaining the code will thus become much more easy. Also delta checks (some parts can only be changed when interface is administratively down, e.g. MAC address) can be unified in one place.
So from a MAC address example, I need to disable the interface, I do this by calling set_admin_state('down'), the function internally keeps a reference counter and the interface is only disabled once ehwn the counter transits from 0 -> 1, and it is only enabled back when the counter resets itself back to 0 - thus no up/down flaps will occur.
Another good example for this is adding and removing members of a bridge / bond interface.