From cee38e3ed090fcb98ffd49a7c8234060ea9b731f Mon Sep 17 00:00:00 2001 From: hagbard Date: Thu, 22 Aug 2019 02:07:26 +0000 Subject: [interfaceconfig] - linkstate as property and depriccated message for get_link_state() --- python/vyos/interfaceconfig.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'python') diff --git a/python/vyos/interfaceconfig.py b/python/vyos/interfaceconfig.py index 54517328a..83e7c03c0 100644 --- a/python/vyos/interfaceconfig.py +++ b/python/vyos/interfaceconfig.py @@ -89,6 +89,7 @@ class Interface: if self._debug(): self._debug(e) + @property def ifalias(self): return open('/sys/class/net/{0}/ifalias'.format(self._ifname),'r').read() @@ -101,9 +102,17 @@ class Interface: self._ifalias = str(ifalias) open('/sys/class/net/{0}/ifalias'.format(self._ifname),'w').write(self._ifalias) + @property def linkstate(self): - return self._linkstate + try: + ret = subprocess.check_output(['ip -j link show ' + self._ifname], shell=True).decode() + s = json.loads(ret) + return s[0]['operstate'].lower() + except subprocess.CalledProcessError as e: + if self._debug(): + self._debug(e) + return None @linkstate.setter def linkstate(self, state='up'): @@ -160,9 +169,7 @@ class Interface: open('/sys/class/net/{0}/ifalias'.format(self._ifname),'w').write() def get_link_state(self): - """ - returns either up/down or None if it can't find the state - """ + print ("function get_link_state() is depricated and will be removed soon") try: ret = subprocess.check_output(['ip -j link show ' + self._ifname], shell=True).decode() s = json.loads(ret) -- cgit v1.2.3