summaryrefslogtreecommitdiff
path: root/python/vyos/util.py
diff options
context:
space:
mode:
authorsarthurdev <965089+sarthurdev@users.noreply.github.com>2021-06-17 18:08:58 +0200
committersarthurdev <965089+sarthurdev@users.noreply.github.com>2021-06-29 15:13:34 +0200
commit6f66e71e4622c54058b8689d4be730905d69fe22 (patch)
treefe0b2b4d097b88b7f62c27486ce25351119edd0f /python/vyos/util.py
parent09efa0550dd169e30a851513781b611dd84e9c79 (diff)
downloadvyos-1x-6f66e71e4622c54058b8689d4be730905d69fe22.tar.gz
vyos-1x-6f66e71e4622c54058b8689d4be730905d69fe22.zip
pki: T3642: New PKI config and management
Diffstat (limited to 'python/vyos/util.py')
-rw-r--r--python/vyos/util.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/python/vyos/util.py b/python/vyos/util.py
index c318d58de..c3bf481ea 100644
--- a/python/vyos/util.py
+++ b/python/vyos/util.py
@@ -566,6 +566,25 @@ def wait_for_commit_lock():
while commit_in_progress():
sleep(1)
+def ask_input(question, default='', numeric_only=False, valid_responses=[]):
+ question_out = question
+ if default:
+ question_out += f' (Default: {default})'
+ response = ''
+ while True:
+ response = input(question_out + ' ').strip()
+ if not response and default:
+ return default
+ if numeric_only:
+ if not response.isnumeric():
+ print("Invalid value, try again.")
+ continue
+ response = int(response)
+ if valid_responses and response not in valid_responses:
+ print("Invalid value, try again.")
+ continue
+ break
+ return response
def ask_yes_no(question, default=False) -> bool:
"""Ask a yes/no question via input() and return their answer."""