summaryrefslogtreecommitdiff
path: root/python/vyos/interfaceconfig.py
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2019-08-30 11:41:48 +0200
committerChristian Poessinger <christian@poessinger.com>2019-08-30 11:41:48 +0200
commit3238a9cc621975c9417885b3f8552585dce594be (patch)
treead5c80ce02a3e2bcdff314a36db5b0e3886c8e99 /python/vyos/interfaceconfig.py
parentdff5f3f38f60b9da8e791593998e6f614da6e5ec (diff)
downloadvyos-1x-3238a9cc621975c9417885b3f8552585dce594be.tar.gz
vyos-1x-3238a9cc621975c9417885b3f8552585dce594be.zip
Python/ifconfig: rework interface alias assignment
Diffstat (limited to 'python/vyos/interfaceconfig.py')
-rw-r--r--python/vyos/interfaceconfig.py39
1 files changed, 33 insertions, 6 deletions
diff --git a/python/vyos/interfaceconfig.py b/python/vyos/interfaceconfig.py
index c83b0d55c..c10f76e52 100644
--- a/python/vyos/interfaceconfig.py
+++ b/python/vyos/interfaceconfig.py
@@ -138,16 +138,43 @@ class Interface:
@property
def ifalias(self):
- return open('/sys/class/net/{0}/ifalias'.format(self._ifname), 'r').read()
+ """
+ Get/set interface alias name
+
+ Example:
+
+ from vyos.interfaceconfig import Interface
+ alias = Interface('ens192').ifalias
+ """
+
+ alias = ''
+ with open('/sys/class/net/{0}/ifalias'.format(self._ifname), 'r') as f:
+ alias = f.read().rstrip('\n')
+ return alias
+
@ifalias.setter
def ifalias(self, ifalias=None):
+ """
+ Get/set interface alias name
+
+ Example:
+
+ from vyos.interfaceconfig import Interface
+ Interface('ens192').ifalias = 'VyOS upstream interface'
+
+ to clear interface alias e.g. delete it use:
+
+ Interface('ens192').ifalias = ''
+ """
+
+ # clear interface alias
if not ifalias:
- self._ifalias = self._ifname
- else:
- self._ifalias = str(ifalias)
- open('/sys/class/net/{0}/ifalias'.format(
- self._ifname), 'w').write(self._ifalias)
+ ifalias = '\0'
+
+ with open('/sys/class/net/{0}/ifalias'.format(self._ifname), 'w') as f:
+ f.write(str(ifalias))
+
@property
def linkstate(self):