From 4b53e99b53c85beaea2b2d33286b66d8d63d9870 Mon Sep 17 00:00:00 2001 From: Indrajit Raychaudhuri Date: Sun, 3 Dec 2023 15:01:35 -0600 Subject: ddclient: T5791: Simplify and fix migration script for dynamic dns Mark 'dns dynamic name' as tag node to avoid unexpected nesting. --- src/migration-scripts/dns-dynamic/2-to-3 | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/migration-scripts/dns-dynamic/2-to-3 b/src/migration-scripts/dns-dynamic/2-to-3 index 02bc9324a..187c2a895 100755 --- a/src/migration-scripts/dns-dynamic/2-to-3 +++ b/src/migration-scripts/dns-dynamic/2-to-3 @@ -44,35 +44,38 @@ if not config.exists(address_path): # Nothing to do sys.exit(0) -# config.copy does not recursively create a path, so initialize the name path +# config.copy does not recursively create a path, so initialize the name path as tagged node if not config.exists(name_path): config.set(name_path) + config.set_tag(name_path) for address in config.list_nodes(address_path): + address_path_tag = address_path + [address] + # Move web-option as a configuration in each service instead of top level web-option - if config.exists(address_path + [address, 'web-options']) and address == 'web': + if config.exists(address_path_tag + ['web-options']) and address == 'web': for svc_type in ['service', 'rfc2136']: - if config.exists(address_path + [address, svc_type]): - for svc_cfg in config.list_nodes(address_path + [address, svc_type]): - config.copy(address_path + [address, 'web-options'], - address_path + [address, svc_type, svc_cfg, 'web-options']) - config.delete(address_path + [address, 'web-options']) + if config.exists(address_path_tag + [svc_type]): + for svc_cfg in config.list_nodes(address_path_tag + [svc_type]): + config.copy(address_path_tag + ['web-options'], + address_path_tag + [svc_type, svc_cfg, 'web-options']) + config.delete(address_path_tag + ['web-options']) for svc_type in ['service', 'rfc2136']: - if config.exists(address_path + [address, svc_type]): + if config.exists(address_path_tag + [svc_type]): # Move RFC2136 as service configuration, rename to avoid name conflict and set protocol to 'nsupdate' if svc_type == 'rfc2136': - for rfc_cfg_old in config.list_nodes(address_path + [address, 'rfc2136']): + for rfc_cfg_old in config.list_nodes(address_path_tag + ['rfc2136']): rfc_cfg_new = f'{rfc_cfg_old}-rfc2136' - config.rename(address_path + [address, 'rfc2136', rfc_cfg_old], rfc_cfg_new) - config.set(address_path + [address, 'rfc2136', rfc_cfg_new, 'protocol'], 'nsupdate') + config.rename(address_path_tag + ['rfc2136', rfc_cfg_old], rfc_cfg_new) + config.set(address_path_tag + ['rfc2136', rfc_cfg_new, 'protocol'], 'nsupdate') # Add address as config value in each service before moving the service path # And then copy the services from 'address service ' to 'name ' - for svc_cfg in config.list_nodes(address_path + [address, svc_type]): - config.set(address_path + [address, svc_type, svc_cfg, 'address'], address) - config.copy(address_path + [address, svc_type, svc_cfg], name_path + [svc_cfg]) + for svc_cfg in config.list_nodes(address_path_tag + [svc_type]): + config.set(address_path_tag + [svc_type, svc_cfg, 'address'], address) + config.copy(address_path_tag + [svc_type, svc_cfg], name_path + [svc_cfg]) # Finally cleanup the old address path config.delete(address_path) -- cgit v1.2.3