Skip to content

Commit

Permalink
implement virt ExecResize (#217)
Browse files Browse the repository at this point in the history
  • Loading branch information
zc authored Jun 15, 2020
1 parent 1a86b3f commit d132f61
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions engine/virt/virt.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,19 @@ func (v *Virt) ExecAttach(ctx context.Context, execID string, tty bool) (io.Read
}

// Execute executes a command in vm
func (v *Virt) Execute(ctx context.Context, target string, config *enginetypes.ExecConfig) (_ string, outputStream io.ReadCloser, inputStream io.WriteCloser, err error) {
func (v *Virt) Execute(ctx context.Context, target string, config *enginetypes.ExecConfig) (execID string, outputStream io.ReadCloser, inputStream io.WriteCloser, err error) {
if config.Tty {
flags := virttypes.AttachGuestFlags{Safe: true, Force: true}
stream, err := v.client.AttachGuest(ctx, target, flags)
if err != nil {
return "", nil, nil, err
}
return "", ioutil.NopCloser(stream), stream, nil
return target, ioutil.NopCloser(stream), stream, nil

}

msg, err := v.client.ExecuteGuest(ctx, target, config.Cmd)
return "", ioutil.NopCloser(bytes.NewReader(msg.Data)), nil, err
return target, ioutil.NopCloser(bytes.NewReader(msg.Data)), nil, err

}

Expand All @@ -103,7 +103,10 @@ func (v *Virt) ExecExitCode(ctx context.Context, execID string) (code int, err e

// ExecResize resize exec tty
func (v *Virt) ExecResize(ctx context.Context, execID string, height, width uint) (err error) {
return nil
resizeCmd := fmt.Sprintf("/bin/stty -F /dev/ttyS0 rows %d cols %d", height, width)
msg, err := v.client.ExecuteGuest(ctx, execID, strings.Split(resizeCmd, " "))
log.Debugf("[ExecResize] resize got response: %v", msg)
return err
}

// NetworkConnect connects to a network.
Expand Down

0 comments on commit d132f61

Please sign in to comment.