summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2020-04-10 08:01:52 -0500
committerJohn Estabrook <jestabro@vyos.io>2020-04-10 09:35:26 -0500
commita32cb241eaf8971bd27713e32f3804d77a9d39ee (patch)
tree9144d1ef081acdb90347faf6eac5b444f15961e6 /python
parent18859e32c4f282e74ea504a04eee92daa6993d89 (diff)
downloadvyos-1x-a32cb241eaf8971bd27713e32f3804d77a9d39ee.tar.gz
vyos-1x-a32cb241eaf8971bd27713e32f3804d77a9d39ee.zip
Revert "Revert "util: T2226: rewrite remote function helpers to use cmd""
This reverts commit 10717c6a3cdf7da7025b03c1abdbd813b4970b19.
Diffstat (limited to 'python')
-rw-r--r--python/vyos/remote.py29
1 files changed, 11 insertions, 18 deletions
diff --git a/python/vyos/remote.py b/python/vyos/remote.py
index f8a21f068..f0bf41cd4 100644
--- a/python/vyos/remote.py
+++ b/python/vyos/remote.py
@@ -17,7 +17,8 @@ import sys
import os
import re
import fileinput
-import subprocess
+
+from vyos.util import cmd, DEVNULL
def check_and_add_host_key(host_name):
@@ -33,10 +34,8 @@ def check_and_add_host_key(host_name):
keyscan_cmd = 'ssh-keyscan -t rsa {} 2>/dev/null'.format(host_name)
try:
- host_key = subprocess.check_output(keyscan_cmd, shell=True,
- stderr=subprocess.DEVNULL,
- universal_newlines=True)
- except subprocess.CalledProcessError as err:
+ host_key = cmd(keyscan_cmd, stderr=DEVNULL, universal_newlines=True)
+ except OSError:
sys.exit("Can not get RSA host key")
# libssh2 (jessie; stretch) does not recognize ec host keys, and curl
@@ -64,10 +63,8 @@ def check_and_add_host_key(host_name):
fingerprint_cmd = 'ssh-keygen -lf /dev/stdin <<< "{}"'.format(host_key)
try:
- fingerprint = subprocess.check_output(fingerprint_cmd, shell=True,
- stderr=subprocess.DEVNULL,
- universal_newlines=True)
- except subprocess.CalledProcessError as err:
+ fingerprint = cmd(fingerprint_cmd, stderr=DEVNULL, universal_newlines=True)
+ except OSError:
sys.exit("Can not get RSA host key fingerprint.")
print("RSA host key fingerprint is {}".format(fingerprint.split()[1]))
@@ -128,9 +125,8 @@ def get_remote_config(remote_file):
# Try header first, and look for 'OK' or 'Moved' codes:
curl_cmd = 'curl {0} -q -I {1}'.format(redirect_opt, remote_file)
try:
- curl_output = subprocess.check_output(curl_cmd, shell=True,
- universal_newlines=True)
- except subprocess.CalledProcessError:
+ curl_output = cmd(curl_cmd, shell=True, universal_newlines=True)
+ except OSError:
sys.exit(1)
return_vals = re.findall(r'^HTTP\/\d+\.?\d\s+(\d+)\s+(.*)$',
@@ -146,9 +142,6 @@ def get_remote_config(remote_file):
curl_cmd = 'curl {0} -# {1}'.format(redirect_opt, remote_file)
try:
- config_file = subprocess.check_output(curl_cmd, shell=True,
- universal_newlines=True)
- except subprocess.CalledProcessError:
- config_file = None
-
- return config_file
+ return cmd(curl_cmd, universal_newlines=True)
+ except OSError:
+ return None