diff options
author | hagbard <vyosdev@derith.de> | 2019-08-22 02:07:26 +0000 |
---|---|---|
committer | hagbard <vyosdev@derith.de> | 2019-08-22 02:07:26 +0000 |
commit | cee38e3ed090fcb98ffd49a7c8234060ea9b731f (patch) | |
tree | 5bb00572e6915cbb16c3f99f81f81718b44852e4 /python/vyos/interfaceconfig.py | |
parent | b1c2275a492e3d86e7c230610e94bef299a67afd (diff) | |
download | vyos-1x-cee38e3ed090fcb98ffd49a7c8234060ea9b731f.tar.gz vyos-1x-cee38e3ed090fcb98ffd49a7c8234060ea9b731f.zip |
[interfaceconfig] - linkstate as property and depriccated message for get_link_state()
Diffstat (limited to 'python/vyos/interfaceconfig.py')
-rw-r--r-- | python/vyos/interfaceconfig.py | 15 |
1 files changed, 11 insertions, 4 deletions
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) |