Skip to content

Commit

Permalink
Inline superfluous function get_unused_ips
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasjuhrich committed Jul 5, 2024
1 parent 937bf77 commit b9f4407
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 16 deletions.
13 changes: 0 additions & 13 deletions pycroft/lib/net.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,6 @@ def __init__(self) -> None:
super().__init__("MAC address already exists")


def get_unused_ips(
subnets: t.Iterable[Subnet],
) -> dict[Subnet, t.Iterator[netaddr.IPAddress]]:
import warnings

warnings.warn(
"Use `subnet.iter_unused_ips()` instead of `net.get_unused_ips`",
DeprecationWarning,
stacklevel=2,
)
return {subnet: subnet.unused_ips_iter() for subnet in subnets}


def get_free_ip(subnets: t.Iterable[Subnet]) -> tuple[netaddr.IPAddress, Subnet]:
try:
return next((ip, subnet) for subnet in subnets for ip in subnet.unused_ips_iter())
Expand Down
6 changes: 3 additions & 3 deletions web/blueprints/host/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pycroft.exc import PycroftException
from pycroft.helpers.net import mac_regex, get_interface_manufacturer
from pycroft.lib import host as lib_host
from pycroft.lib.net import get_subnets_for_room, get_unused_ips
from pycroft.lib.net import get_subnets_for_room
from pycroft.lib.facilities import get_room
from pycroft.model import session
from pycroft.model.host import Host, Interface
Expand Down Expand Up @@ -247,10 +247,10 @@ def interface_edit(interface_id: int) -> ResponseReturnValue:

subnets = get_subnets_for_room(interface.host.room)
current_ips = [ip.address for ip in interface.ips]
unused_ips = [ip for subnet in subnets for ip in subnet.unused_ips_iter()]

form = InterfaceForm(obj=interface)
form.meta.current_mac = interface.mac
unused_ips = [ip for ips in get_unused_ips(subnets).values() for ip in ips]
form.ips.choices = [(str(ip), str(ip)) for ip in current_ips + unused_ips]

def default_response() -> ResponseReturnValue:
Expand Down Expand Up @@ -287,7 +287,7 @@ def interface_create(host_id: int) -> ResponseReturnValue:
host = get_host_or_404(host_id)
subnets = get_subnets_for_room(host.room)
form = InterfaceForm()
unused_ips = [ip for ips in get_unused_ips(subnets).values() for ip in ips]
unused_ips = [ip for subnet in subnets for ip in subnet.unused_ips_iter()]
form.ips.choices = [(str(ip), str(ip)) for ip in unused_ips]

def default_response() -> ResponseReturnValue:
Expand Down

0 comments on commit b9f4407

Please sign in to comment.