Skip to content

Commit

Permalink
Remove ill-defined, broken, and unused ptr_name function
Browse files Browse the repository at this point in the history
In case this is needed, the commit can be reverted.

See discussion in #150.
  • Loading branch information
lukasjuhrich committed Jul 5, 2024
1 parent 9f257d4 commit 937bf77
Showing 1 changed file with 0 additions and 15 deletions.
15 changes: 0 additions & 15 deletions pycroft/lib/net.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
~~~~~~~~~~~~~~~
"""
import typing as t
from itertools import islice

import netaddr
from sqlalchemy import func, and_, cast
Expand Down Expand Up @@ -100,20 +99,6 @@ def get_subnets_with_usage() -> list[tuple[Subnet, SubnetUsage]]:
]


def ptr_name(network: netaddr.IPNetwork, ip_address: netaddr.IPAddress) -> str:
hostbits = network.max_prefixlen - network.prefixlen
if ip_address.version == 4:
num_octets = min((hostbits + 7 // 8), 1)
reversed_octets = reversed(ip_address.exploded.split('.'))
return '.'.join(islice(reversed_octets, num_octets))

if ip_address.version == 6:
num_chars = min((hostbits + 3 // 4), 1)
reversed_chars = reversed(ip_address.exploded.replace(':', ''))
return '.'.join(islice(reversed_chars, num_chars))
raise TypeError()


def delete_ip(session: Session, ip: netaddr.IPAddress) -> None:
# TODO use proper `delete` statement
session.delete(IP.q.filter_by(address=ip).first())

0 comments on commit 937bf77

Please sign in to comment.