package app import ( "errors" "github.com/Nwflower/reims-go/internal/driver" "github.com/Nwflower/reims-go/internal/vmstart" ) // CloneVMCoW derives a VM through the source VM's owning driver. func (a *App) CloneVMCoW(sourceName, cloneName string) error { return a.CloneVMCoWWithDriver("", sourceName, cloneName) } func (a *App) CloneVMCoWWithDriver(driverID, sourceName, cloneName string) error { _, err := a.cloneVMCoWWithDriverInfo(driverID, sourceName, cloneName) return err } func (a *App) cloneVMCoWWithDriverInfo(driverID, sourceName, cloneName string) (driver.VMInfo, error) { a.mu.Lock() svc := a.lifecycleSvc a.mu.Unlock() if svc == nil { return driver.VMInfo{}, errors.New("driver lifecycle is not initialized") } ref := driver.VMRef{DriverID: driverID, Name: sourceName} w := vmstart.LineWriter(func(line string) { a.emitVMLogForDriver(driverID, cloneName, line) }) cloned, err := svc.CloneCoWWithInfo(a.baseCtx(), ref, cloneName, w, w) if err != nil { return driver.VMInfo{}, err } a.wakePoll() a.emitLifecycleStateChanged() return cloned, nil }