summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2021-11-11 19:56:02 +0100
committerGitHub <noreply@github.com>2021-11-11 19:56:02 +0100
commite6e09a039fe4e81f5825d049a6c50197958e75de (patch)
tree08a0d65ec81370d58ce47d095a832426f478d353 /python
parent7357be6b5d77d3edabd7d75c402d8732770c6361 (diff)
parent23691df934ff3714b8f523ce96ce3fbced066be1 (diff)
downloadvyos-1x-e6e09a039fe4e81f5825d049a6c50197958e75de.tar.gz
vyos-1x-e6e09a039fe4e81f5825d049a6c50197958e75de.zip
Merge pull request #1066 from sarthurdev/pki_install
pki: T3970: Allow op-mode PKI commands in a config session to install directly
Diffstat (limited to 'python')
-rw-r--r--python/vyos/util.py30
1 files changed, 29 insertions, 1 deletions
diff --git a/python/vyos/util.py b/python/vyos/util.py
index 2c4051a7a..9c4c29322 100644
--- a/python/vyos/util.py
+++ b/python/vyos/util.py
@@ -664,7 +664,6 @@ def ask_yes_no(question, default=False) -> bool:
except EOFError:
stdout.write("\nPlease respond with yes/y or no/n\n")
-
def is_admin() -> bool:
"""Look if current user is in sudo group"""
from getpass import getuser
@@ -903,3 +902,32 @@ def check_port_availability(ipaddress, port, protocol):
return True
except:
return False
+
+def install_into_config(conf, config_paths, override_prompt=True):
+ # Allows op-mode scripts to install values if called from an active config session
+ # config_paths: dict of config paths
+ # override_prompt: if True, user will be prompted before existing nodes are overwritten
+
+ if not config_paths:
+ return None
+
+ from vyos.config import Config
+
+ if not Config().in_session():
+ print('You are not in configure mode, commands to install manually from configure mode:')
+ for path in config_paths:
+ print(f'set {path}')
+ return None
+
+ count = 0
+
+ for path in config_paths:
+ if override_prompt and conf.exists(path) and not conf.is_multi(path):
+ if not ask_yes_no(f'Config node "{node}" already exists. Do you want to overwrite it?'):
+ continue
+
+ cmd(f'/opt/vyatta/sbin/my_set {path}')
+ count += 1
+
+ if count > 0:
+ print(f'{count} value(s) installed. Use "compare" to see the pending changes, and "commit" to apply.')