feat(lxc): support reinstall for LXC created from CT template file
Previously the reinstall endpoint required cached.template_id (clone-from-VM-
template flow), so LXC instances created via the wizard from an OS template
file (e.g. local:vztmpl/debian-13-...tar.zst) returned 'VM has no associated
template; reinstall is not available'.
Now reinstall works in two modes:
1) clone-from-template (existing): VM/LXC with cached.template_id pointing
to OSTemplate.vmid
2) ostemplate-file (new, LXC only): cached.template_name like
'storage:vztmpl/...tar.zst'. Reinstall stops, deletes, then re-creates
the container with the same VMID using create_lxc_container, preserving
network config, storage, rootfs size, swap, features, ssh_keys, etc.
pulled from the previous container config + VMInstance cache.
This commit is contained in:
@@ -409,16 +409,24 @@ def reinstall_vm_endpoint(
|
||||
VMInstance.vmid == vmid,
|
||||
VMInstance.deleted_at.is_(None),
|
||||
).first()
|
||||
if not cached or not cached.template_id:
|
||||
raise HTTPException(status_code=400, detail="VM has no associated template; reinstall is not available")
|
||||
if not cached:
|
||||
raise HTTPException(status_code=404, detail="VM not found")
|
||||
|
||||
tpl = db.query(OSTemplate).filter(OSTemplate.id == cached.template_id).first()
|
||||
if not tpl or not tpl.vmid:
|
||||
raise HTTPException(status_code=400, detail="Template not found or invalid")
|
||||
is_lxc = (cached.vm_type == 'lxc')
|
||||
tpl = None
|
||||
if cached.template_id:
|
||||
tpl = db.query(OSTemplate).filter(OSTemplate.id == cached.template_id).first()
|
||||
if not tpl or not tpl.vmid:
|
||||
raise HTTPException(status_code=400, detail="Template not found or invalid")
|
||||
elif is_lxc and cached.template_name and ':' in cached.template_name:
|
||||
# LXC created from CT template file (e.g. local:vztmpl/debian-13-...tar.zst)
|
||||
tpl = None
|
||||
else:
|
||||
raise HTTPException(status_code=400, detail="VM has no associated template; reinstall is not available")
|
||||
|
||||
task = DeployTask(
|
||||
kind='reinstall', name=cached.name, status='pending', step='В очереди...', progress=0,
|
||||
template_id=tpl.id, server_id=server_id, user_id=current_user.id,
|
||||
template_id=tpl.id if tpl else None, server_id=server_id, user_id=current_user.id,
|
||||
vmid=vmid, node=node,
|
||||
)
|
||||
db.add(task); db.commit(); db.refresh(task)
|
||||
|
||||
Reference in New Issue
Block a user