From 6731515709a7f230308cb69cc56b9cedff6e85b5 Mon Sep 17 00:00:00 2001 From: pederhan Date: Mon, 16 Dec 2024 11:03:45 +0100 Subject: [PATCH] Allow `a(aaa)_add` with IP from non-existent network --- mreg_cli/api/models.py | 2 +- mreg_cli/commands/host_submodules/a_aaaa.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/mreg_cli/api/models.py b/mreg_cli/api/models.py index 31a44da2..2f36499c 100644 --- a/mreg_cli/api/models.py +++ b/mreg_cli/api/models.py @@ -1658,7 +1658,7 @@ def get_by_ip(cls, ip: IP_AddressT) -> Self | None: :returns: The network if found, None otherwise. :raises EntityNotFound: If the network is not found. """ - resp = get(Endpoint.NetworksByIP.with_id(str(ip))) + resp = get(Endpoint.NetworksByIP.with_id(str(ip)), ok404=True) if not resp: return None return cls.model_validate_json(resp.text) diff --git a/mreg_cli/commands/host_submodules/a_aaaa.py b/mreg_cli/commands/host_submodules/a_aaaa.py index 1d79b700..cd9fa836 100644 --- a/mreg_cli/commands/host_submodules/a_aaaa.py +++ b/mreg_cli/commands/host_submodules/a_aaaa.py @@ -181,6 +181,9 @@ def _add_ip( network = Network.get_by_ip(ip_or_net.as_ip()) ip = ip_or_net.as_ip() + if not force and not network: + raise ForceMissing(f"Network for {ip} not found, must force") + if not force and network and network.frozen: raise ForceMissing(f"Network {network.network} is frozen, must force")