Skip to content

Commit

Permalink
Allow a(aaa)_add with IP from non-existent network (#367)
Browse files Browse the repository at this point in the history
* Allow `a(aaa)_add` with IP from non-existent network

* Update changelog
  • Loading branch information
pederhan authored Dec 16, 2024
1 parent c2df782 commit 516393f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

<!-- ## Unreleased -->
## Unreleased

### Added

- `a_add` & `aaaa_add` `-force` option to force use an IP from a network that cannot be found in MREG.

### Fixed

- Commands that try to find networks by IP raising a 404 error instead of a proper error message when no network can be found with the given IP.

## [1.2.2](https://github.com/unioslo/mreg-cli/releases/tag/1.2.2) - 2024-12-09

Expand Down
2 changes: 1 addition & 1 deletion mreg_cli/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions mreg_cli/commands/host_submodules/a_aaaa.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down

0 comments on commit 516393f

Please sign in to comment.