summaryrefslogtreecommitdiff
path: root/src/op_mode
diff options
context:
space:
mode:
Diffstat (limited to 'src/op_mode')
-rwxr-xr-xsrc/op_mode/connect_disconnect.py9
-rwxr-xr-xsrc/op_mode/dns_forwarding_reset.py6
-rwxr-xr-xsrc/op_mode/dynamic_dns.py6
-rwxr-xr-xsrc/op_mode/restart_dhcp_relay.py6
-rwxr-xr-xsrc/op_mode/show_acceleration.py10
-rwxr-xr-xsrc/op_mode/show_dhcp.py7
-rwxr-xr-xsrc/op_mode/show_dhcpv6.py6
-rwxr-xr-xsrc/op_mode/snmp.py3
8 files changed, 34 insertions, 19 deletions
diff --git a/src/op_mode/connect_disconnect.py b/src/op_mode/connect_disconnect.py
index a22615096..192fd80ec 100755
--- a/src/op_mode/connect_disconnect.py
+++ b/src/op_mode/connect_disconnect.py
@@ -21,6 +21,9 @@ from sys import exit
from psutil import process_iter
from time import strftime, localtime, time
+from vyos.util import run
+
+
PPP_LOGFILE = '/var/log/vyatta/ppp_{}.log'
def check_interface(interface):
@@ -56,8 +59,7 @@ def connect(interface):
tm = strftime("%a %d %b %Y %I:%M:%S %p %Z", localtime(time()))
with open(PPP_LOGFILE.format(interface), 'a') as f:
f.write('{}: user {} started PPP daemon for {} by connect command\n'.format(tm, user, interface))
- cmd = 'umask 0; setsid sh -c "nohup /usr/sbin/pppd call {0} > /tmp/{0}.log 2>&1 &"'.format(interface)
- os.system(cmd)
+ run('umask 0; setsid sh -c "nohup /usr/sbin/pppd call {0} > /tmp/{0}.log 2>&1 &"'.format(interface))
def disconnect(interface):
@@ -75,8 +77,7 @@ def disconnect(interface):
tm = strftime("%a %d %b %Y %I:%M:%S %p %Z", localtime(time()))
with open(PPP_LOGFILE.format(interface), 'a') as f:
f.write('{}: user {} stopped PPP daemon for {} by disconnect command\n'.format(tm, user, interface))
- cmd = '/usr/bin/poff "{}"'.format(interface)
- os.system(cmd)
+ run('/usr/bin/poff "{}"'.format(interface))
def main():
parser = argparse.ArgumentParser()
diff --git a/src/op_mode/dns_forwarding_reset.py b/src/op_mode/dns_forwarding_reset.py
index da4fba3a2..93c2444b9 100755
--- a/src/op_mode/dns_forwarding_reset.py
+++ b/src/op_mode/dns_forwarding_reset.py
@@ -25,6 +25,8 @@ import sys
import argparse
import vyos.config
+from vyos.util import run
+
parser = argparse.ArgumentParser()
parser.add_argument("-a", "--all", action="store_true", help="Reset all cache")
@@ -40,10 +42,10 @@ if __name__ == '__main__':
sys.exit(0)
if args.all:
- os.system("rec_control wipe-cache \'.$\'")
+ run("rec_control wipe-cache \'.$\'")
sys.exit(1)
elif args.domain:
- os.system("rec_control wipe-cache \'{0}$\'".format(args.domain))
+ run("rec_control wipe-cache \'{0}$\'".format(args.domain))
else:
parser.print_help()
sys.exit(1)
diff --git a/src/op_mode/dynamic_dns.py b/src/op_mode/dynamic_dns.py
index 0d457e247..d991848ad 100755
--- a/src/op_mode/dynamic_dns.py
+++ b/src/op_mode/dynamic_dns.py
@@ -21,6 +21,8 @@ import sys
import time
from vyos.config import Config
+from vyos.util import run
+
cache_file = r'/var/cache/ddclient/ddclient.cache'
@@ -84,9 +86,9 @@ def show_status():
def update_ddns():
- os.system('systemctl stop ddclient')
+ run('systemctl stop ddclient')
os.remove(cache_file)
- os.system('systemctl start ddclient')
+ run('systemctl start ddclient')
def main():
diff --git a/src/op_mode/restart_dhcp_relay.py b/src/op_mode/restart_dhcp_relay.py
index ab02d1eb3..057b4dcd8 100755
--- a/src/op_mode/restart_dhcp_relay.py
+++ b/src/op_mode/restart_dhcp_relay.py
@@ -23,6 +23,8 @@ import argparse
import os
import vyos.config
+from vyos.util import run
+
parser = argparse.ArgumentParser()
parser.add_argument("--ipv4", action="store_true", help="Restart IPv4 DHCP relay")
@@ -37,7 +39,7 @@ if __name__ == '__main__':
if not c.exists_effective('service dhcp-relay'):
print("DHCP relay service not configured")
else:
- os.system('sudo systemctl restart isc-dhcp-relay.service')
+ run('sudo systemctl restart isc-dhcp-relay.service')
sys.exit(0)
elif args.ipv6:
@@ -45,7 +47,7 @@ if __name__ == '__main__':
if not c.exists_effective('service dhcpv6-relay'):
print("DHCPv6 relay service not configured")
else:
- os.system('sudo systemctl restart isc-dhcpv6-relay.service')
+ run('sudo systemctl restart isc-dhcpv6-relay.service')
sys.exit(0)
else:
diff --git a/src/op_mode/show_acceleration.py b/src/op_mode/show_acceleration.py
index 3ba0e85dd..cdd8ce037 100755
--- a/src/op_mode/show_acceleration.py
+++ b/src/op_mode/show_acceleration.py
@@ -21,6 +21,8 @@ import re
import argparse
import subprocess
from vyos.config import Config
+from vyos.util import popen, run
+
def detect_qat_dev():
ret = subprocess.Popen(['sudo', 'lspci', '-nn'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
@@ -97,20 +99,20 @@ args = parser.parse_args()
if args.hw:
detect_qat_dev()
# Show availible Intel QAT devices
- os.system('sudo lspci -nn | egrep -e \'8086:37c8|8086:19e2|8086:0435|8086:6f54\'')
+ run('sudo lspci -nn | egrep -e \'8086:37c8|8086:19e2|8086:0435|8086:6f54\'')
elif args.flow and args.dev:
check_qat_if_conf()
- os.system('sudo cat '+get_qat_proc_path(args.dev)+"fw_counters")
+ run('sudo cat '+get_qat_proc_path(args.dev)+"fw_counters")
elif args.interrupts:
check_qat_if_conf()
# Delete _dev from args.dev
- os.system('sudo cat /proc/interrupts | grep qat')
+ run('sudo cat /proc/interrupts | grep qat')
elif args.status:
check_qat_if_conf()
show_qat_status()
elif args.conf and args.dev:
check_qat_if_conf()
- os.system('sudo cat '+get_qat_proc_path(args.dev)+"dev_cfg")
+ run('sudo cat '+get_qat_proc_path(args.dev)+"dev_cfg")
elif args.dev_list:
get_qat_devices()
else:
diff --git a/src/op_mode/show_dhcp.py b/src/op_mode/show_dhcp.py
index f801ba753..4e3e08263 100755
--- a/src/op_mode/show_dhcp.py
+++ b/src/op_mode/show_dhcp.py
@@ -24,9 +24,12 @@ import collections
import os
from datetime import datetime
-from vyos.config import Config
from isc_dhcp_leases import Lease, IscDhcpLeases
+from vyos.config import Config
+from vyos.util import run
+
+
lease_file = "/config/dhcpd.leases"
pool_key = "shared-networkname"
@@ -190,7 +193,7 @@ if __name__ == '__main__':
sys.exit(0)
# if dhcp server is down, inactive leases may still be shown as active, so warn the user.
- if os.system('systemctl -q is-active isc-dhcpv4-server.service') != 0:
+ if run('systemctl -q is-active isc-dhcpv4-server.service') != 0:
print("WARNING: DHCP server is configured but not started. Data may be stale.")
if args.leases:
diff --git a/src/op_mode/show_dhcpv6.py b/src/op_mode/show_dhcpv6.py
index ae63af39b..4ef4849ff 100755
--- a/src/op_mode/show_dhcpv6.py
+++ b/src/op_mode/show_dhcpv6.py
@@ -24,9 +24,11 @@ import collections
import os
from datetime import datetime
-from vyos.config import Config
from isc_dhcp_leases import Lease, IscDhcpLeases
+from vyos.config import Config
+from vyos.util import run
+
lease_file = "/config/dhcpdv6.leases"
pool_key = "shared-networkname"
@@ -177,7 +179,7 @@ if __name__ == '__main__':
sys.exit(0)
# if dhcp server is down, inactive leases may still be shown as active, so warn the user.
- if os.system('systemctl -q is-active isc-dhcpv6-server.service') != 0:
+ if run('systemctl -q is-active isc-dhcpv6-server.service') != 0:
print("WARNING: DHCPv6 server is configured but not started. Data may be stale.")
if args.leases:
diff --git a/src/op_mode/snmp.py b/src/op_mode/snmp.py
index e08441f0e..b09eab97f 100755
--- a/src/op_mode/snmp.py
+++ b/src/op_mode/snmp.py
@@ -24,6 +24,7 @@ import sys
import argparse
from vyos.config import Config
+from vyos.util import run
config_file_daemon = r'/etc/snmp/snmpd.conf'
@@ -53,7 +54,7 @@ def show_all():
def show_community(c, h):
print('Status of SNMP community {0} on {1}'.format(c, h), flush=True)
- os.system('/usr/bin/snmpstatus -t1 -v1 -c {0} {1}'.format(c, h))
+ run('/usr/bin/snmpstatus -t1 -v1 -c {0} {1}'.format(c, h))
if __name__ == '__main__':
args = parser.parse_args()