summaryrefslogtreecommitdiff
path: root/src/conf_mode/dns_dynamic.py
diff options
context:
space:
mode:
authorIndrajit Raychaudhuri <irc@indrajit.com>2023-06-06 12:55:57 -0500
committerIndrajit Raychaudhuri <irc@indrajit.com>2023-06-06 22:31:36 -0500
commitdbe8189d54b89bdbec65e852ac591546e77d19a1 (patch)
tree30f8489a6c2bc890fb818bec08e79b15db8201ca /src/conf_mode/dns_dynamic.py
parentb1e379f2a298de58445a0565f889faff920e82f3 (diff)
downloadvyos-1x-dbe8189d54b89bdbec65e852ac591546e77d19a1.tar.gz
vyos-1x-dbe8189d54b89bdbec65e852ac591546e77d19a1.zip
dns: T5144: Handle partial conf mode CLI gracefully
Prevent failure when the user enters a partial CLI command without any address specified. Also, apply some minor formatting changes.
Diffstat (limited to 'src/conf_mode/dns_dynamic.py')
-rwxr-xr-xsrc/conf_mode/dns_dynamic.py30
1 files changed, 17 insertions, 13 deletions
diff --git a/src/conf_mode/dns_dynamic.py b/src/conf_mode/dns_dynamic.py
index f97225370..e070a3502 100755
--- a/src/conf_mode/dns_dynamic.py
+++ b/src/conf_mode/dns_dynamic.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
#
-# Copyright (C) 2018-2020 VyOS maintainers and contributors
+# Copyright (C) 2018-2023 VyOS maintainers and contributors
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or later as
@@ -51,20 +51,21 @@ def get_config(config=None):
dyndns = conf.get_config_dict(base_level, key_mangling=('-', '_'), get_first_key=True)
- for address in dyndns['address']:
- # Apply service specific defaults (stype = ['rfc2136', 'service'])
- for svc_type in dyndns['address'][address]:
- default_values = defaults(base_level + ['address', svc_type])
- for svc_cfg in dyndns['address'][address][svc_type]:
- dyndns['address'][address][svc_type][svc_cfg] = dict_merge(
- default_values, dyndns['address'][address][svc_type][svc_cfg])
+ if 'address' in dyndns:
+ for address in dyndns['address']:
+ # Apply service specific defaults (svc_type = ['rfc2136', 'service'])
+ for svc_type in dyndns['address'][address]:
+ default_values = defaults(base_level + ['address', svc_type])
+ for svc_cfg in dyndns['address'][address][svc_type]:
+ dyndns['address'][address][svc_type][svc_cfg] = dict_merge(
+ default_values, dyndns['address'][address][svc_type][svc_cfg])
dyndns['config_file'] = config_file
return dyndns
def verify(dyndns):
# bail out early - looks like removal from running config
- if not dyndns:
+ if not dyndns or 'address' not in dyndns:
return None
for address in dyndns['address']:
@@ -97,16 +98,18 @@ def verify(dyndns):
if config['ip_version'] == 'both':
if config['protocol'] not in dualstack_supported:
- raise ConfigError(f'"{config["protocol"]}" does not support IPv4 and IPv6 at the same time')
+ raise ConfigError(f'"{config["protocol"]}" does not support '
+ f'both IPv4 and IPv6 at the same time')
# dyndns2 protocol in ddclient honors dual stack only for dyn.com (dyndns.org)
if config['protocol'] == 'dyndns2' and 'server' in config and config['server'] != 'members.dyndns.org':
- raise ConfigError(f'"{config["protocol"]}" for "{config["server"]}" does not support IPv4 and IPv6 at the same time')
+ raise ConfigError(f'"{config["protocol"]}" does not support '
+ f'both IPv4 and IPv6 at the same time for "{config["server"]}"')
return None
def generate(dyndns):
# bail out early - looks like removal from running config
- if not dyndns:
+ if not dyndns or 'address' not in dyndns:
return None
render(config_file, 'dns-dynamic/ddclient.conf.j2', dyndns)
@@ -114,7 +117,8 @@ def generate(dyndns):
return None
def apply(dyndns):
- if not dyndns:
+ # bail out early - looks like removal from running config
+ if not dyndns or 'address' not in dyndns:
call('systemctl stop ddclient.service')
if os.path.exists(config_file):
os.unlink(config_file)