-
Notifications
You must be signed in to change notification settings - Fork 11
feat: set primary IP action #303
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
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
0d746a7
feat: UI improvements extracted from oob-sync
marcinpsk 0d71995
fix(template): close platform-row if and make new-import mapping form…
marcinpsk 88635b4
fix(AddPlatformMappingView): close TOCTOU window with select_for_update
marcinpsk 2bc4457
fix(AddPlatformMappingView): use _htmx_error_response and reject "-" OS
marcinpsk b72ee93
fix(ui): expose platform-mapping form in existing-device branches
marcinpsk 7d7be71
fix(ui): guard against duplicate PlatformMapping rows with proper row…
marcinpsk 517cc95
ui(platform): compact platform cell with a single edit icon -> combin…
marcinpsk 55509aa
fix(ui): use {% comment %} in _platform_manage_icon (multi-line {# #}…
marcinpsk 6020daa
test(templates): guard against multi-line {# #} comments leaking as text
marcinpsk abf769b
fix(import): forward server_key from mapping forms; use logger.exception
marcinpsk 847e274
feat(ipam): add auto-create IPAM on device/VM import
marcinpsk eeb9099
fix(ip_helpers): wrap create() in nested savepoint to avoid poisoning…
marcinpsk ee95c05
fix: duplicate PlatformMapping guard and expose VM created_ips in bul…
marcinpsk 506c40d
fix(ipam): address PR #84 review — server_key in HTMX mapping forms, …
marcinpsk 4bced09
refactor(ipam): remove generic auto-create-IPAM-on-import feature
marcinpsk 81ac570
feat(ipam): set Primary IP from LibreNMS mgmt IP on the IP-sync tab
marcinpsk a48ff0d
ui(ipam): rename toggle label to 'Set Primary IP'
marcinpsk dd0c621
feat(ipam): auto-select the management-IP row when 'Set Primary IP' i…
marcinpsk 8983a22
fix(ipam): surface IP-sync errors and warn when Primary IP has no int…
marcinpsk 0c17b06
fix(ipam): check response.ok when persisting the Set-Primary-IP toggl…
marcinpsk c7acffa
fix(ip-sync): scope existing-IP lookup to the target VRF
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -749,7 +749,7 @@ def import_single_device( | |
| 'interfaces': int, | ||
| 'cables': int, | ||
| 'ip_addresses': int | ||
| } | ||
| }, | ||
| } | ||
| """ | ||
| try: | ||
|
|
||
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
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
115 changes: 115 additions & 0 deletions
115
netbox_librenms_plugin/templates/netbox_librenms_plugin/htmx/_dt_mapping_form.html
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 |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| {% comment %} | ||
| Reusable "Add Device Type Mapping" form for the import validation modal. | ||
|
|
||
| Required context: | ||
| - libre_device (dict-like with device_id, hardware) | ||
| Optional context: | ||
| - preselect_device_type: a DeviceType instance to pre-fill the typeahead | ||
| (used in the existing-device + mismatch branch so a single click maps | ||
| `libre_device.hardware` → `existing_device.device_type`). | ||
| - submit_label (defaults to "Add Mapping") | ||
| {% endcomment %} | ||
| <form hx-post="{% url 'plugins:netbox_librenms_plugin:add_device_type_mapping' device_id=libre_device.device_id %}" | ||
| hx-swap="none" | ||
| hx-include="[name=role_{{ libre_device.device_id }}], [name=rack_{{ libre_device.device_id }}], [name=cluster_{{ libre_device.device_id }}], #use-sysname-toggle, #strip-domain-toggle" | ||
| class="mt-1" | ||
| id="dt-mapping-form-{{ libre_device.device_id }}"> | ||
| {% csrf_token %} | ||
| {% if server_key %}<input type="hidden" name="server_key" value="{{ server_key }}">{% endif %} | ||
| <div class="position-relative"> | ||
| <label for="dt-search-{{ libre_device.device_id }}" class="visually-hidden"> | ||
| Search device types | ||
| </label> | ||
| <input type="text" | ||
| class="form-control form-control-sm" | ||
| id="dt-search-{{ libre_device.device_id }}" | ||
| placeholder="Search device types…" | ||
| autocomplete="off" | ||
| {% if preselect_device_type %}value="{% if preselect_device_type.manufacturer %}{{ preselect_device_type.manufacturer.name }} — {% endif %}{{ preselect_device_type.display }}"{% endif %}> | ||
| <input type="hidden" | ||
| name="device_type_id" | ||
| id="dt-id-{{ libre_device.device_id }}" | ||
| value="{% if preselect_device_type %}{{ preselect_device_type.pk }}{% endif %}"> | ||
| <div id="dt-dropdown-{{ libre_device.device_id }}" | ||
| class="dropdown-menu w-100 shadow" | ||
| style="z-index:1050; max-height:200px; overflow-y:auto; display:none;"></div> | ||
| </div> | ||
| {# Disabled until a typeahead item is chosen (or a preselect value is present). #} | ||
| <button type="submit" | ||
| id="dt-submit-{{ libre_device.device_id }}" | ||
| class="btn btn-sm btn-primary mt-1 w-100" | ||
| {% if not preselect_device_type %}disabled{% endif %}>{{ submit_label|default:"Add Mapping" }}</button> | ||
| </form> | ||
| <script> | ||
| (function () { | ||
| var searchEl = document.getElementById("dt-search-{{ libre_device.device_id }}"); | ||
| var dropdownEl = document.getElementById("dt-dropdown-{{ libre_device.device_id }}"); | ||
| var hiddenEl = document.getElementById("dt-id-{{ libre_device.device_id }}"); | ||
| var submitBtn = document.getElementById("dt-submit-{{ libre_device.device_id }}"); | ||
| if (!searchEl) return; | ||
| var timer = null; | ||
| var requestSeq = 0; | ||
|
|
||
| searchEl.addEventListener("input", function () { | ||
| clearTimeout(timer); | ||
| hiddenEl.value = ""; | ||
| submitBtn.disabled = true; | ||
| var q = this.value.trim(); | ||
| requestSeq += 1; | ||
| var seq = requestSeq; | ||
| if (q.length < 2) { dropdownEl.style.display = "none"; dropdownEl.innerHTML = ""; return; } | ||
| timer = setTimeout(function () { | ||
| var csrfToken = (document.querySelector('[name=csrfmiddlewaretoken]') || {}).value || ""; | ||
| fetch("{% url 'dcim-api:devicetype-list' %}?q=" + encodeURIComponent(q) + "&limit=20", { | ||
| headers: { "X-CSRFToken": csrfToken } | ||
| }) | ||
| .then(function (r) { | ||
| if (!r.ok) { throw new Error("HTTP " + r.status); } | ||
| return r.json(); | ||
| }) | ||
| .then(function (data) { | ||
| if (seq !== requestSeq) return; | ||
| dropdownEl.innerHTML = ""; | ||
| if (!data.results || data.results.length === 0) { | ||
| dropdownEl.innerHTML = '<a class="dropdown-item small py-1 text-muted disabled">No results</a>'; | ||
| } else { | ||
| data.results.forEach(function (dt) { | ||
| var a = document.createElement("a"); | ||
| a.className = "dropdown-item small py-1"; | ||
| a.href = "#"; | ||
| a.textContent = (dt.manufacturer ? dt.manufacturer.display + " — " : "") + dt.display; | ||
| a.addEventListener("click", function (e) { | ||
| e.preventDefault(); | ||
| searchEl.value = (dt.manufacturer ? dt.manufacturer.display + " — " : "") + dt.display; | ||
| hiddenEl.value = dt.id; | ||
| submitBtn.disabled = false; | ||
| dropdownEl.style.display = "none"; | ||
| }); | ||
| dropdownEl.appendChild(a); | ||
| }); | ||
| } | ||
| dropdownEl.style.display = "block"; | ||
| }) | ||
| .catch(function (error) { | ||
| if (seq !== requestSeq) return; | ||
| console.debug("Device type lookup failed:", error.message); | ||
| dropdownEl.style.display = "none"; | ||
| }); | ||
| }, 300); | ||
| }); | ||
|
|
||
| // Outside-click hides the dropdown. The listener self-removes once the | ||
| // form leaves the DOM (HTMX swap, modal teardown) so handlers don't | ||
| // accumulate on document each time this template re-renders. | ||
| function onDocClick(e) { | ||
| if (!document.body.contains(searchEl)) { | ||
| document.removeEventListener("click", onDocClick); | ||
| return; | ||
| } | ||
| if (!searchEl.contains(e.target) && !dropdownEl.contains(e.target)) { | ||
| dropdownEl.style.display = "none"; | ||
| } | ||
| } | ||
| document.addEventListener("click", onDocClick); | ||
| })(); | ||
| </script> |
15 changes: 15 additions & 0 deletions
15
netbox_librenms_plugin/templates/netbox_librenms_plugin/htmx/_platform_manage_icon.html
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 |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| {% comment %} | ||
| Compact pencil icon that opens the combined "manage platform" modal (map | ||
| LibreNMS OS to an existing platform, or create a new one). Keeps the platform | ||
| cell uncluttered. Requires: libre_device, server_key. | ||
| {% endcomment %} | ||
| {% if libre_device.os and libre_device.os != "-" %} | ||
| <button type="button" class="btn btn-sm btn-outline-secondary py-0 px-1 ms-1" | ||
| hx-get="{% url 'plugins:netbox_librenms_plugin:create_platform_from_import' device_id=libre_device.device_id %}?server_key={{ server_key|urlencode }}" | ||
| hx-target="#htmx-modal-content" | ||
| hx-swap="innerHTML" | ||
| title="Map or create platform for '{{ libre_device.os }}'" | ||
| aria-label="Map or create platform"> | ||
| <i class="mdi mdi-pencil"></i> | ||
| </button> | ||
| {% endif %} | ||
113 changes: 113 additions & 0 deletions
113
netbox_librenms_plugin/templates/netbox_librenms_plugin/htmx/_platform_mapping_form.html
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 |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| {% comment %} | ||
| Reusable "Add Platform Mapping" form for the import validation modal. | ||
|
|
||
| Required context: | ||
| - libre_device (dict-like with device_id, os) | ||
| Optional: | ||
| - preselect_platform: a Platform instance to pre-fill the typeahead. | ||
| - submit_label | ||
| {% endcomment %} | ||
| <form hx-post="{% url 'plugins:netbox_librenms_plugin:add_platform_mapping' device_id=libre_device.device_id %}" | ||
| hx-swap="none" | ||
| hx-include="[name=role_{{ libre_device.device_id }}], [name=rack_{{ libre_device.device_id }}], [name=cluster_{{ libre_device.device_id }}], #use-sysname-toggle, #strip-domain-toggle" | ||
| class="mt-1" | ||
| id="plat-mapping-form-{{ libre_device.device_id }}"> | ||
| {% csrf_token %} | ||
| {% if server_key %}<input type="hidden" name="server_key" value="{{ server_key }}">{% endif %} | ||
| <div class="position-relative"> | ||
| <label for="plat-search-{{ libre_device.device_id }}" class="visually-hidden"> | ||
| Search platforms | ||
| </label> | ||
| <input type="text" | ||
| class="form-control form-control-sm" | ||
| id="plat-search-{{ libre_device.device_id }}" | ||
| placeholder="Search platforms…" | ||
| autocomplete="off" | ||
| {% if preselect_platform %}value="{{ preselect_platform.name }}"{% endif %}> | ||
| <input type="hidden" | ||
| name="platform_id" | ||
| id="plat-id-{{ libre_device.device_id }}" | ||
| value="{% if preselect_platform %}{{ preselect_platform.pk }}{% endif %}"> | ||
| <div id="plat-dropdown-{{ libre_device.device_id }}" | ||
| class="dropdown-menu w-100 shadow" | ||
| style="z-index:1050; max-height:200px; overflow-y:auto; display:none;"></div> | ||
| </div> | ||
| {# Disabled until a typeahead item is chosen (or a preselect value is present). #} | ||
| <button type="submit" | ||
| id="plat-submit-{{ libre_device.device_id }}" | ||
| class="btn btn-sm btn-primary mt-1 w-100" | ||
| {% if not preselect_platform %}disabled{% endif %}>{{ submit_label|default:"Add Mapping" }}</button> | ||
| </form> | ||
| <script> | ||
| (function () { | ||
| var searchEl = document.getElementById("plat-search-{{ libre_device.device_id }}"); | ||
| var dropdownEl = document.getElementById("plat-dropdown-{{ libre_device.device_id }}"); | ||
| var hiddenEl = document.getElementById("plat-id-{{ libre_device.device_id }}"); | ||
| var submitBtn = document.getElementById("plat-submit-{{ libre_device.device_id }}"); | ||
| if (!searchEl) return; | ||
| var timer = null; | ||
| var requestSeq = 0; | ||
|
|
||
| searchEl.addEventListener("input", function () { | ||
| clearTimeout(timer); | ||
| hiddenEl.value = ""; | ||
| submitBtn.disabled = true; | ||
| var q = this.value.trim(); | ||
| requestSeq += 1; | ||
| var seq = requestSeq; | ||
| if (q.length < 2) { dropdownEl.style.display = "none"; dropdownEl.innerHTML = ""; return; } | ||
| timer = setTimeout(function () { | ||
| var csrfToken = (document.querySelector('[name=csrfmiddlewaretoken]') || {}).value || ""; | ||
| fetch("{% url 'dcim-api:platform-list' %}?q=" + encodeURIComponent(q) + "&limit=20", { | ||
| headers: { "X-CSRFToken": csrfToken } | ||
| }) | ||
| .then(function (r) { | ||
| if (!r.ok) { throw new Error("HTTP " + r.status); } | ||
| return r.json(); | ||
| }) | ||
| .then(function (data) { | ||
| if (seq !== requestSeq) return; | ||
| dropdownEl.innerHTML = ""; | ||
| if (!data.results || data.results.length === 0) { | ||
| dropdownEl.innerHTML = '<a class="dropdown-item small py-1 text-muted disabled">No results</a>'; | ||
| } else { | ||
| data.results.forEach(function (p) { | ||
| var a = document.createElement("a"); | ||
| a.className = "dropdown-item small py-1"; | ||
| a.href = "#"; | ||
| a.textContent = p.display || p.name; | ||
| a.addEventListener("click", function (e) { | ||
| e.preventDefault(); | ||
| searchEl.value = p.display || p.name; | ||
| hiddenEl.value = p.id; | ||
| submitBtn.disabled = false; | ||
| dropdownEl.style.display = "none"; | ||
| }); | ||
| dropdownEl.appendChild(a); | ||
| }); | ||
| } | ||
| dropdownEl.style.display = "block"; | ||
| }) | ||
| .catch(function (error) { | ||
| if (seq !== requestSeq) return; | ||
| console.debug("Platform lookup failed:", error.message); | ||
| dropdownEl.style.display = "none"; | ||
| }); | ||
| }, 300); | ||
| }); | ||
|
|
||
| // Outside-click hides the dropdown. The listener self-removes once the | ||
| // form leaves the DOM (HTMX swap, modal teardown) so handlers don't | ||
| // accumulate on document each time this template re-renders. | ||
| function onDocClick(e) { | ||
| if (!document.body.contains(searchEl)) { | ||
| document.removeEventListener("click", onDocClick); | ||
| return; | ||
| } | ||
| if (!searchEl.contains(e.target) && !dropdownEl.contains(e.target)) { | ||
| dropdownEl.style.display = "none"; | ||
| } | ||
| } | ||
| document.addEventListener("click", onDocClick); | ||
| })(); | ||
| </script> |
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.