summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas Mangin <thomas.mangin@exa.net.uk>2020-04-05 18:18:50 +0100
committerThomas Mangin <thomas.mangin@exa.net.uk>2020-04-06 20:22:35 +0100
commite9b0b0704e49b4ec048ba3caae9a4f0d949ebc55 (patch)
treec3619b6662f7999eb4f9ad073f10be49baa41309 /src
parentad723975a71f75081b4a38c9eb083dd941fe1bc9 (diff)
downloadvyos-1x-e9b0b0704e49b4ec048ba3caae9a4f0d949ebc55.tar.gz
vyos-1x-e9b0b0704e49b4ec048ba3caae9a4f0d949ebc55.zip
util: T2226: rewrite ifmib to use popen
Diffstat (limited to 'src')
-rwxr-xr-xsrc/op_mode/snmp_ifmib.py33
1 files changed, 10 insertions, 23 deletions
diff --git a/src/op_mode/snmp_ifmib.py b/src/op_mode/snmp_ifmib.py
index 3a0e0d4b2..2479936bd 100755
--- a/src/op_mode/snmp_ifmib.py
+++ b/src/op_mode/snmp_ifmib.py
@@ -22,36 +22,24 @@
import sys
import argparse
import netifaces
-import subprocess
from vyos.config import Config
+from vyos.util import popen
parser = argparse.ArgumentParser(description='Retrieve SNMP interfaces information')
parser.add_argument('--ifindex', action='store', nargs='?', const='all', help='Show interface index')
parser.add_argument('--ifalias', action='store', nargs='?', const='all', help='Show interface aliase')
parser.add_argument('--ifdescr', action='store', nargs='?', const='all', help='Show interface description')
-def show_ifindex(i):
- proc = subprocess.Popen(['/bin/ip', 'link', 'show', i], stdout=subprocess.PIPE)
- (out, err) = proc.communicate()
- # convert output to string
- string = out.decode("utf-8")
-
- index = 'ifIndex = ' + string.split(':')[0]
+def show_ifindex(intf):
+ out, err = popen(f'/bin/ip link show {intf}', decode='utf-8')
+ index = 'ifIndex = ' + out.split(':')[0]
return index.replace('\n', '')
-def show_ifalias(i):
- proc = subprocess.Popen(['/bin/ip', 'link', 'show', i], stdout=subprocess.PIPE)
- (out, err) = proc.communicate()
- # convert output to string
- string = out.decode("utf-8")
-
- if 'alias' in string:
- alias = 'ifAlias = ' + string.split('alias')[1].lstrip()
- else:
- alias = 'ifAlias = ' + i
-
- return alias.replace('\n', '')
+def show_ifalias(intf):
+ out, err = popen(f'/bin/ip link show {intf}', decode='utf-8')
+ alias = out.split('alias')[1].lstrip() if 'alias' in out else intf
+ return 'ifAlias = ' + alias.replace('\n', '')
def show_ifdescr(i):
ven_id = ''
@@ -74,14 +62,13 @@ def show_ifdescr(i):
return ret
device = str(ven_id) + ':' + str(dev_id)
- proc = subprocess.Popen(['/usr/bin/lspci', '-mm', '-d', device], stdout=subprocess.PIPE)
- (out, err) = proc.communicate()
+ out, err = popen(f'/usr/bin/lspci -mm -d {device}', decode='utf-8')
vendor = ""
device = ""
# convert output to string
- string = out.decode("utf-8").split('"')
+ string = out.split('"')
if len(string) > 3:
vendor = string[3]