From d132f61dac7625afb7be6b4d7eae5e8fbcf15eed Mon Sep 17 00:00:00 2001 From: zc Date: Tue, 16 Jun 2020 01:36:19 +0800 Subject: [PATCH] implement virt ExecResize (#217) --- engine/virt/virt.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/engine/virt/virt.go b/engine/virt/virt.go index f51b112ca..6c41c919a 100644 --- a/engine/virt/virt.go +++ b/engine/virt/virt.go @@ -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 } @@ -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.