diff options
author | hagbard <vyosdev@derith.de> | 2019-08-21 16:53:16 +0000 |
---|---|---|
committer | hagbard <vyosdev@derith.de> | 2019-08-21 16:53:16 +0000 |
commit | 0b9c894fcece6df553a89e42147768ce6efaf372 (patch) | |
tree | 36feec9954e1c196e1364da7e0af583a4555ee00 /python | |
parent | 63855b5c6b674d102804b43bcda85499a43973a4 (diff) | |
download | vyos-1x-0b9c894fcece6df553a89e42147768ce6efaf372.tar.gz vyos-1x-0b9c894fcece6df553a89e42147768ce6efaf372.zip |
[interfaceconfig class] - moved get functionaility for mtu, mac and ifalias into its property
Diffstat (limited to 'python')
-rw-r--r-- | python/vyos/interfaceconfig.py | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/python/vyos/interfaceconfig.py b/python/vyos/interfaceconfig.py index b8bfb707e..54517328a 100644 --- a/python/vyos/interfaceconfig.py +++ b/python/vyos/interfaceconfig.py @@ -46,7 +46,14 @@ class Interface: @property def mtu(self): - return self._mtu + try: + ret = subprocess.check_output(['ip -j link list dev ' + self._ifname], shell=True).decode() + a = json.loads(ret)[0] + return a['mtu'] + except subprocess.CalledProcessError as e: + if self._debug(): + self._debug(e) + return None @mtu.setter def mtu(self, mtu=None): @@ -62,7 +69,14 @@ class Interface: @property def macaddr(self): - return self._macaddr + try: + ret = subprocess.check_output(['ip -j -4 link show dev ' + self._ifname], stderr=subprocess.STDOUT, shell=True).decode() + j = json.loads(ret) + return j[0]['address'] + except subprocess.CalledProcessError as e: + if self._debug(): + self._debug(e) + return None @macaddr.setter def macaddr(self, mac=None): @@ -77,7 +91,7 @@ class Interface: @property def ifalias(self): - return self._ifalias + return open('/sys/class/net/{0}/ifalias'.format(self._ifname),'r').read() @ifalias.setter def ifalias(self, ifalias=None): @@ -116,6 +130,7 @@ class Interface: return False def get_mtu(self): + print ("function get_mtu() is depricated and will be removed soon") try: ret = subprocess.check_output(['ip -j link list dev ' + self._ifname], shell=True).decode() a = json.loads(ret)[0] @@ -125,7 +140,9 @@ class Interface: self._debug(e) return None + def get_macaddr(self): + print ("function get_macaddr() is depricated and will be removed soon") try: ret = subprocess.check_output(['ip -j -4 link show dev ' + self._ifname], stderr=subprocess.STDOUT, shell=True).decode() j = json.loads(ret) @@ -136,6 +153,7 @@ class Interface: return None def get_alias(self): + print ("function get_alias() is depricated and will be removed soon") return open('/sys/class/net/{0}/ifalias'.format(self._ifname),'r').read() def del_alias(self): |