Integrate NetBox VM management#340
Merged
Merged
Conversation
Add NetBox integration to register and remove LXC records that mirror managed containers. - Add utils/netbox.js implementing NetBox API helpers: nbFetch, findClusterId, createVirtualMachine, deleteVirtualMachine, and withNetbox (loads netbox_url/netbox_token from Settings). - Use withNetbox/createVirtualMachine in bin/create-container.js to register a VM after container creation (non-fatal; errors are warned). - Use withNetbox/deleteVirtualMachine in routers/api/v1/containers.js to remove the VM when a container is deleted. - Expose new settings keys (netbox_url, netbox_token) in routers/api/v1/settings.js for GET/PUT so NetBox credentials can be configured. The NetBox deletion helper is resilient to errors (logs but does not throw) to avoid blocking core workflows.
Add helpers to resolve NetBox site and device IDs (findSiteId, findDeviceId) and extend createVirtualMachine to accept nodeName. The code now concurrently resolves cluster, site, and device IDs and includes site/device fields in the VM payload when available. Also pass nodeName from the container script when creating the NetBox VM record so the Proxmox node can be mapped to the NetBox device.
Expose NetBox URL/token in settings and types, add UI inputs and defaults; include vcpus/memory/disk when creating VMs and export a new updateVirtualMachine helper to patch resources by hostname. Also tighten hostname validation on the container form and improve API error toast details. Minor: include **/node_modules in .dockerignore.
Collaborator
Author
runleveldev
requested changes
Jun 12, 2026
Replace hardcoded vCPU/memory/disk values with actual provisioned values read from the LXC config. Add parseRootfsSizeGb helper that parses Proxmox LXC `rootfs` size strings (supports T/G/M/K, defaults to GB) and returns rounded gigabytes or null if unparseable. Update create-container flow to set vcpus, memoryMb and diskGb from the container config. Add a design note in netbox utils documenting why standalone functions (stateless Token auth) are used instead of a NetBoxApi class.
Collaborator
Author
|
@copilot resolve the merge conflicts in this pull request |
Contributor
Resolved. I merged |
Collaborator
Author
|
@copilot resolve the merge conflicts in this pull request |
Contributor
Resolved. I merged the latest |
auto-merge was automatically disabled
June 12, 2026 20:29
Head branch was pushed to by a user without write access
runleveldev
approved these changes
Jun 12, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.



Add NetBox integration to register and remove LXC records that mirror managed containers.
utils/netbox.jsimplementing NetBox API helpers:nbFetch,findClusterId,createVirtualMachine,deleteVirtualMachine, and withNetbox (loads netbox_url/netbox_token from Settings).bin/create-container.jsto register a VM after container creation (non-fatal; errors are warned).routers/api/v1/settings.jsfor GET/PUT so NetBox credentials can be configured.The NetBox deletion helper is resilient to errors (logs but does not throw) to avoid blocking core workflows.
NetBox Integration — How It Works
All NetBox logic lives in utils/netbox.js. It's invoked from two places: bin/create-container.js (on create) and routers/api/v1/containers.js (on delete).
Prerequisites (manual setup in NetBox)
The integration is opt-in — it silently does nothing if these two settings are absent from the
Settingstable:netbox_urlhttps://netbox.example.comnetbox_tokenThe integration also currently expects a cluster to already exist in NetBox whose name matches your
Site.name. The cluster is required; site and device are looked up opportunistically.On container creation (create-container.js)
Triggered after the container is running and has an IP address. Steps:
flowchart TD A[withNetbox: check settings] -->|missing| Z[skip silently] A -->|present| B[Parallel lookups] B --> C[findClusterId — required\nmatches Site.name] B --> D[findSiteId — optional\nmatches Site.name in /dcim/sites/] B --> E[findDeviceId — optional\nmatches Node.name in /dcim/devices/] C --> F[POST /virtualization/virtual-machines/\nname=hostname, cluster, site?, device?\ncomments = created-by username] F --> G[POST /virtualization/interfaces/\neth0 on the VM] G --> H[POST /ipam/ip-addresses/\nassigned to eth0, CIDR notation] H --> I[PATCH virtual-machine\nset primary_ip4]findClusterIdfails (cluster not found), the whole call throws — caught by thetry/catchin create-container.js and logged as a non-fatal warning. The container is still markedrunning.siteanddeviceare only included in the VM body if the lookups return a result. Missing ones are silently omitted.On container deletion (containers.js DELETE handler)
flowchart TD A[withNetbox: check settings] -->|missing| Z[skip silently] A -->|present| B[GET /virtualization/virtual-machines/?name=hostname] B -->|not found| C[log and return] B -->|found| D[GET /virtualization/interfaces/?virtual_machine_id=id] D --> E[For each interface:\nGET assigned IP addresses] E --> F[DELETE each IP address] F --> G[DELETE each interface] G --> H[DELETE virtual-machine]Deletion is fully non-throwing — any error is caught, logged to stderr, and the primary container deletion proceeds regardless.
What ends up in NetBox per container
virtualization.virtual-machinename= hostname,cluster= site name,site= site (if found),device= Proxmox node (if found),comments="This container was built using opensource-server\nCreated by: <username>"virtualization.interfacename=eth0, attached to the VMipam.ip-address/32CIDR, assigned toeth0, set asprimary_ip4