Skip to content

feat(admin): import existing host VMs (#166)#174

Merged
v0l merged 1 commit into
masterfrom
feat/import-vm-166
Jul 17, 2026
Merged

feat(admin): import existing host VMs (#166)#174
v0l merged 1 commit into
masterfrom
feat/import-vm-166

Conversation

@v0l

@v0l v0l commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

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 to user_id and 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 a job_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 WorkJob to 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 the Completed { result } payload.

Imported VMs use the fixed Proxmox id mapping (vmid = db_id + 100), inserted via a new insert_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: shared HostVmSpec type; ListUnmanagedVms + ImportVm work jobs
  • lnvps_api: VmHostClient::list_host_vms trait method + Proxmox impl (net0/scsi0 parsing, ProxmoxVmId::inner), VmProvisioner::import_vm, worker handlers, DummyVmHost discovery registry for tests
  • lnvps_api_admin: two endpoints + request/response models
  • API_CHANGELOG.md

Tests

  • test_import_vm — success, re-import rejection, not-found, missing-custom-pricing scenarios
  • parse_mac_from_net, parse_storage_from_disk, proxmox_vm_id_inner
  • Workspace builds, fmt clean, no new clippy issues; affected crate test suites pass.

Notes / follow-ups

  • IP assignments are not imported yet (specs = CPU/mem/disk only); can be added later.
  • Imported VMs get a placeholder OS image (required FK) since the real OS is unknown — cosmetic, only used on reinstall.

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
v0l force-pushed the feat/import-vm-166 branch from 80b8a9a to 55cbeb2 Compare July 17, 2026 15:28
@v0l
v0l merged commit 9fd0ea8 into master Jul 17, 2026
8 checks passed
@v0l
v0l deleted the feat/import-vm-166 branch July 17, 2026 15:29
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Import VM

1 participant