diff options
author | Thomas Mangin <thomas.mangin@exa.net.uk> | 2020-04-04 12:55:08 +0100 |
---|---|---|
committer | Thomas Mangin <thomas.mangin@exa.net.uk> | 2020-04-04 12:55:08 +0100 |
commit | dcbd5f430907747f8c29111fbe9f5737865a7ae8 (patch) | |
tree | 81d62dbbe7954973b94db08f180967db984b6942 /python/vyos/util.py | |
parent | f91a8869cb1ab3acc605a93789e9310f33dbd979 (diff) | |
download | vyos-1x-dcbd5f430907747f8c29111fbe9f5737865a7ae8.tar.gz vyos-1x-dcbd5f430907747f8c29111fbe9f5737865a7ae8.zip |
ifconfig: T2205: silence ethtool harmless failures
Not all interface are capable of all features. Since commands are
now checked for valid completion, ethtool command failure must
be ignored.
Diffstat (limited to 'python/vyos/util.py')
-rw-r--r-- | python/vyos/util.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/python/vyos/util.py b/python/vyos/util.py index 3970b8bf1..87c2dcedc 100644 --- a/python/vyos/util.py +++ b/python/vyos/util.py @@ -16,6 +16,44 @@ import os import re import sys +from subprocess import Popen, PIPE, STDOUT + + +# debugging + + +def debug(flag): + return flag if os.path.isfile(f'/tmp/vyos.{flag}.debug') else '' + + +def debug_msg(message, section=''): + if section: + print(f'DEBUG/{section:<6} {message}') + + +# commands + + +def popen(command, section=''): + p = Popen(command, stdout=PIPE, stderr=STDOUT, shell=True) + tmp = p.communicate()[0].strip() + debug_msg(f"cmd '{command}'", section) + decoded = tmp.decode() + if decoded: + debug_msg(f"returned:\n{decoded}", section) + return decoded, p.returncode + + +def cmd(command, section=''): + decoded, code = popen(command, section) + if code != 0: + # error code can be recovered with .errno + raise OSError(code, f'{command}\nreturned: {decoded}') + return decoded + + +# file manipulation + def read_file(path): """ Read a file to string """ |