Skip to content

Commit

Permalink
Flaps: add machine exec
Browse files Browse the repository at this point in the history
  • Loading branch information
rugwirobaker committed Jan 15, 2023
1 parent 8a55d40 commit 9079f10
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
10 changes: 10 additions & 0 deletions api/machine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,13 @@ type MachineProcess struct {
UserOverride string `json:"user,omitempty"`
ExtraEnv map[string]string `json:"env"`
}

type MachineExecRequest struct {
Cmd []string `json:"cmd"`
}

type MachineExecResponse struct {
ExitCode int32 `json:"exit_code"`
StdOut *string `json:"stdout"`
StdErr *string `json:"stderr"`
}
12 changes: 12 additions & 0 deletions flaps/flaps.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,18 @@ func (f *Client) ReleaseLease(ctx context.Context, machineID, nonce string) erro
return f.sendRequest(ctx, http.MethodDelete, endpoint, nil, nil, headers)
}

func (f *Client) Exec(ctx context.Context, machineID string, in *api.MachineExecRequest) (*api.MachineExecResponse, error) {
endpoint := fmt.Sprintf("/%s/exec", machineID)

out := new(api.MachineExecResponse)

err := f.sendRequest(ctx, http.MethodPost, endpoint, in, out, nil)
if err != nil {
return nil, fmt.Errorf("failed to exec on VM %s: %w", machineID, err)
}
return out, nil
}

func (f *Client) sendRequest(ctx context.Context, method, endpoint string, in, out interface{}, headers map[string][]string) error {
req, err := f.NewRequest(ctx, method, endpoint, in, headers)
if err != nil {
Expand Down

0 comments on commit 9079f10

Please sign in to comment.