本文整理汇总了Golang中github.com/lxc/lxd/shared.ContainerExecControl类的典型用法代码示例。如果您正苦于以下问题:Golang ContainerExecControl类的具体用法?Golang ContainerExecControl怎么用?Golang ContainerExecControl使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ContainerExecControl类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: sendTermSize
func sendTermSize(control *websocket.Conn) error {
width, height, err := terminal.GetSize(int(syscall.Stdout))
if err != nil {
return err
}
shared.Debugf("Window size is now: %dx%d", width, height)
w, err := control.NextWriter(websocket.TextMessage)
if err != nil {
return err
}
msg := shared.ContainerExecControl{}
msg.Command = "window-resize"
msg.Args = make(map[string]string)
msg.Args["width"] = strconv.Itoa(width)
msg.Args["height"] = strconv.Itoa(height)
buf, err := json.Marshal(msg)
if err != nil {
return err
}
_, err = w.Write(buf)
w.Close()
return err
}
示例2: forwardSignal
func (c *execCmd) forwardSignal(control *websocket.Conn, sig syscall.Signal) error {
shared.LogDebugf("Forwarding signal: %s", sig)
w, err := control.NextWriter(websocket.TextMessage)
if err != nil {
return err
}
msg := shared.ContainerExecControl{}
msg.Command = "signal"
msg.Signal = sig
buf, err := json.Marshal(msg)
if err != nil {
return err
}
_, err = w.Write(buf)
w.Close()
return err
}
示例3: Exec
func (c *Client) Exec(name string, cmd []string, env map[string]string, stdin *os.File, stdout *os.File, stderr *os.File) (int, error) {
interactive := terminal.IsTerminal(int(stdin.Fd()))
body := shared.Jmap{"command": cmd, "wait-for-websocket": true, "interactive": interactive, "environment": env}
resp, err := c.post(fmt.Sprintf("containers/%s/exec", name), body, Async)
if err != nil {
return -1, err
}
md := execMd{}
if err := json.Unmarshal(resp.Metadata, &md); err != nil {
return -1, err
}
if interactive {
if wsControl, ok := md.FDs["control"]; ok {
go func() {
control, err := c.websocket(resp.Operation, wsControl)
if err != nil {
return
}
for {
width, height, err := terminal.GetSize(syscall.Stdout)
if err != nil {
continue
}
shared.Debugf("Window size is now: %dx%d", width, height)
w, err := control.NextWriter(websocket.TextMessage)
if err != nil {
shared.Debugf("Got error getting next writer %s", err)
break
}
msg := shared.ContainerExecControl{}
msg.Command = "window-resize"
msg.Args = make(map[string]string)
msg.Args["width"] = strconv.Itoa(width)
msg.Args["height"] = strconv.Itoa(height)
buf, err := json.Marshal(msg)
if err != nil {
shared.Debugf("Failed to convert to json %s", err)
break
}
_, err = w.Write(buf)
w.Close()
if err != nil {
shared.Debugf("Got err writing %s", err)
break
}
ch := make(chan os.Signal)
signal.Notify(ch, syscall.SIGWINCH)
sig := <-ch
shared.Debugf("Received '%s signal', updating window geometry.", sig)
}
closeMsg := websocket.FormatCloseMessage(websocket.CloseNormalClosure, "")
control.WriteMessage(websocket.CloseMessage, closeMsg)
}()
}
conn, err := c.websocket(resp.Operation, md.FDs["0"])
if err != nil {
return -1, err
}
shared.WebsocketSendStream(conn, stdin)
<-shared.WebsocketRecvStream(stdout, conn)
} else {
sources := []*os.File{stdin, stdout, stderr}
conns := make([]*websocket.Conn, 3)
dones := make([]chan bool, 3)
for i := 0; i < 3; i++ {
conns[i], err = c.websocket(resp.Operation, md.FDs[strconv.Itoa(i)])
if err != nil {
return -1, err
}
if i == 0 {
dones[i] = shared.WebsocketSendStream(conns[i], sources[i])
} else {
dones[i] = shared.WebsocketRecvStream(sources[i], conns[i])
}
}
/*
* We'll get a read signal from each of stdout, stderr when they've
* both died. We need to wait for these in addition to the operation,
* because the server may indicate that the operation is done before we
* can actually read the last bits of data off these sockets and print
* it to the screen.
*
* We don't wait for stdin here, because if we're interactive, the user
* may not have closed it (e.g. if the command exits but the user
//.........这里部分代码省略.........