Skip to content

Commit afa2744

Browse files
committed
store: add StatusSaved to the Instance Status
Signed-off-by: Norio Nomura <[email protected]>
1 parent 6ded041 commit afa2744

File tree

8 files changed

+25
-2
lines changed

8 files changed

+25
-2
lines changed

cmd/limactl/copy.go

+2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ func copyAction(cmd *cobra.Command, args []string) error {
7777
}
7878
if inst.Status == store.StatusStopped {
7979
return fmt.Errorf("instance %q is stopped, run `limactl start %s` to start the instance", instName, instName)
80+
} else if inst.Status == store.StatusSaved {
81+
return fmt.Errorf("instance %q is saved, run `limactl start %s` to restore the instance", instName, instName)
8082
}
8183
if legacySSH {
8284
scpFlags = append(scpFlags, "-P", fmt.Sprintf("%d", inst.SSHLocalPort))

cmd/limactl/disk.go

+5
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,9 @@ func diskUnlockAction(_ *cobra.Command, args []string) error {
331331
if inst.Status == store.StatusRunning {
332332
logrus.Warnf("Cannot unlock disk %q used by running instance %q", diskName, disk.Instance)
333333
continue
334+
} else if inst.Status == store.StatusSaved {
335+
logrus.Warnf("Cannot unlock disk %q used by saved instance %q", diskName, disk.Instance)
336+
continue
334337
}
335338
}
336339
if err := disk.Unlock(); err != nil {
@@ -387,6 +390,8 @@ func diskResizeAction(cmd *cobra.Command, args []string) error {
387390
if err == nil {
388391
if inst.Status == store.StatusRunning {
389392
return fmt.Errorf("cannot resize disk %q used by running instance %q. Please stop the VM instance", diskName, disk.Instance)
393+
} else if inst.Status == store.StatusSaved {
394+
return fmt.Errorf("cannot resize disk %q used by saved instance %q. Please restore and stop the VM instance", diskName, disk.Instance)
390395
}
391396
}
392397
}

cmd/limactl/edit.go

+2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ func editAction(cmd *cobra.Command, args []string) error {
6868

6969
if inst.Status == store.StatusRunning {
7070
return errors.New("cannot edit a running instance")
71+
} else if inst.Status == store.StatusSaved {
72+
return errors.New("cannot edit a saved instance")
7173
}
7274
filePath = filepath.Join(inst.Dir, filenames.LimaYAML)
7375
}

cmd/limactl/shell.go

+2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ func shellAction(cmd *cobra.Command, args []string) error {
7777
}
7878
if inst.Status == store.StatusStopped {
7979
return fmt.Errorf("instance %q is stopped, run `limactl start %s` to start the instance", instName, instName)
80+
} else if inst.Status == store.StatusSaved {
81+
return fmt.Errorf("instance %q is saved, run `limactl start %s` to restore the instance", instName, instName)
8082
}
8183

8284
// When workDir is explicitly set, the shell MUST have workDir as the cwd, or exit with an error.

cmd/limactl/start.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ func startAction(cmd *cobra.Command, args []string) error {
490490
inst.Name, instance.LimactlShellCmd(inst.Name))
491491
// Not an error
492492
return nil
493-
case store.StatusStopped:
493+
case store.StatusStopped, store.StatusSaved:
494494
// NOP
495495
default:
496496
logrus.Warnf("expected status %q, got %q", store.StatusStopped, inst.Status)

cmd/limactl/tunnel.go

+2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ func tunnelAction(cmd *cobra.Command, args []string) error {
7070
}
7171
if inst.Status == store.StatusStopped {
7272
return fmt.Errorf("instance %q is stopped, run `limactl start %s` to start the instance", instName, instName)
73+
} else if inst.Status == store.StatusSaved {
74+
return fmt.Errorf("instance %q is saved, run `limactl start %s` to restore the instance", instName, instName)
7375
}
7476

7577
if port == 0 {

pkg/instance/stop.go

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
)
1818

1919
func StopGracefully(inst *store.Instance) error {
20+
// TODO: support store.StatusSuspended
2021
if inst.Status != store.StatusRunning {
2122
return fmt.Errorf("expected status %q, got %q (maybe use `limactl stop -f`?)", store.StatusRunning, inst.Status)
2223
}

pkg/store/instance.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const (
3636
StatusBroken Status = "Broken"
3737
StatusStopped Status = "Stopped"
3838
StatusRunning Status = "Running"
39+
StatusSaved Status = "Saved"
3940
)
4041

4142
type Instance struct {
@@ -198,7 +199,15 @@ func inspectStatusWithPIDFiles(instDir string, inst *Instance, y *limayaml.LimaY
198199
case inst.HostAgentPID > 0 && inst.DriverPID > 0:
199200
inst.Status = StatusRunning
200201
case inst.HostAgentPID == 0 && inst.DriverPID == 0:
201-
inst.Status = StatusStopped
202+
_, err = os.Stat(filepath.Join(instDir, filenames.VzMachineState))
203+
if err == nil {
204+
inst.Status = StatusSaved
205+
} else if errors.Is(err, os.ErrNotExist) {
206+
inst.Status = StatusStopped
207+
} else {
208+
inst.Errors = append(inst.Errors, err)
209+
inst.Status = StatusBroken
210+
}
202211
case inst.HostAgentPID > 0 && inst.DriverPID == 0:
203212
inst.Errors = append(inst.Errors, errors.New("host agent is running but driver is not"))
204213
inst.Status = StatusBroken

0 commit comments

Comments
 (0)