Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config: T5330: add boolean check for additions by default in config dict #2079

Merged
merged 3 commits into from Jul 12, 2023

Conversation

jestabro
Copy link
Contributor

@jestabro jestabro commented Jul 7, 2023

Change Summary

For a config dict returned with defaults automatically merged (as in the case of get_interface_dict; get_accel_dict; or get_config_dict(..., with_defaults=True | with_recursive_defaults=True) ), it may be useful to know if an entry was set in CLI, or only merged with defaults: retain this information internally and add a configdict method from_defaults -> bool.

Simple example:

>>> conf = Config()
>>> base = ['interfaces', 'ethernet']
>>> # no defaults:
>>> d = conf.get_config_dict(base, get_first_key=True)
>>> pprint(d)
{'eth0': {'address': ['dhcp'],
          'description': 'test',
          'hw-id': '52:54:00:ad:9f:43',
          'ip': {'arp-cache-timeout': '40'}}}
>>> # merged defaults:
>>> _, d = get_interface_dict(conf, base, ifname='eth0')
>>> pprint(d)
{'address': ['dhcp'],
 'description': 'test',
 'dhcp_options': {'default_route_distance': '210'},
 'duplex': 'auto',
 'hw_id': '52:54:00:ad:9f:43',
 'ifname': 'eth0',
 'ip': {'arp_cache_timeout': '40'},
 'mtu': '1500',
 'speed': 'auto'}
>>> d.from_defaults(['mtu'])
True
>>> d.from_defaults(['dhcp_options'])
True
>>> d.from_defaults(['ip'])
False
>>> d.from_defaults(['ip', 'arp_cache_timeout'])
False

The method is present in the above cases get_interface_dict, get_accel_dict, get_config_dict(..., with_defaults=True | with_recursive_defaults=True).

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes)
  • Migration from an old Vyatta component to vyos-1x, please link to related PR inside obsoleted component
  • Other (please describe):

Related Task(s)

Component(s) name

Proposed changes

How to test

Checklist:

  • I have read the CONTRIBUTING document
  • I have linked this PR to one or more Phabricator Task(s)
  • I have run the components SMOKETESTS if applicable
  • My commit headlines contain a valid Task id
  • My change requires a change to the documentation
  • I have updated the documentation accordingly

@jestabro jestabro self-assigned this Jul 7, 2023
@vyosbot vyosbot requested review from a team, dmbaturin, sarthurdev, zdc, sever-sever and c-po and removed request for a team July 7, 2023 14:13
@c-po
Copy link
Member

c-po commented Jul 8, 2023

Very cool, @zdc that's what you requested?

@dmbaturin dmbaturin merged commit 0378577 into vyos:current Jul 12, 2023
6 of 7 checks passed
@jestabro jestabro deleted the from-defaults branch September 1, 2023 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants