summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2019-08-30 12:00:44 +0200
committerChristian Poessinger <christian@poessinger.com>2019-08-30 12:00:44 +0200
commitcb1b72c5ccce1bd2d0f0b02eb4abeee0b5635d55 (patch)
tree503adcf5dd5c1f3afc79b84f0cedc8c5cd6371b7 /python
parentbb5ff5e0b968612890791de48e43479b0352c532 (diff)
downloadvyos-1x-cb1b72c5ccce1bd2d0f0b02eb4abeee0b5635d55.tar.gz
vyos-1x-cb1b72c5ccce1bd2d0f0b02eb4abeee0b5635d55.zip
Python/ifconfig: replace linkstate() with up()/down() methods
Diffstat (limited to 'python')
-rw-r--r--python/vyos/interfaceconfig.py55
1 files changed, 32 insertions, 23 deletions
diff --git a/python/vyos/interfaceconfig.py b/python/vyos/interfaceconfig.py
index c40912e3c..f9e231267 100644
--- a/python/vyos/interfaceconfig.py
+++ b/python/vyos/interfaceconfig.py
@@ -176,30 +176,39 @@ class Interface:
f.write(str(ifalias))
- @property
- def linkstate(self):
- 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
+ def up(self):
+ """
+ Bring interface up
+
+ Example:
+
+ from vyos.interfaceconfig import Interface
+ i = Interface('br100', type='bridge')
+ i.up()
+ """
+
+ # Assemble command executed on system. Unfortunately there is no way
+ # to up/down an interface via sysfs
+ cmd = 'ip link set dev "{}" up'.format(self._ifname)
+ self._cmd(cmd)
+
+
+ def down(self):
+ """
+ Bring interface down
+
+ Example:
+
+ from vyos.interfaceconfig import Interface
+ i = Interface('br100', type='bridge')
+ i.down()
+ """
+
+ # Assemble command executed on system. Unfortunately there is no way
+ # to up/down an interface via sysfs
+ cmd = 'ip link set dev "{}" down'.format(self._ifname)
+ self._cmd(cmd)
- @linkstate.setter
- def linkstate(self, state='up'):
- if str(state).lower() == 'up' or str(state).lower() == 'down':
- self._linkstate = str(state).lower()
- else:
- self._linkstate = 'up'
- try:
- ret = subprocess.check_output(
- ['ip link set dev ' + self._ifname + ' ' + state], shell=True).decode()
- except subprocess.CalledProcessError as e:
- if self._debug():
- self._debug(e)
def _debug(self, e=None):
"""