Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions src/op_mode/dhcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,31 @@ def _wrapper(*args, **kwargs):
v = 'v6' if family == 'inet6' else ''
interface = kwargs.get('interface')
interface_path = Section.get_config_path(interface)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if Section.get_config_path(interface) should return a list instead, as we mostly work with lists - but this is another discussion.

path_elems = interface_path.split()
base_path = ['interfaces'] + path_elems

unconf_message = f'DHCP{v} client not configured on interface {interface}!'

# Check if config does not exist
if not config.exists(f'interfaces {interface_path} address dhcp{v}'):
iface_conf = config.get_config_dict(
base_path, key_mangling=('-', '_'), get_first_key=True
)

if family == 'inet6':
addrs = iface_conf.get('address', [])
has_dhcpv6_addr = 'dhcpv6' in addrs

dhcpv6_opts = iface_conf.get('dhcpv6_options', {})
has_parameters_only = 'parameters_only' in dhcpv6_opts
has_pd = 'pd' in dhcpv6_opts

config_exists = has_dhcpv6_addr or has_parameters_only or has_pd
else:
addrs = iface_conf.get('address', [])
config_exists = 'dhcp' in addrs

if not config_exists:
raise vyos.opmode.UnconfiguredObject(unconf_message)

return func(*args, **kwargs)

return _wrapper
Expand Down
Loading