Skip to content

Commit d132f61

Browse files
author
zc
authored
implement virt ExecResize (#217)
1 parent 1a86b3f commit d132f61

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

engine/virt/virt.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,19 @@ func (v *Virt) ExecAttach(ctx context.Context, execID string, tty bool) (io.Read
8080
}
8181

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

9292
}
9393

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

9797
}
9898

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

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

109112
// NetworkConnect connects to a network.

0 commit comments

Comments
 (0)