Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/aleph/vm/network/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,18 @@
logger.error(f"Unknown exception while adding address {ip} to interface {device_name}: {e}")


def delete_ip_address(ipr: IPRoute, device_name: str, ip: IPv4Interface | IPv6Interface):
def delete_ip_address(ipr: IPRoute, device_name: str, ip: str, mask: int):
"""Delete an IP address to the given interface."""
interface_index: list[int] = ipr.link_lookup(ifname=device_name)
if not interface_index:
msg = f"Interface {device_name} does not exist, can't delete address {ip} to it."
raise MissingInterfaceError(msg)
try:
ipr.addr("del", index=interface_index[0], address=str(ip.ip), mask=ip.network.prefixlen)
ipr.addr("del", index=interface_index[0], address=ip, mask=mask)

Check warning on line 71 in src/aleph/vm/network/interfaces.py

View check run for this annotation

Codecov / codecov/patch

src/aleph/vm/network/interfaces.py#L71

Added line #L71 was not covered by tests
except NetlinkError as e:
logger.exception(f"Unknown exception while deleting address {ip} to interface {device_name}: {e}")
logger.exception(f"Unknown exception while deleting address {ip}/{mask} to interface {device_name}: {e}")

Check warning on line 73 in src/aleph/vm/network/interfaces.py

View check run for this annotation

Codecov / codecov/patch

src/aleph/vm/network/interfaces.py#L73

Added line #L73 was not covered by tests
except OSError as e:
logger.exception(f"Unknown exception while deleting address {ip} to interface {device_name}: {e}")
logger.exception(f"Unknown exception while deleting address {ip}/{mask} to interface {device_name}: {e}")

Check warning on line 75 in src/aleph/vm/network/interfaces.py

View check run for this annotation

Codecov / codecov/patch

src/aleph/vm/network/interfaces.py#L75

Added line #L75 was not covered by tests


def set_link_up(ipr: IPRoute, device_name: str):
Expand Down Expand Up @@ -170,6 +170,11 @@
if self.ndp_proxy:
await self.ndp_proxy.delete_range(self.device_name)
with IPRoute() as ipr:
delete_ip_address(ipr, self.device_name, self.host_ip)
delete_ip_address(ipr, self.device_name, self.host_ipv6)
interface_index: list[int] = ipr.link_lookup(ifname=self.device_name)
for addr in ipr.get_addr(index=interface_index):
# The order of attributes in the attrs field comes from the Netlink protocol
attrs = dict(addr["attrs"])
ip_addr: str = attrs["IFA_ADDRESS"]
mask: int = addr["prefixlen"]
delete_ip_address(ipr, self.device_name, ip_addr, mask)

Check warning on line 179 in src/aleph/vm/network/interfaces.py

View check run for this annotation

Codecov / codecov/patch

src/aleph/vm/network/interfaces.py#L176-L179

Added lines #L176 - L179 were not covered by tests
delete_tap_interface(ipr, self.device_name)
Loading