Skip to content

Commit

Permalink
Merge pull request #6042 from FarooqAbdulla02/nm_flush_ipaddr
Browse files Browse the repository at this point in the history
Remove IPv4 Addresses of network interface.
  • Loading branch information
richtja authored Oct 17, 2024
2 parents 19ab1e2 + 1db9a62 commit 3b1f5cb
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions avocado/utils/network/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,25 @@ def flush_ipaddr(self):
msg = f"Failed to flush ipaddr. {ex}"
raise NWException(msg)

def nm_flush_ipaddr(self):
"""Remove all the IPv4 address for this interface by using IP tool.
This method will explicitly identifies all available IP addresses with
netmask of interfaces and deletes them.
You must have sudo permissions to run this method on a host.
"""
cmd = f"nmcli -g ip4.ADDRESS device show {self.name}"
ipaddresses = run_command(cmd, self.host, sudo=True).strip().split(" | ")
if ipaddresses:
try:
for ipaddr in ipaddresses:
cmd = f"ip addr delete {ipaddr} dev {self.name}"
run_command(cmd, self.host, sudo=True)
except Exception as ex:
msg = f"Failed to flush ipaddr. {ex}"
raise NWException(msg)

def remove_link(self):
"""Deletes virtual interface link.
Expand Down

0 comments on commit 3b1f5cb

Please sign in to comment.