summaryrefslogtreecommitdiff
path: root/src/conf_mode/host_name.py
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-04-07 08:27:36 +0200
committerGitHub <noreply@github.com>2020-04-07 08:27:36 +0200
commit09ad28b28c9ebd9308cfe9048686b3b0ef9cfd9c (patch)
tree6e7b0971ecd8859cff864b3ebb37f86f8ba288f5 /src/conf_mode/host_name.py
parente0f13b79a669e7fc8cadac8757b2f5fbbf51dc99 (diff)
parent7256810914e6664bf92041dcd7c3daf649ce0001 (diff)
downloadvyos-1x-09ad28b28c9ebd9308cfe9048686b3b0ef9cfd9c.tar.gz
vyos-1x-09ad28b28c9ebd9308cfe9048686b3b0ef9cfd9c.zip
Merge pull request #307 from thomas-mangin/T2226
util: T2226: convert all call to use vyos.util.{popen, cmd, run}
Diffstat (limited to 'src/conf_mode/host_name.py')
-rwxr-xr-xsrc/conf_mode/host_name.py19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/conf_mode/host_name.py b/src/conf_mode/host_name.py
index 47cf232e9..690d1e030 100755
--- a/src/conf_mode/host_name.py
+++ b/src/conf_mode/host_name.py
@@ -25,7 +25,6 @@ import re
import sys
import copy
import glob
-import subprocess
import argparse
import jinja2
@@ -34,6 +33,7 @@ import vyos.hostsd_client
from vyos.config import Config
from vyos import ConfigError
+from vyos.util import cmd, run
default_config_data = {
@@ -156,21 +156,22 @@ def apply(config):
# rsyslog runs into a race condition at boot time with systemd
# restart rsyslog only if the hostname changed.
- hostname_old = subprocess.check_output(['hostnamectl', '--static']).decode().strip()
-
- os.system("hostnamectl set-hostname --static {0}".format(hostname_new))
+ hostname_old = cmd('hostnamectl --static')
+ cmd(f'hostnamectl set-hostname --static {hostname_new}')
# Restart services that use the hostname
if hostname_new != hostname_old:
- os.system("systemctl restart rsyslog.service")
+ run("systemctl restart rsyslog.service")
# If SNMP is running, restart it too
- if os.system("pgrep snmpd > /dev/null") == 0:
- os.system("systemctl restart snmpd.service")
+ ret = run("pgrep snmpd > /dev/null")
+ if ret == 0:
+ run("systemctl restart snmpd.service")
# restart pdns if it is used
- if os.system("/usr/bin/rec_control ping >/dev/null 2>&1") == 0:
- os.system("/etc/init.d/pdns-recursor restart >/dev/null")
+ ret = run('/usr/bin/rec_control ping >/dev/null 2>&1')
+ if ret == 0:
+ run('/etc/init.d/pdns-recursor restart >/dev/null')
return None