summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2019-09-24 18:48:49 +0200
committerChristian Poessinger <christian@poessinger.com>2019-09-24 21:53:25 +0200
commit3e108025a16a6d4db1bc08ea9161709b13295dfb (patch)
treec8f452188a93f10700fb57fb12a8e9fcc364bf00
parent12d0cdf69ba15dccb705e212ea605b692f825dbd (diff)
downloadvyos-1x-3e108025a16a6d4db1bc08ea9161709b13295dfb.tar.gz
vyos-1x-3e108025a16a6d4db1bc08ea9161709b13295dfb.zip
Python/ifconfig: T1557: loopback: implement derived remove()
-rw-r--r--python/vyos/ifconfig.py15
-rwxr-xr-xsrc/conf_mode/interface-loopback.py16
2 files changed, 23 insertions, 8 deletions
diff --git a/python/vyos/ifconfig.py b/python/vyos/ifconfig.py
index 86e2084d3..776fe1a23 100644
--- a/python/vyos/ifconfig.py
+++ b/python/vyos/ifconfig.py
@@ -680,6 +680,21 @@ class LoopbackIf(Interface):
def __init__(self, ifname):
super().__init__(ifname, type='loopback')
+ def remove(self):
+ """
+ Loopback interface can not be deleted from operating system. We can
+ only remove all assigned IP addresses.
+
+ Example:
+ >>> from vyos.ifconfig import Interface
+ >>> i = LoopbackIf('lo').remove()
+ """
+ # remove all assigned IP addresses from interface
+ for addr in self.get_addr():
+ self.del_addr(addr)
+
+ # question: do we also delerte the loopback address? 127.0.0.1/8
+
class DummyIf(Interface):
diff --git a/src/conf_mode/interface-loopback.py b/src/conf_mode/interface-loopback.py
index 46fc6809b..10722d137 100755
--- a/src/conf_mode/interface-loopback.py
+++ b/src/conf_mode/interface-loopback.py
@@ -72,20 +72,20 @@ def generate(loopback):
return None
def apply(loopback):
- lo = LoopbackIf(loopback['intf'])
- if not loopback['deleted']:
+ l = LoopbackIf(loopback['intf'])
+ if loopback['deleted']:
+ l.remove()
+ else:
# update interface description used e.g. within SNMP
- lo.set_alias(loopback['description'])
+ l.set_alias(loopback['description'])
# Configure interface address(es)
# - not longer required addresses get removed first
# - newly addresses will be added second
+ for addr in loopback['address_remove']:
+ l.del_addr(addr)
for addr in loopback['address']:
- lo.add_addr(addr)
-
- # remove interface address(es)
- for addr in loopback['address_remove']:
- lo.del_addr(addr)
+ l.add_addr(addr)
return None