feat(admin): import existing host VMs (#166)#174
Merged
Conversation
Add admin capability to adopt VMs that exist on a host but aren't tracked
in the database:
- GET /api/admin/v1/hosts/{id}/vms/unmanaged - discover host VMs with no
matching DB record
- POST /api/admin/v1/hosts/{id}/vms/import - import one VM, assigned to a
user and billed via the region's custom pricing (required), capturing
the VM's live CPU/memory/disk specs into a custom template
The admin service has no direct host access, so both operations dispatch
a WorkJob to the worker; discovery replies over a temporary Redis pub/sub
channel. Imported VMs use the fixed Proxmox id mapping (vmid = db_id + 100)
so lifecycle operations target the correct host VM. Proxmox only.
Fixes #166
v0l
added a commit
that referenced
this pull request
Jul 17, 2026
Add ADMIN_API_ENDPOINTS.md entries for the unmanaged-VM discovery and VM import endpoints introduced in #174.
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.
Fixes #166
Summary
Adds an admin capability to adopt VMs that already exist on a host but aren't tracked in the database.
GET /api/admin/v1/hosts/{id}/vms/unmanaged— lists host VMs with no matching DB record (host vmid, mapped DB id, name, CPU/memory/disk specs, storage, MAC, running state).POST /api/admin/v1/hosts/{id}/vms/import({ host_vm_id, user_id, reason? }) — imports one VM: assigned touser_idand billed via the region's custom pricing (required — fails if the region has none), capturing the VM's current CPU/memory/disk specs into a custom template. Returns ajob_id. Proxmox only.Architecture
The admin service has no direct host connection (host actions go through the worker over Redis), so both operations dispatch a
WorkJobto the worker. Per design, discovery replies over a temporary Redis pub/sub channel (per-request UUID) reusing the existing job-feedback infra — the admin endpoint subscribes before dispatching and waits (30s timeout) for theCompleted { result }payload.Imported VMs use the fixed Proxmox id mapping (
vmid = db_id + 100), inserted via a newinsert_vm_with_id, so all subsequent lifecycle operations target the correct host VM.Changes
lnvps_db/ mock:insert_vm_with_id(explicit-id insert)lnvps_api_common: sharedHostVmSpectype;ListUnmanagedVms+ImportVmwork jobslnvps_api:VmHostClient::list_host_vmstrait method + Proxmox impl (net0/scsi0 parsing,ProxmoxVmId::inner),VmProvisioner::import_vm, worker handlers,DummyVmHostdiscovery registry for testslnvps_api_admin: two endpoints + request/response modelsAPI_CHANGELOG.mdTests
test_import_vm— success, re-import rejection, not-found, missing-custom-pricing scenariosparse_mac_from_net,parse_storage_from_disk,proxmox_vm_id_innerNotes / follow-ups