forked from netbox-community/Device-Type-Library-Import
-
Notifications
You must be signed in to change notification settings - Fork 6
feat: module bay types #136
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
Open
marcinpsk
wants to merge
20
commits into
main
Choose a base branch
from
develop
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
b32ec48
fix(repo): add REPO_URL=local sentinel to bypass git entirely (#124)
mmguero 5694aaa
fix(repo): validate the local library layout and share the check with…
marcinpsk 1084c1c
chore: sync develop with main
marcinpsk d5e848a
feat(module-bay-types): carry NetBox 4.7 module bay types through the…
marcinpsk a0ee29b
feat(export): write the NetBox 4.5 port-mappings stanza (#134)
marcinpsk 43480e7
fix(export): default front-port positions for pre-4.5 servers
marcinpsk a9fed72
feat(export): report module bays exported without a position
marcinpsk c20153d
refactor: drop version branches unreachable at the NetBox 4.3 floor (…
marcinpsk 7b3c9e5
fix(export): treat an omitted front-port positions as the default
marcinpsk ac319ce
fix(config): report a NETBOX_URL that sends the token in cleartext
marcinpsk 2f0bd80
fix(module-bay-types): separate a catalog load failure from a name miss
marcinpsk 0b12aca
fix: close the paths that resolve a short catalog to the wrong entry
marcinpsk 51dc2a8
test(module-bay-types): restore the vendor directory owner-only
marcinpsk 5d80883
fix: stop three silent data paths the adversarial review found
marcinpsk c4baac8
fix(mappings): report legacy truncation and detect a legacy rear-port…
marcinpsk 26f24e9
test: split composite assertions and drop a useless lambda
marcinpsk 15ac9a9
fix(mappings): name the stanza as authoritative instead of blaming a …
marcinpsk e0fb671
refactor: remove two ways for the same fact to be stated twice
marcinpsk d704a71
fix(mappings): only an explicit list may clear a relation
marcinpsk c2c16cf
fix(mappings): clearing a mapping now obeys --remove-components
marcinpsk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,61 +1,27 @@ | ||
| """NetBox version-compatibility helpers. | ||
|
|
||
| Centralises filter parameter names that changed between NetBox releases so | ||
| that every caller uses the same logic and drift is impossible. | ||
|
|
||
| NetBox 4.1 renamed several filter keys on the DCIM endpoints: | ||
|
|
||
| devicetype_id → device_type_id | ||
| moduletype_id → module_type_id | ||
|
|
||
| Any code that constructs endpoint filter kwargs should call the helpers | ||
| here rather than inlining ``"device_type_id" if new_filters else "devicetype_id"``. | ||
| Centralises the version line each feature sits behind so that every caller uses the | ||
| same logic and drift is impossible. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import re | ||
|
|
||
| def device_type_filter_key(new_filters: bool) -> str: | ||
| """Return the correct filter parameter name for device-type component queries. | ||
| # Selecting or sending the relation below this release fails the whole query. | ||
| MODULE_BAY_TYPE_MINIMUM_VERSION = (4, 7) | ||
|
|
||
| Args: | ||
| new_filters: ``True`` for NetBox ≥ 4.1 (returns ``"device_type_id"``); | ||
| ``False`` for older releases (returns ``"devicetype_id"``). | ||
| """ | ||
| return "device_type_id" if new_filters else "devicetype_id" | ||
|
|
||
| def parse_netbox_version(version) -> tuple[int, int]: | ||
| """Return ``(major, minor)`` from a NetBox version string. | ||
|
|
||
| def module_type_filter_key(new_filters: bool) -> str: | ||
| """Return the correct filter parameter name for module-type component queries. | ||
|
|
||
| Args: | ||
| new_filters: ``True`` for NetBox ≥ 4.1 (returns ``"module_type_id"``); | ||
| ``False`` for older releases (returns ``"moduletype_id"``). | ||
| Padded to two parts so a single-component string cannot raise, and tolerant of the | ||
| suffixes NetBox ships ("4.7.0-beta2"). | ||
| """ | ||
| return "module_type_id" if new_filters else "moduletype_id" | ||
|
|
||
|
|
||
| def device_type_filter_kwargs(device_type_id: int, *, new_filters: bool) -> dict: | ||
| """Return filter kwargs for querying components of a device type. | ||
| raw = [int(re.sub(r"\D.*", "", part.strip()) or "0") for part in str(version).split(".")] | ||
| return tuple((raw + [0, 0])[:2]) # type: ignore[return-value] | ||
|
|
||
| Args: | ||
| device_type_id: NetBox ID of the device type. | ||
| new_filters: ``True`` for NetBox ≥ 4.1; ``False`` for older releases. | ||
|
|
||
| Returns: | ||
| A dict suitable for unpacking into ``endpoint.filter(**kwargs)``. | ||
| """ | ||
| return {device_type_filter_key(new_filters): device_type_id} | ||
|
|
||
|
|
||
| def module_type_filter_kwargs(module_type_id: int, *, new_filters: bool) -> dict: | ||
| """Return filter kwargs for querying components of a module type. | ||
|
|
||
| Args: | ||
| module_type_id: NetBox ID of the module type. | ||
| new_filters: ``True`` for NetBox ≥ 4.1; ``False`` for older releases. | ||
|
|
||
| Returns: | ||
| A dict suitable for unpacking into ``endpoint.filter(**kwargs)``. | ||
| """ | ||
| return {module_type_filter_key(new_filters): module_type_id} | ||
| def supports_module_bay_types(version) -> bool: | ||
| """Return True when this NetBox release exposes the module bay type relation.""" | ||
| return parse_netbox_version(version) >= MODULE_BAY_TYPE_MINIMUM_VERSION |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.