summaryrefslogtreecommitdiff
path: root/python/vyos
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2019-08-30 12:06:59 +0200
committerChristian Poessinger <christian@poessinger.com>2019-08-30 12:06:59 +0200
commit17454c22554b6161dbc177f9e6b798ae6d73e7bc (patch)
treecaa6cd3f9dc5b4d490d351d598bafe85d6960a3d /python/vyos
parentcb1b72c5ccce1bd2d0f0b02eb4abeee0b5635d55 (diff)
downloadvyos-1x-17454c22554b6161dbc177f9e6b798ae6d73e7bc.tar.gz
vyos-1x-17454c22554b6161dbc177f9e6b798ae6d73e7bc.zip
Python/ifconfig: re-work and rename remove_interface() -> remove() to delete an interface
Diffstat (limited to 'python/vyos')
-rw-r--r--python/vyos/interfaceconfig.py39
1 files changed, 30 insertions, 9 deletions
diff --git a/python/vyos/interfaceconfig.py b/python/vyos/interfaceconfig.py
index f9e231267..1d3215a0a 100644
--- a/python/vyos/interfaceconfig.py
+++ b/python/vyos/interfaceconfig.py
@@ -27,6 +27,15 @@ dhclient_conf_dir = r'/var/lib/dhcp/dhclient_'
class Interface:
def __init__(self, ifname=None, type=None):
+ """
+ Create instance of an IP interface
+
+ Example:
+
+ from vyos.interfaceconfig import Interface
+ i = Interface('br111', type='bridge')
+ """
+
if not ifname:
raise Exception("interface name required")
@@ -46,11 +55,32 @@ class Interface:
self._ifname = str(ifname)
+
+ def remove(self):
+ """
+ Remove system interface
+
+ Example:
+
+ from vyos.interfaceconfig import Interface
+ i = Interface('br111')
+ i.remove()
+ """
+
+ # NOTE (Improvement):
+ # after interface removal no other commands should be allowed
+ # to be called and instead should raise an Exception:
+
+ cmd = 'ip link del dev "{}"'.format(self._ifname)
+ self._cmd(cmd)
+
+
def _cmd(self, command):
process = subprocess.Popen(command,stdout=subprocess.PIPE, shell=True)
proc_stdout = process.communicate()[0].strip()
pass
+
@property
def mtu(self):
"""
@@ -221,15 +251,6 @@ class Interface:
return True
return False
- def remove_interface(self):
- try:
- ret = subprocess.check_output(
- ['ip link del dev ' + self._ifname], shell=True).decode()
- return 0
- except subprocess.CalledProcessError as e:
- if self._debug():
- self._debug(e)
- return None
def get_addr(self, ret_prefix=None):
"""