diff options
author | Christian Poessinger <christian@poessinger.com> | 2019-08-30 10:47:10 +0200 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2019-08-30 10:47:10 +0200 |
commit | c50327efe341bfc5444a8b888e4cd58bb251fc01 (patch) | |
tree | f60ae8f19201c062a3009a2d4ce17206f8d9bbf6 | |
parent | 4057159c949f8caa5078e984b8d521850a1b73be (diff) | |
download | vyos-1x-c50327efe341bfc5444a8b888e4cd58bb251fc01.tar.gz vyos-1x-c50327efe341bfc5444a8b888e4cd58bb251fc01.zip |
Python/ifconfig: ease __init__ if/else statements
-rw-r--r-- | python/vyos/interfaceconfig.py | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/python/vyos/interfaceconfig.py b/python/vyos/interfaceconfig.py index e354d900d..1dd6487d7 100644 --- a/python/vyos/interfaceconfig.py +++ b/python/vyos/interfaceconfig.py @@ -25,25 +25,24 @@ import ipaddress dhclient_conf_dir = r'/var/lib/dhcp/dhclient_' - class Interface: - def __init__(self, ifname=None, type=None): if not ifname: raise Exception("interface name required") + if not os.path.exists('/sys/class/net/{0}'.format(ifname)) and not type: raise Exception("interface {0} not found".format(str(ifname))) - else: - if not os.path.exists('/sys/class/net/{0}'.format(ifname)): - try: - ret = subprocess.check_output( - ['ip link add dev ' + str(ifname) + ' type ' + type], stderr=subprocess.STDOUT, shell=True).decode() - except subprocess.CalledProcessError as e: - if self._debug(): - self._debug(e) - if "Operation not supported" in str(e.output.decode()): - print(str(e.output.decode())) - sys.exit(0) + + if not os.path.exists('/sys/class/net/{0}'.format(ifname)): + try: + ret = subprocess.check_output( + ['ip link add dev ' + str(ifname) + ' type ' + type], stderr=subprocess.STDOUT, shell=True).decode() + except subprocess.CalledProcessError as e: + if self._debug(): + self._debug(e) + if "Operation not supported" in str(e.output.decode()): + print(str(e.output.decode())) + sys.exit(0) self._ifname = str(ifname) |