Polish code

This commit is contained in:
AlexSSD7 2023-08-29 14:24:18 +01:00
commit 0870f8113a
10 changed files with 246 additions and 238 deletions

View file

@ -17,6 +17,7 @@ import (
"log/slog"
"github.com/AlexSSD7/linsk/sshutil"
"github.com/AlexSSD7/linsk/utils"
"github.com/alessio/shellescape"
"github.com/bramvdbogaerde/go-scp"
@ -91,8 +92,6 @@ func NewVM(logger *slog.Logger, cfg VMConfig) (*VM, error) {
return nil, errors.Wrap(err, "get free port for ssh server")
}
// TODO: Configurable memory allocation
cmdArgs := []string{"-serial", "stdio", "-m", fmt.Sprint(cfg.MemoryAlloc), "-smp", fmt.Sprint(runtime.NumCPU())}
baseCmd := "qemu-system"
@ -373,7 +372,7 @@ func (vm *VM) Cancel() error {
}
} else {
vm.logger.Warn("Sending poweroff command to the VM")
_, err = runSSHCmd(sc, "poweroff")
_, err = sshutil.RunSSHCmd(context.Background(), sc, "poweroff")
_ = sc.Close()
if err != nil {
vm.logger.Warn("Could not power off the VM safely", "error", err.Error())