Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow a(aaa)_add with IP from non-existent network #367

Merged
merged 2 commits into from
Dec 16, 2024

Conversation

pederhan
Copy link
Member

Adds the ability for the commands a_add and aaaa_add to add an IP from a network that cannot be found with -force. Previously, trying to add an IP from a network that could not be found raised a 404 error, which is not something we intended. This PR fixes that by using ok404=True in Network.get_by_ip().

All other calls to Network.get_by_ip expect it to return None when the network cannot be found:

if net_or_ip.is_ip() and not autodetect:
ipaddr = net_or_ip.as_ip()
try:
network = Network.get_by_ip(ipaddr)
if network:
if ipaddr == network.network_address:
raise InvalidIPAddress(
f"IP {ipaddr} is a network address, not a host address"
)
elif ipaddr == network.broadcast_address:
raise InvalidIPAddress(
f"IP {ipaddr} is a broadcast address, not a host address"
)

elif net_or_ip.is_network() or autodetect:
network = (
Network.get_by_ip(net_or_ip.as_ip())
if autodetect
else Network.get_by_network(str(network_or_ip))
)
if network:
data["network"] = str(network.network)

network = Network.get_by_ip(ip)
if not network:
raise EntityNotFound(f"{ip} isn't in a network controlled by MREG")

This PR now ensures the 404 error is handled when the network does, in fact, not exist.

@pederhan pederhan requested a review from terjekv December 16, 2024 10:14
Copy link
Collaborator

@terjekv terjekv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Tests got canceled? :(

@pederhan pederhan merged commit 516393f into master Dec 16, 2024
18 checks passed
@pederhan pederhan deleted the allow-ip-from-non-existent-network branch December 16, 2024 10:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants