machine: machine set only when machine's stopped

Requires that the specified machine's state is `define.Stopped` in order
to set settings.

Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
This commit is contained in:
Jake Correnti
2024-02-13 15:28:36 -05:00
parent 4304e1075a
commit 0e9d867555
5 changed files with 51 additions and 19 deletions

View File

@ -3,6 +3,7 @@ package qemu
import (
"bufio"
"bytes"
"errors"
"fmt"
"net"
"os"
@ -255,6 +256,17 @@ func (q *QEMUStubber) resizeDisk(newSize strongunits.GiB, diskPath *define.VMFil
}
func (q *QEMUStubber) SetProviderAttrs(mc *vmconfigs.MachineConfig, opts define.SetOptions) error {
mc.Lock()
defer mc.Unlock()
state, err := q.State(mc, false)
if err != nil {
return err
}
if state != define.Stopped {
return errors.New("unable to change settings unless vm is stopped")
}
if opts.DiskSize != nil {
if err := q.resizeDisk(*opts.DiskSize, mc.ImagePath); err != nil {
return err