Skip to content

Commit f5286f1

Browse files
committed
Convert hostagent api to use string not bool
Signed-off-by: Anders F Björklund <anders.f.bjorklund@gmail.com>
1 parent 22f212b commit f5286f1

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

pkg/hostagent/api/api.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ type Info struct {
44
SSHLocalPort int `json:"sshLocalPort,omitempty"`
55
}
66

7+
type RunState = string
8+
9+
const (
10+
StateRunning RunState = "running"
11+
StatePaused RunState = "paused"
12+
)
13+
714
type Status struct {
8-
Running bool `json:"running"`
9-
Paused bool `json:"paused"`
15+
State RunState `json:"state"`
1016
}

pkg/hostagent/hostagent.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,9 +470,15 @@ func (a *HostAgent) Status(ctx context.Context) (*hostagentapi.Status, error) {
470470
if err != nil {
471471
return nil, err
472472
}
473+
var state hostagentapi.RunState
474+
if driverStatus.Running {
475+
state = hostagentapi.StateRunning
476+
}
477+
if driverStatus.Paused {
478+
state = hostagentapi.StatePaused
479+
}
473480
status := &hostagentapi.Status{
474-
Running: driverStatus.Running,
475-
Paused: driverStatus.Paused,
481+
State: state,
476482
}
477483
return status, nil
478484
}

pkg/store/instance.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"time"
1818

1919
"github.com/docker/go-units"
20+
hostagentapi "github.com/lima-vm/lima/pkg/hostagent/api"
2021
hostagentclient "github.com/lima-vm/lima/pkg/hostagent/api/client"
2122
"github.com/lima-vm/lima/pkg/limayaml"
2223
"github.com/lima-vm/lima/pkg/store/dirnames"
@@ -201,10 +202,10 @@ func inspectStatusWithPIDFiles(instDir string, inst *Instance, y *limayaml.LimaY
201202
inst.Status = StatusBroken
202203
inst.Errors = append(inst.Errors, fmt.Errorf("failed to get Status from %q: %w", haSock, err))
203204
} else {
204-
if status.Paused {
205+
if status.State == hostagentapi.StatePaused {
205206
instStatus = StatusPaused
206207
}
207-
if status.Running {
208+
if status.State == hostagentapi.StateRunning {
208209
instStatus = StatusRunning
209210
}
210211
}

0 commit comments

Comments
 (0)