From 87435775ee6208b3773288f879e8b79ead1430b6 Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Tue, 27 Aug 2019 19:45:33 +0200 Subject: [PATCH] [enh] add --dry-run option to dyndns update --- data/actionsmap/yunohost.yml | 4 ++++ src/yunohost/dyndns.py | 23 ++++++++++++++--------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/data/actionsmap/yunohost.yml b/data/actionsmap/yunohost.yml index 454ccc76e..7c864cce0 100644 --- a/data/actionsmap/yunohost.yml +++ b/data/actionsmap/yunohost.yml @@ -1537,6 +1537,10 @@ dyndns: full: --force help: Force the update (for debugging only) action: store_true + -D: + full: --dry-run + help: Only display the generated zone + action: store_true -6: full: --ipv6 help: IPv6 address to send diff --git a/src/yunohost/dyndns.py b/src/yunohost/dyndns.py index 0a5b8c180..70b964b7c 100644 --- a/src/yunohost/dyndns.py +++ b/src/yunohost/dyndns.py @@ -33,7 +33,7 @@ import subprocess from moulinette import m18n from moulinette.core import MoulinetteError from moulinette.utils.log import getActionLogger -from moulinette.utils.filesystem import write_to_file +from moulinette.utils.filesystem import write_to_file, read_file from moulinette.utils.network import download_json from moulinette.utils.process import check_output @@ -176,7 +176,7 @@ def dyndns_subscribe(operation_logger, subscribe_host="dyndns.yunohost.org", dom @is_unit_operation() def dyndns_update(operation_logger, dyn_host="dyndns.yunohost.org", domain=None, key=None, - ipv4=None, ipv6=None, force=False): + ipv4=None, ipv6=None, force=False, dry_run=False): """ Update IP on DynDNS platform @@ -249,7 +249,7 @@ def dyndns_update(operation_logger, dyn_host="dyndns.yunohost.org", domain=None, logger.debug("Requested IPv4/v6 are (%s, %s)" % (ipv4, ipv6)) # no need to update - if not force and (old_ipv4 == ipv4 and old_ipv6 == ipv6): + if (not force and not dry_run) and (old_ipv4 == ipv4 and old_ipv6 == ipv6): logger.info("No updated needed.") return else: @@ -296,13 +296,18 @@ def dyndns_update(operation_logger, dyn_host="dyndns.yunohost.org", domain=None, logger.debug("Now pushing new conf to DynDNS host...") - try: - command = ["/usr/bin/nsupdate", "-k", key, DYNDNS_ZONE] - subprocess.check_call(command) - except subprocess.CalledProcessError: - raise YunohostError('dyndns_ip_update_failed') + if not dry_run: + try: + command = ["/usr/bin/nsupdate", "-k", key, DYNDNS_ZONE] + subprocess.check_call(command) + except subprocess.CalledProcessError: + raise YunohostError('dyndns_ip_update_failed') - logger.success(m18n.n('dyndns_ip_updated')) + logger.success(m18n.n('dyndns_ip_updated')) + else: + print(read_file(DYNDNS_ZONE)) + print("") + print("Warning: dry run, this is only the generated config, it won't be applied") def dyndns_installcron():