diff options
author | Christian Poessinger <christian@poessinger.com> | 2020-03-03 17:37:35 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-03 17:37:35 +0100 |
commit | 3dc1921ea1c5bde86d948df22a7566f71357dd0a (patch) | |
tree | d13ee4853cec7f777838185fab6e622bb3492c30 /python/vyos | |
parent | 98a4a7d66a7dbfee113885a5f804e7d3f344685d (diff) | |
parent | c7e4d1d2e9207d41096e34f9ea345d9e2d9a9d8f (diff) | |
download | vyos-1x-3dc1921ea1c5bde86d948df22a7566f71357dd0a.tar.gz vyos-1x-3dc1921ea1c5bde86d948df22a7566f71357dd0a.zip |
Merge pull request #236 from DmitriyEshenko/docker-intfc
ifconfig: T2074: add check for sysfs files
Diffstat (limited to 'python/vyos')
-rw-r--r-- | python/vyos/ifconfig.py | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/python/vyos/ifconfig.py b/python/vyos/ifconfig.py index b1f9baabe..d5b511f82 100644 --- a/python/vyos/ifconfig.py +++ b/python/vyos/ifconfig.py @@ -407,11 +407,12 @@ class Interface: >>> from vyos.ifconfig import Interface >>> Interface('eth0').set_link_detect(1) """ - if int(link_filter) >= 0 and int(link_filter) <= 2: - return self._write_sysfs('/proc/sys/net/ipv4/conf/{0}/link_filter' - .format(self.config['ifname']), link_filter) - else: - raise ValueError("Value out of range") + sysfs_file = '/proc/sys/net/ipv4/conf/{0}/link_filter'.format(self.config['ifname']) + if os.path.exists(sysfs_file): + if int(link_filter) >= 0 and int(link_filter) <= 2: + return self._write_sysfs(sysfs_file, link_filter) + else: + raise ValueError("Value out of range") def set_alias(self, ifalias=None): """ @@ -1218,8 +1219,12 @@ class EthernetIf(VLANIf): >>> i.get_driver_name() 'vmxnet3' """ - link = os.readlink('/sys/class/net/{}/device/driver/module'.format(self.config['ifname'])) - return os.path.basename(link) + sysfs_file = '/sys/class/net/{}/device/driver/module'.format(self.config['ifname']) + if os.path.exists(sysfs_file): + link = os.readlink(sysfs_file) + return os.path.basename(link) + else: + return None def set_flow_control(self, enable): """ |