Skip to content

Commit ef8f24e

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 08e762d commit ef8f24e

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
@@ -471,9 +471,15 @@ func (a *HostAgent) Status(ctx context.Context) (*hostagentapi.Status, error) {
471471
if err != nil {
472472
return nil, err
473473
}
474+
var state hostagentapi.RunState
475+
if driverStatus.Running {
476+
state = hostagentapi.StateRunning
477+
}
478+
if driverStatus.Paused {
479+
state = hostagentapi.StatePaused
480+
}
474481
status := &hostagentapi.Status{
475-
Running: driverStatus.Running,
476-
Paused: driverStatus.Paused,
482+
State: state,
477483
}
478484
return status, nil
479485
}

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"
@@ -209,10 +210,10 @@ func inspectStatusWithPIDFiles(instDir string, inst *Instance, y *limayaml.LimaY
209210
inst.Status = StatusBroken
210211
inst.Errors = append(inst.Errors, fmt.Errorf("failed to get Status from %q: %w", haSock, err))
211212
} else {
212-
if status.Paused {
213+
if status.State == hostagentapi.StatePaused {
213214
instStatus = StatusPaused
214215
}
215-
if status.Running {
216+
if status.State == hostagentapi.StateRunning {
216217
instStatus = StatusRunning
217218
}
218219
}

0 commit comments

Comments
 (0)