Skip to content

Commit 6782cf8

Browse files
feat(frontend): Add per-instance start command with snapshot support
1 parent f4b3344 commit 6782cf8

3 files changed

Lines changed: 26 additions & 17 deletions

File tree

frontend/src/host_orchestrator/orchestrator/controller.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func (c *Controller) AddRoutes(router *mux.Router) {
8080
router.Handle("/cvds/{group}/{name}",
8181
httpHandler(newExecCVDGroupCommandHandler(c.Config, c.OperationManager, &removeCvdCommand{}))).Methods("DELETE")
8282
router.Handle("/cvds/{group}/{name}/:start",
83-
httpHandler(newStartCVDHandler(c.Config, c.OperationManager))).Methods("POST")
83+
httpHandler(newStartCVDInstanceHandler(c.Config, c.OperationManager))).Methods("POST")
8484
router.Handle("/cvds/{group}/{name}/:stop",
8585
httpHandler(newExecCVDInstanceCommandHandler(c.Config, c.OperationManager, &stopCvdInstanceCommand{}))).Methods("POST")
8686
router.Handle("/cvds/{group}/{name}/:powerwash",
@@ -502,31 +502,32 @@ func (h *displayScreenshotHandler) Handle(r *http.Request) (interface{}, error)
502502
return NewDisplayScreenshotAction(opts).Run()
503503
}
504504

505-
type startCVDHandler struct {
505+
type startCVDInstanceHandler struct {
506506
Config Config
507507
OM OperationManager
508508
}
509509

510-
func newStartCVDHandler(c Config, om OperationManager) *startCVDHandler {
511-
return &startCVDHandler{Config: c, OM: om}
510+
func newStartCVDInstanceHandler(c Config, om OperationManager) *startCVDInstanceHandler {
511+
return &startCVDInstanceHandler{Config: c, OM: om}
512512
}
513513

514-
func (h *startCVDHandler) Handle(r *http.Request) (interface{}, error) {
514+
func (h *startCVDInstanceHandler) Handle(r *http.Request) (interface{}, error) {
515515
req := &apiv1.StartCVDRequest{}
516516
err := json.NewDecoder(r.Body).Decode(req)
517517
if err != nil {
518518
return nil, operator.NewBadRequestError("Malformed JSON in request", err)
519519
}
520520
vars := mux.Vars(r)
521521
group := vars["group"]
522-
opts := StartCVDActionOpts{
522+
name := vars["name"]
523+
opts := StartCVDInstanceActionOpts{
523524
Request: req,
524-
Selector: cvd.GroupSelector{Name: group},
525+
Selector: cvd.InstanceSelector{GroupName: group, Name: name},
525526
Paths: h.Config.Paths,
526527
OperationManager: h.OM,
527528
ExecContext: exec.CommandContext,
528529
}
529-
return NewStartCVDAction(opts).Run()
530+
return NewStartCVDInstanceAction(opts).Run()
530531
}
531532

532533
type getCVDLogsHandler struct {

frontend/src/host_orchestrator/orchestrator/cvd/cvd.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,14 @@ func (i *Instance) Stop() error {
390390
return err
391391
}
392392

393+
func (i *Instance) Start(opts StartOptions) error {
394+
args := i.selectorArgs()
395+
args = append(args, "start", "--report_anonymous_usage_stats=y")
396+
args = append(args, opts.toArgs()...)
397+
_, err := i.cli.exec(CVDBin, args...)
398+
return err
399+
}
400+
393401
type DisplayAddOpts struct {
394402
Width int
395403
Height int

frontend/src/host_orchestrator/orchestrator/startcvdaction.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,24 @@ import (
2525
"github.com/google/android-cuttlefish/frontend/src/liboperator/operator"
2626
)
2727

28-
type StartCVDActionOpts struct {
28+
type StartCVDInstanceActionOpts struct {
2929
Request *apiv1.StartCVDRequest
30-
Selector cvd.GroupSelector
30+
Selector cvd.InstanceSelector
3131
Paths IMPaths
3232
OperationManager OperationManager
3333
ExecContext exec.ExecContext
3434
}
3535

36-
type StartCVDAction struct {
36+
type StartCVDInstanceAction struct {
3737
req *apiv1.StartCVDRequest
38-
selector cvd.GroupSelector
38+
selector cvd.InstanceSelector
3939
paths IMPaths
4040
om OperationManager
4141
cvdCLI *cvd.CLI
4242
}
4343

44-
func NewStartCVDAction(opts StartCVDActionOpts) *StartCVDAction {
45-
return &StartCVDAction{
44+
func NewStartCVDInstanceAction(opts StartCVDInstanceActionOpts) *StartCVDInstanceAction {
45+
return &StartCVDInstanceAction{
4646
req: opts.Request,
4747
selector: opts.Selector,
4848
paths: opts.Paths,
@@ -51,7 +51,7 @@ func NewStartCVDAction(opts StartCVDActionOpts) *StartCVDAction {
5151
}
5252
}
5353

54-
func (a *StartCVDAction) Run() (apiv1.Operation, error) {
54+
func (a *StartCVDInstanceAction) Run() (apiv1.Operation, error) {
5555
if err := ValidateStartCVDRequest(a.req); err != nil {
5656
return apiv1.Operation{}, err
5757
}
@@ -77,8 +77,8 @@ func (a *StartCVDAction) Run() (apiv1.Operation, error) {
7777
return op, nil
7878
}
7979

80-
func (a *StartCVDAction) exec(opts cvd.StartOptions) (*apiv1.EmptyResponse, error) {
81-
if err := a.cvdCLI.LazySelectGroup(a.selector).Start(opts); err != nil {
80+
func (a *StartCVDInstanceAction) exec(opts cvd.StartOptions) (*apiv1.EmptyResponse, error) {
81+
if err := a.cvdCLI.LazySelectInstance(a.selector).Start(opts); err != nil {
8282
return nil, operator.NewInternalError("cvd start failed", err)
8383
}
8484
return &apiv1.EmptyResponse{}, nil

0 commit comments

Comments
 (0)