本文整理匯總了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
//.........這裏部分代碼省略.........