summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2019-09-08 19:51:33 +0200
committerChristian Poessinger <christian@poessinger.com>2019-09-20 21:28:53 +0200
commiteb48a7fde5c37f1c905d1c85aca7d0518f65e652 (patch)
tree4ce3f06103724b25e0598ad49be14cb71a94fcf7 /python
parentf8d6ba647e0ef4f1c18302bfb4bebb040f2df95c (diff)
downloadvyos-1x-eb48a7fde5c37f1c905d1c85aca7d0518f65e652.tar.gz
vyos-1x-eb48a7fde5c37f1c905d1c85aca7d0518f65e652.zip
Python/ifconfig: T1557: import cleanup for subprocess
Diffstat (limited to 'python')
-rw-r--r--python/vyos/ifconfig.py62
1 files changed, 31 insertions, 31 deletions
diff --git a/python/vyos/ifconfig.py b/python/vyos/ifconfig.py
index 80b5592c2..9b37fdbff 100644
--- a/python/vyos/ifconfig.py
+++ b/python/vyos/ifconfig.py
@@ -15,12 +15,12 @@
import os
import re
-import subprocess
import jinja2
from vyos.validate import *
from ipaddress import IPv4Network, IPv6Address
from netifaces import ifaddresses, AF_INET, AF_INET6
+from subprocess import Popen, PIPE
from time import sleep
dhcp_cfg = """
@@ -84,6 +84,36 @@ class Interface:
if os.path.isfile('/tmp/vyos.ifconfig.debug'):
print('DEBUG/{:<6} {}'.format(self._ifname, msg))
+ def _cmd(self, command):
+ p = Popen(command, stdout=PIPE, shell=True)
+ tmp = p.communicate()[0].strip()
+ self._debug_msg("cmd '{}'".format(command))
+ if tmp.decode():
+ self._debug_msg("returned:\n{}".format(tmp.decode()))
+
+ # do we need some error checking code here?
+
+ def _read_sysfs(self, filename):
+ """
+ Provide a single primitive w/ error checking for reading from sysfs.
+ """
+ value = None
+ with open(filename, 'r') as f:
+ value = f.read().rstrip('\n')
+
+ self._debug_msg("read '{}' < '{}'".format(value, filename))
+ return value
+
+ def _write_sysfs(self, filename, value):
+ """
+ Provide a single primitive w/ error checking for writing to sysfs.
+ """
+ self._debug_msg("write '{}' > '{}'".format(value, filename))
+ with open(filename, 'w') as f:
+ f.write(str(value))
+
+ return None
+
def remove(self):
"""
Remove interface from operating system. Removing the interface
@@ -118,36 +148,6 @@ class Interface:
cmd = 'ip link del dev {}'.format(self._ifname)
self._cmd(cmd)
- def _cmd(self, command):
- self._debug_msg("cmd '{}'".format(command))
-
- process = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True)
- proc_stdout = process.communicate()[0].strip()
-
- # add exception handling code
- pass
-
- def _read_sysfs(self, filename):
- """
- Provide a single primitive w/ error checking for reading from sysfs.
- """
- value = None
- with open(filename, 'r') as f:
- value = f.read().rstrip('\n')
-
- self._debug_msg("read '{}' < '{}'".format(value, filename))
- return value
-
- def _write_sysfs(self, filename, value):
- """
- Provide a single primitive w/ error checking for writing to sysfs.
- """
- self._debug_msg("write '{}' > '{}'".format(value, filename))
- with open(filename, 'w') as f:
- f.write(str(value))
-
- return None
-
@property
def mtu(self):
"""