summaryrefslogtreecommitdiff
path: root/src/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'src/helpers')
-rwxr-xr-xsrc/helpers/run-config-migration.py10
-rwxr-xr-xsrc/helpers/validate-value.py4
-rwxr-xr-xsrc/helpers/vyos-boot-config-loader.py9
-rwxr-xr-xsrc/helpers/vyos-bridge-sync.py14
-rwxr-xr-xsrc/helpers/vyos-load-config.py14
-rwxr-xr-xsrc/helpers/vyos-merge-config.py10
6 files changed, 22 insertions, 39 deletions
diff --git a/src/helpers/run-config-migration.py b/src/helpers/run-config-migration.py
index 3c06e38f8..cc7166c22 100755
--- a/src/helpers/run-config-migration.py
+++ b/src/helpers/run-config-migration.py
@@ -19,7 +19,8 @@ import os
import sys
import argparse
import datetime
-import subprocess
+
+from vyos.util import cmd
from vyos.migrator import Migrator, VirtualMigrator
def main():
@@ -61,12 +62,7 @@ def main():
'{0:%Y-%m-%d-%H%M%S}'.format(datetime.datetime.now()),
'pre-migration'])
- try:
- subprocess.check_call(['cp', '-p', config_file_name,
- backup_file_name])
- except subprocess.CalledProcessError as err:
- print("Called process error: {}.".format(err))
- sys.exit(1)
+ cmd(f'cp -p {config_file_name} {backup_file_name}')
if not virtual:
virtual_migration = VirtualMigrator(config_file_name)
diff --git a/src/helpers/validate-value.py b/src/helpers/validate-value.py
index 36f996d38..fab6ca81e 100755
--- a/src/helpers/validate-value.py
+++ b/src/helpers/validate-value.py
@@ -5,6 +5,8 @@ import os
import sys
import argparse
+from vyos.util import run
+
parser = argparse.ArgumentParser()
parser.add_argument('--regex', action='append')
parser.add_argument('--exec', action='append')
@@ -31,7 +33,7 @@ try:
cmd = "{0} {1}".format(cmd, args.value)
if debug:
print(cmd)
- res = os.system(cmd)
+ res = run(cmd)
if res == 0:
sys.exit(0)
except Exception as exn:
diff --git a/src/helpers/vyos-boot-config-loader.py b/src/helpers/vyos-boot-config-loader.py
index 58483fe50..c5bf22f10 100755
--- a/src/helpers/vyos-boot-config-loader.py
+++ b/src/helpers/vyos-boot-config-loader.py
@@ -20,13 +20,13 @@ import os
import sys
import pwd
import grp
-import subprocess
import traceback
from datetime import datetime
from vyos.defaults import directories
from vyos.configsession import ConfigSession, ConfigSessionError
from vyos.configtree import ConfigTree
+from vyos.util import cmd
STATUS_FILE = '/tmp/vyos-config-status'
TRACE_FILE = '/tmp/boot-config-trace'
@@ -102,12 +102,7 @@ def failsafe(config_file_name):
'authentication',
'encrypted-password'])
- cmd = ("useradd -s /bin/bash -G 'users,sudo' -m -N -p '{0}' "
- "vyos".format(passwd))
- try:
- subprocess.check_call(cmd, shell=True)
- except subprocess.CalledProcessError as e:
- sys.exit("{0}".format(e))
+ cmd(f"useradd -s /bin/bash -G 'users,sudo' -m -N -p '{passwd}' vyos")
if __name__ == '__main__':
if len(sys.argv) < 2:
diff --git a/src/helpers/vyos-bridge-sync.py b/src/helpers/vyos-bridge-sync.py
index 495eb5d40..097d28d85 100755
--- a/src/helpers/vyos-bridge-sync.py
+++ b/src/helpers/vyos-bridge-sync.py
@@ -21,16 +21,12 @@
# to the bridge automatically once it's available
import argparse
-import subprocess
-
from sys import exit
from time import sleep
+
from vyos.config import Config
+from vyos.util import cmd, run
-def subprocess_cmd(command):
- process = subprocess.Popen(command,stdout=subprocess.PIPE, shell=True)
- proc_stdout = process.communicate()[0].strip()
- pass
if __name__ == '__main__':
parser = argparse.ArgumentParser()
@@ -45,9 +41,11 @@ if __name__ == '__main__':
for bridge in conf.list_nodes('interfaces bridge'):
for member_if in conf.list_nodes('interfaces bridge {} member interface'.format(bridge)):
if args.interface == member_if:
- cmd = 'brctl addif "{}" "{}"'.format(bridge, args.interface)
+ command = 'brctl addif "{}" "{}"'.format(bridge, args.interface)
# let interfaces etc. settle - especially required for OpenVPN bridged interfaces
sleep(4)
- subprocess_cmd(cmd)
+ # XXX: This is ignoring any issue, should be cmd but kept as it
+ # XXX: during the migration to not cause any regression
+ run(command)
exit(0)
diff --git a/src/helpers/vyos-load-config.py b/src/helpers/vyos-load-config.py
index 693529c23..a9fa15778 100755
--- a/src/helpers/vyos-load-config.py
+++ b/src/helpers/vyos-load-config.py
@@ -30,25 +30,19 @@ import vyos.remote
from vyos.config import Config, VyOSError
from vyos.migrator import Migrator, VirtualMigrator, MigratorError
-system_config_file = 'config.boot'
-
class LoadConfig(Config):
"""A subclass for calling 'loadFile'.
This does not belong in config.py, and only has a single caller.
"""
- def load_config(self, file_path):
- cmd = [self._cli_shell_api, 'loadFile', file_path]
- self._run(cmd)
+ def load_config(self, path):
+ return self._run(['/bin/cli-shell-api','loadFile',path])
-if len(sys.argv) > 1:
- file_name = sys.argv[1]
-else:
- file_name = system_config_file
+file_name = sys.argv[1] if len(sys.argv) > 1 else 'config.boot'
configdir = vyos.defaults.directories['config']
-
protocols = ['scp', 'sftp', 'http', 'https', 'ftp', 'tftp']
+
if any(x in file_name for x in protocols):
config_file = vyos.remote.get_remote_config(file_name)
if not config_file:
diff --git a/src/helpers/vyos-merge-config.py b/src/helpers/vyos-merge-config.py
index 10a5ea4bc..6546c03e3 100755
--- a/src/helpers/vyos-merge-config.py
+++ b/src/helpers/vyos-merge-config.py
@@ -17,13 +17,13 @@
import sys
import os
-import subprocess
import tempfile
import vyos.defaults
import vyos.remote
from vyos.config import Config
from vyos.configtree import ConfigTree
from vyos.migrator import Migrator, VirtualMigrator
+from vyos.util import cmd
if (len(sys.argv) < 2):
@@ -100,12 +100,10 @@ if path:
add_cmds = [ cmd for cmd in add_cmds if path in cmd ]
for cmd in add_cmds:
- cmd = "/opt/vyatta/sbin/my_" + cmd
-
try:
- subprocess.check_call(cmd, shell=True)
- except subprocess.CalledProcessError as err:
- print("Called process error: {}.".format(err))
+ cmd(f'/opt/vyatta/sbin/my_{cmd}', message='Called process error')
+ except OSError as err:
+ print(err)
if effective_config.session_changed():
print("Merge complete. Use 'commit' to make changes effective.")