diff options
author | Jernej Jakob <jernej.jakob@gmail.com> | 2020-05-02 18:07:15 +0200 |
---|---|---|
committer | Jernej Jakob <jernej.jakob@gmail.com> | 2020-05-02 20:40:43 +0200 |
commit | a4e29a0de10572e8bfb2804a86ae3aa3eaac5ff7 (patch) | |
tree | d1500782bedede700115389114d6541a699f0c72 /python/vyos/ifconfig/interface.py | |
parent | 9e51fa4ad6c2edd25c57d17e520a5b5c83a4f5b8 (diff) | |
download | vyos-1x-a4e29a0de10572e8bfb2804a86ae3aa3eaac5ff7.tar.gz vyos-1x-a4e29a0de10572e8bfb2804a86ae3aa3eaac5ff7.zip |
interface: T2367: add flush_addrs function
Add function that flushes all addresses from an interface.
Diffstat (limited to 'python/vyos/ifconfig/interface.py')
-rw-r--r-- | python/vyos/ifconfig/interface.py | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/python/vyos/ifconfig/interface.py b/python/vyos/ifconfig/interface.py index 8bcfda13c..6241c83b5 100644 --- a/python/vyos/ifconfig/interface.py +++ b/python/vyos/ifconfig/interface.py @@ -240,15 +240,11 @@ class Interface(Control): >>> i = Interface('eth0') >>> i.remove() """ - # stop DHCP(v6) if running - self.dhcp.v4.delete() - self.dhcp.v6.delete() # remove all assigned IP addresses from interface - this is a bit redundant # as the kernel will remove all addresses on interface deletion, but we # can not delete ALL interfaces, see below - for addr in self.get_addr(): - self.del_addr(addr) + self.flush_addrs() # --------------------------------------------------------------------- # Any class can define an eternal regex in its definition @@ -712,3 +708,16 @@ class Interface(Control): self._addr.remove(addr) return ret + + def flush_addrs(self): + """ + Flush all addresses from an interface, including DHCP. + + Will raise an exception on error. + """ + # stop DHCP(v6) if running + self.dhcp.v4.delete() + self.dhcp.v6.delete() + + # flush all addresses + self._cmd(f'ip addr flush dev "{self.config["ifname"]}"') |