Skip to content

Commit

Permalink
Merge pull request #2076 from jestabro/accel-dict
Browse files Browse the repository at this point in the history
vyos.configdict: T5319: remove workarounds for incorrect defaults in get_accel_dict
  • Loading branch information
dmbaturin authored Jul 6, 2023
2 parents e47668d + 7147c7c commit e8ff7aa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 74 deletions.
78 changes: 6 additions & 72 deletions python/vyos/configdict.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,40 +595,8 @@ def get_accel_dict(config, base, chap_secrets):

dict = config.get_config_dict(base, key_mangling=('-', '_'),
get_first_key=True,
no_tag_node_value_mangle=True)

# We have gathered the dict representation of the CLI, but there are default
# options which we need to update into the dictionary retrived.
default_values = defaults(base)

# T2665: defaults include RADIUS server specifics per TAG node which need to
# be added to individual RADIUS servers instead - so we can simply delete them
if dict_search('authentication.radius.server', default_values):
del default_values['authentication']['radius']['server']

# T2665: defaults include static-ip address per TAG node which need to be
# added to individual local users instead - so we can simply delete them
if dict_search('authentication.local_users.username', default_values):
del default_values['authentication']['local_users']['username']

# T2665: defaults include IPv6 client-pool mask per TAG node which need to be
# added to individual local users instead - so we can simply delete them
if dict_search('client_ipv6_pool.prefix.mask', default_values):
del default_values['client_ipv6_pool']['prefix']['mask']
# delete empty dicts
if len (default_values['client_ipv6_pool']['prefix']) == 0:
del default_values['client_ipv6_pool']['prefix']
if len (default_values['client_ipv6_pool']) == 0:
del default_values['client_ipv6_pool']

# T2665: IPoE only - it has an interface tag node
# added to individual local users instead - so we can simply delete them
if dict_search('authentication.interface', default_values):
del default_values['authentication']['interface']
if dict_search('interface', default_values):
del default_values['interface']

dict = dict_merge(default_values, dict)
no_tag_node_value_mangle=True,
with_recursive_defaults=True)

# set CPUs cores to process requests
dict.update({'thread_count' : get_half_cpus()})
Expand All @@ -648,43 +616,9 @@ def get_accel_dict(config, base, chap_secrets):
dict.update({'name_server_ipv4' : ns_v4, 'name_server_ipv6' : ns_v6})
del dict['name_server']

# T2665: Add individual RADIUS server default values
if dict_search('authentication.radius.server', dict):
default_values = defaults(base + ['authentication', 'radius', 'server'])
for server in dict_search('authentication.radius.server', dict):
dict['authentication']['radius']['server'][server] = dict_merge(
default_values, dict['authentication']['radius']['server'][server])

# Check option "disable-accounting" per server and replace default value from '1813' to '0'
# set vpn sstp authentication radius server x.x.x.x disable-accounting
if 'disable_accounting' in dict['authentication']['radius']['server'][server]:
dict['authentication']['radius']['server'][server]['acct_port'] = '0'

# T2665: Add individual local-user default values
if dict_search('authentication.local_users.username', dict):
default_values = defaults(base + ['authentication', 'local-users', 'username'])
for username in dict_search('authentication.local_users.username', dict):
dict['authentication']['local_users']['username'][username] = dict_merge(
default_values, dict['authentication']['local_users']['username'][username])

# T2665: Add individual IPv6 client-pool default mask if required
if dict_search('client_ipv6_pool.prefix', dict):
default_values = defaults(base + ['client-ipv6-pool', 'prefix'])
for prefix in dict_search('client_ipv6_pool.prefix', dict):
dict['client_ipv6_pool']['prefix'][prefix] = dict_merge(
default_values, dict['client_ipv6_pool']['prefix'][prefix])

# T2665: IPoE only - add individual local-user default values
if dict_search('authentication.interface', dict):
default_values = defaults(base + ['authentication', 'interface'])
for interface in dict_search('authentication.interface', dict):
dict['authentication']['interface'][interface] = dict_merge(
default_values, dict['authentication']['interface'][interface])

if dict_search('interface', dict):
default_values = defaults(base + ['interface'])
for interface in dict_search('interface', dict):
dict['interface'][interface] = dict_merge(default_values,
dict['interface'][interface])
# Check option "disable-accounting" per server and replace default value from '1813' to '0'
for server in (dict_search('authentication.radius.server', dict) or []):
if 'disable_accounting' in dict['authentication']['radius']['server'][server]:
dict['authentication']['radius']['server'][server]['acct_port'] = '0'

return dict
4 changes: 2 additions & 2 deletions python/vyos/xml_ref/definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ def _get_default(self, node: dict) -> Optional[Union[str, list]]:
default = self._get_default_value(node)
if default is None:
return None
if self._is_multi_node(node) and not isinstance(default, list):
return [default]
if self._is_multi_node(node):
return default.split()
return default

def get_defaults(self, path: list, get_first_key=False, recursive=False) -> dict:
Expand Down

0 comments on commit e8ff7aa

Please sign in to comment.