Skip to content

Commit 26b23d0

Browse files
committed
feat: add --wait-for-agent flag to exec command
By default, waits up to 30 seconds for the guest agent to become ready. This prevents immediate failures when the VM is still booting. Use --wait-for-agent=0 to fail immediately (old behavior). Depends on: onkernel/hypeman#50
1 parent 1a1d84b commit 26b23d0

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

pkg/cmd/exec.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ func (e *ExecExitError) Error() string {
3030

3131
// execRequest represents the JSON body for exec requests
3232
type execRequest struct {
33-
Command []string `json:"command"`
34-
TTY bool `json:"tty"`
35-
Env map[string]string `json:"env,omitempty"`
36-
Cwd string `json:"cwd,omitempty"`
37-
Timeout int32 `json:"timeout,omitempty"`
33+
Command []string `json:"command"`
34+
TTY bool `json:"tty"`
35+
Env map[string]string `json:"env,omitempty"`
36+
Cwd string `json:"cwd,omitempty"`
37+
Timeout int32 `json:"timeout,omitempty"`
38+
WaitForAgent int32 `json:"wait_for_agent,omitempty"`
3839
}
3940

4041
var execCmd = cli.Command{
@@ -65,6 +66,11 @@ var execCmd = cli.Command{
6566
Name: "timeout",
6667
Usage: "Execution timeout in seconds (0 = no timeout)",
6768
},
69+
&cli.IntFlag{
70+
Name: "wait-for-agent",
71+
Usage: "Seconds to wait for guest agent to be ready (0 = fail immediately)",
72+
Value: 30, // Default: wait up to 30 seconds for agent
73+
},
6874
},
6975
Action: handleExec,
7076
HideHelpCommand: true,
@@ -126,6 +132,7 @@ func handleExec(ctx context.Context, cmd *cli.Command) error {
126132
if timeout := cmd.Int("timeout"); timeout > 0 {
127133
execReq.Timeout = int32(timeout)
128134
}
135+
execReq.WaitForAgent = int32(cmd.Int("wait-for-agent"))
129136

130137
reqBody, err := json.Marshal(execReq)
131138
if err != nil {

0 commit comments

Comments
 (0)