本文整理汇总了Golang中github.com/docker/docker/pkg/stdcopy.NewStdWriter函数的典型用法代码示例。如果您正苦于以下问题:Golang NewStdWriter函数的具体用法?Golang NewStdWriter怎么用?Golang NewStdWriter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewStdWriter函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: postContainerExecStart
// TODO(vishh): Refactor the code to avoid having to specify stream config as part of both create and start.
func (s *containerRouter) postContainerExecStart(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
if err := httputils.ParseForm(r); err != nil {
return err
}
version := httputils.VersionFromContext(ctx)
if versions.GreaterThan(version, "1.21") {
if err := httputils.CheckForJSON(r); err != nil {
return err
}
}
var (
execName = vars["name"]
stdin, inStream io.ReadCloser
stdout, stderr, outStream io.Writer
)
execStartCheck := &types.ExecStartCheck{}
if err := json.NewDecoder(r.Body).Decode(execStartCheck); err != nil {
return err
}
if exists, err := s.backend.ExecExists(execName); !exists {
return err
}
if !execStartCheck.Detach {
var err error
// Setting up the streaming http interface.
inStream, outStream, err = httputils.HijackConnection(w)
if err != nil {
return err
}
defer httputils.CloseStreams(inStream, outStream)
if _, ok := r.Header["Upgrade"]; ok {
fmt.Fprintf(outStream, "HTTP/1.1 101 UPGRADED\r\nContent-Type: application/vnd.docker.raw-stream\r\nConnection: Upgrade\r\nUpgrade: tcp\r\n\r\n")
} else {
fmt.Fprintf(outStream, "HTTP/1.1 200 OK\r\nContent-Type: application/vnd.docker.raw-stream\r\n\r\n")
}
stdin = inStream
stdout = outStream
if !execStartCheck.Tty {
stderr = stdcopy.NewStdWriter(outStream, stdcopy.Stderr)
stdout = stdcopy.NewStdWriter(outStream, stdcopy.Stdout)
}
}
// Now run the user process in container.
if err := s.backend.ContainerExecStart(execName, stdin, stdout, stderr); err != nil {
if execStartCheck.Detach {
return err
}
stdout.Write([]byte(err.Error() + "\r\n"))
logrus.Errorf("Error running exec in container: %v", err)
}
return nil
}
开发者ID:RAMESHBABUK,项目名称:docker,代码行数:61,代码来源:exec.go
示例2: handleContainerLogs
func handleContainerLogs(w http.ResponseWriter, r *http.Request) {
var outStream, errStream io.Writer
outStream = ioutils.NewWriteFlusher(w)
// not sure how to test follow
if err := r.ParseForm(); err != nil {
http.Error(w, err.Error(), 500)
}
stdout, stderr := getBoolValue(r.Form.Get("stdout")), getBoolValue(r.Form.Get("stderr"))
if stderr {
errStream = stdcopy.NewStdWriter(outStream, stdcopy.Stderr)
}
if stdout {
outStream = stdcopy.NewStdWriter(outStream, stdcopy.Stdout)
}
var i int
if tail, err := strconv.Atoi(r.Form.Get("tail")); err == nil && tail > 0 {
i = 50 - tail
if i < 0 {
i = 0
}
}
for ; i < 50; i++ {
line := fmt.Sprintf("line %d", i)
if getBoolValue(r.Form.Get("timestamps")) {
l := &jsonlog.JSONLog{Log: line, Created: time.Now()}
line = fmt.Sprintf("%s %s", l.Created.Format(timeutils.RFC3339NanoFixed), line)
}
if i%2 == 0 && stderr {
fmt.Fprintln(errStream, line)
} else if i%2 == 1 && stdout {
fmt.Fprintln(outStream, line)
}
}
}
开发者ID:ChrisMcKenzie,项目名称:watchtower,代码行数:35,代码来源:engine_mock_test.go
示例3: ContainerAttachWithLogs
func (daemon *Daemon) ContainerAttachWithLogs(name string, c *ContainerAttachWithLogsConfig) error {
container, err := daemon.Get(name)
if err != nil {
return err
}
var errStream io.Writer
if !container.Config.Tty && c.Multiplex {
errStream = stdcopy.NewStdWriter(c.OutStream, stdcopy.Stderr)
c.OutStream = stdcopy.NewStdWriter(c.OutStream, stdcopy.Stdout)
} else {
errStream = c.OutStream
}
var stdin io.ReadCloser
var stdout, stderr io.Writer
if c.UseStdin {
stdin = c.InStream
}
if c.UseStdout {
stdout = c.OutStream
}
if c.UseStderr {
stderr = errStream
}
return container.AttachWithLogs(stdin, stdout, stderr, c.Logs, c.Stream)
}
开发者ID:colebrumley,项目名称:docker,代码行数:30,代码来源:attach.go
示例4: ContainerAttachWithLogs
func (daemon *Daemon) ContainerAttachWithLogs(container *Container, c *ContainerAttachWithLogsConfig) error {
var errStream io.Writer
if !container.Config.Tty {
errStream = stdcopy.NewStdWriter(c.OutStream, stdcopy.Stderr)
c.OutStream = stdcopy.NewStdWriter(c.OutStream, stdcopy.Stdout)
} else {
errStream = c.OutStream
}
var stdin io.ReadCloser
var stdout, stderr io.Writer
if c.UseStdin {
stdin = c.InStream
}
if c.UseStdout {
stdout = c.OutStream
}
if c.UseStderr {
stderr = errStream
}
return container.AttachWithLogs(stdin, stdout, stderr, c.Logs, c.Stream)
}
开发者ID:vito,项目名称:garden-linux-release,代码行数:25,代码来源:attach.go
示例5: attach
func (c *Container) attach(stdin io.ReadCloser, stdout io.WriteCloser, winsize *hypervisor.WindowSize, rsp chan<- error) error {
if c.p.sandbox == nil || c.descript == nil {
err := fmt.Errorf("container not ready for attach")
c.Log(ERROR, err)
return err
}
tty := &hypervisor.TtyIO{
Stdin: stdin,
Stdout: stdout,
Callback: make(chan *runvtypes.VmResponse, 1),
}
if stdout != nil {
if !c.hasTty() {
tty.Stderr = stdcopy.NewStdWriter(stdout, stdcopy.Stderr)
tty.Stdout = stdcopy.NewStdWriter(stdout, stdcopy.Stdout)
}
}
if rsp != nil {
go func() {
rsp <- tty.WaitForFinish()
}()
}
return c.p.sandbox.Attach(tty, c.Id(), winsize)
}
开发者ID:gnawux,项目名称:hyper,代码行数:28,代码来源:container.go
示例6: postContainerExecStart
// TODO(vishh): Refactor the code to avoid having to specify stream config as part of both create and start.
func postContainerExecStart(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
if err := parseForm(r); err != nil {
return nil
}
var (
name = vars["name"]
job = eng.Job("execStart", name)
errOut io.Writer = os.Stderr
)
if err := job.DecodeEnv(r.Body); err != nil {
return err
}
if !job.GetenvBool("Detach") {
// Setting up the streaming http interface.
inStream, outStream, err := hijackServer(w)
if err != nil {
return err
}
defer func() {
if tcpc, ok := inStream.(*net.TCPConn); ok {
tcpc.CloseWrite()
} else {
inStream.Close()
}
}()
defer func() {
if tcpc, ok := outStream.(*net.TCPConn); ok {
tcpc.CloseWrite()
} else if closer, ok := outStream.(io.Closer); ok {
closer.Close()
}
}()
var errStream io.Writer
fmt.Fprintf(outStream, "HTTP/1.1 200 OK\r\nContent-Type: application/vnd.docker.raw-stream\r\n\r\n")
if !job.GetenvBool("Tty") && version.GreaterThanOrEqualTo("1.6") {
errStream = stdcopy.NewStdWriter(outStream, stdcopy.Stderr)
outStream = stdcopy.NewStdWriter(outStream, stdcopy.Stdout)
} else {
errStream = outStream
}
job.Stdin.Add(inStream)
job.Stdout.Add(outStream)
job.Stderr.Set(errStream)
errOut = outStream
}
// Now run the user process in container.
job.SetCloseIO(false)
if err := job.Run(); err != nil {
fmt.Fprintf(errOut, "Error starting exec command in container %s: %s\n", name, err)
return err
}
w.WriteHeader(http.StatusNoContent)
return nil
}
开发者ID:hustcat,项目名称:docker-1.3,代码行数:60,代码来源:server.go
示例7: StartExec
func (p *XPod) StartExec(stdin io.ReadCloser, stdout io.WriteCloser, containerId, execId string) error {
p.statusLock.RLock()
es, ok := p.execs[execId]
p.statusLock.RUnlock()
if !ok {
err := fmt.Errorf("no exec %s exists for container %s", execId, containerId)
p.Log(ERROR, err)
return err
}
tty := &hypervisor.TtyIO{
Stdin: stdin,
Stdout: stdout,
Callback: make(chan *types.VmResponse, 1),
}
if !es.Terminal && stdout != nil {
tty.Stderr = stdcopy.NewStdWriter(stdout, stdcopy.Stderr)
tty.Stdout = stdcopy.NewStdWriter(stdout, stdcopy.Stdout)
}
var fin = true
for fin {
select {
case fin = <-es.finChan:
es.Log(DEBUG, "try to drain the sync chan")
default:
fin = false
es.Log(DEBUG, "the sync chan is empty")
}
}
go func(es *Exec) {
result := p.sandbox.WaitProcess(false, []string{execId}, -1)
if result == nil {
es.Log(ERROR, "can not wait exec")
return
}
r, ok := <-result
if !ok {
es.Log(ERROR, "waiting exec interrupted")
return
}
es.Log(DEBUG, "exec terminated at %v with code %d", r.FinishedAt, r.Code)
es.ExitCode = uint8(r.Code)
select {
case es.finChan <- true:
es.Log(DEBUG, "wake exec stopped chan")
default:
es.Log(WARNING, "exec already set as stopped")
}
}(es)
return p.sandbox.Exec(es.Container, es.Id, es.Cmds, es.Terminal, tty)
}
开发者ID:gnawux,项目名称:hyper,代码行数:58,代码来源:exec.go
示例8: postContainersAttach
func postContainersAttach(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
if err := parseForm(r); err != nil {
return err
}
if vars == nil {
return fmt.Errorf("Missing parameter")
}
d := getDaemon(eng)
cont, err := d.Get(vars["name"])
if err != nil {
return err
}
inStream, outStream, err := hijackServer(w)
if err != nil {
return err
}
defer closeStreams(inStream, outStream)
var errStream io.Writer
if _, ok := r.Header["Upgrade"]; ok {
fmt.Fprintf(outStream, "HTTP/1.1 101 UPGRADED\r\nContent-Type: application/vnd.docker.raw-stream\r\nConnection: Upgrade\r\nUpgrade: tcp\r\n\r\n")
} else {
fmt.Fprintf(outStream, "HTTP/1.1 200 OK\r\nContent-Type: application/vnd.docker.raw-stream\r\n\r\n")
}
if !cont.Config.Tty && version.GreaterThanOrEqualTo("1.6") {
errStream = stdcopy.NewStdWriter(outStream, stdcopy.Stderr)
outStream = stdcopy.NewStdWriter(outStream, stdcopy.Stdout)
} else {
errStream = outStream
}
logs := toBool(r.Form.Get("logs"))
stream := toBool(r.Form.Get("stream"))
var stdin io.ReadCloser
var stdout, stderr io.Writer
if toBool(r.Form.Get("stdin")) {
stdin = inStream
}
if toBool(r.Form.Get("stdout")) {
stdout = outStream
}
if toBool(r.Form.Get("stderr")) {
stderr = errStream
}
if err := cont.AttachWithLogs(stdin, stdout, stderr, logs, stream); err != nil {
fmt.Fprintf(outStream, "Error attaching: %s\n", err)
}
return nil
}
开发者ID:yingmsky,项目名称:docker,代码行数:56,代码来源:server.go
示例9: ContainerAttachWithLogs
// ContainerAttachWithLogs attaches to logs according to the config passed in. See ContainerAttachWithLogsConfig.
func (daemon *Daemon) ContainerAttachWithLogs(prefixOrName string, c *ContainerAttachWithLogsConfig) error {
if c.Hijacker == nil {
return derr.ErrorCodeNoHijackConnection.WithArgs(prefixOrName)
}
container, err := daemon.GetContainer(prefixOrName)
if err != nil {
return derr.ErrorCodeNoSuchContainer.WithArgs(prefixOrName)
}
if container.IsPaused() {
return derr.ErrorCodePausedContainer.WithArgs(prefixOrName)
}
conn, _, err := c.Hijacker.Hijack()
if err != nil {
return err
}
defer conn.Close()
// Flush the options to make sure the client sets the raw mode
conn.Write([]byte{})
inStream := conn.(io.ReadCloser)
outStream := conn.(io.Writer)
if c.Upgrade {
fmt.Fprintf(outStream, "HTTP/1.1 101 UPGRADED\r\nContent-Type: application/vnd.docker.raw-stream\r\nConnection: Upgrade\r\nUpgrade: tcp\r\n\r\n")
} else {
fmt.Fprintf(outStream, "HTTP/1.1 200 OK\r\nContent-Type: application/vnd.docker.raw-stream\r\n\r\n")
}
var errStream io.Writer
if !container.Config.Tty {
errStream = stdcopy.NewStdWriter(outStream, stdcopy.Stderr)
outStream = stdcopy.NewStdWriter(outStream, stdcopy.Stdout)
} else {
errStream = outStream
}
var stdin io.ReadCloser
var stdout, stderr io.Writer
if c.UseStdin {
stdin = inStream
}
if c.UseStdout {
stdout = outStream
}
if c.UseStderr {
stderr = errStream
}
if err := daemon.attachWithLogs(container, stdin, stdout, stderr, c.Logs, c.Stream, c.DetachKeys); err != nil {
fmt.Fprintf(outStream, "Error attaching: %s\n", err)
}
return nil
}
开发者ID:supasate,项目名称:docker,代码行数:56,代码来源:attach.go
示例10: postContainersAttach
func postContainersAttach(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
if err := parseForm(r); err != nil {
return err
}
if vars == nil {
return fmt.Errorf("Missing parameter")
}
var (
job = eng.Job("container_inspect", vars["name"])
c, err = job.Stdout.AddEnv()
)
if err != nil {
return err
}
if err = job.Run(); err != nil {
return err
}
inStream, outStream, err := hijackServer(w)
if err != nil {
return err
}
defer closeStreams(inStream, outStream)
var errStream io.Writer
if _, ok := r.Header["Upgrade"]; ok {
fmt.Fprintf(outStream, "HTTP/1.1 101 UPGRADED\r\nContent-Type: application/vnd.docker.raw-stream\r\nConnection: Upgrade\r\nUpgrade: tcp\r\n\r\n")
} else {
fmt.Fprintf(outStream, "HTTP/1.1 200 OK\r\nContent-Type: application/vnd.docker.raw-stream\r\n\r\n")
}
if c.GetSubEnv("Config") != nil && !c.GetSubEnv("Config").GetBool("Tty") && version.GreaterThanOrEqualTo("1.6") {
errStream = stdcopy.NewStdWriter(outStream, stdcopy.Stderr)
outStream = stdcopy.NewStdWriter(outStream, stdcopy.Stdout)
} else {
errStream = outStream
}
job = eng.Job("attach", vars["name"])
job.Setenv("logs", r.Form.Get("logs"))
job.Setenv("stream", r.Form.Get("stream"))
job.Setenv("stdin", r.Form.Get("stdin"))
job.Setenv("stdout", r.Form.Get("stdout"))
job.Setenv("stderr", r.Form.Get("stderr"))
job.Stdin.Add(inStream)
job.Stdout.Add(outStream)
job.Stderr.Set(errStream)
if err := job.Run(); err != nil {
fmt.Fprintf(outStream, "Error attaching: %s\n", err)
}
return nil
}
开发者ID:pombredanne,项目名称:docker,代码行数:55,代码来源:server.go
示例11: postContainerExecStart
// TODO(vishh): Refactor the code to avoid having to specify stream config as part of both create and start.
func (s *Server) postContainerExecStart(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
if err := parseForm(r); err != nil {
return nil
}
var (
execName = vars["name"]
stdin io.ReadCloser
stdout io.Writer
stderr io.Writer
)
execStartCheck := &types.ExecStartCheck{}
if err := json.NewDecoder(r.Body).Decode(execStartCheck); err != nil {
return err
}
if !execStartCheck.Detach {
// Setting up the streaming http interface.
inStream, outStream, err := hijackServer(w)
if err != nil {
return err
}
defer closeStreams(inStream, outStream)
var errStream io.Writer
if _, ok := r.Header["Upgrade"]; ok {
fmt.Fprintf(outStream, "HTTP/1.1 101 UPGRADED\r\nContent-Type: application/vnd.docker.raw-stream\r\nConnection: Upgrade\r\nUpgrade: tcp\r\n\r\n")
} else {
fmt.Fprintf(outStream, "HTTP/1.1 200 OK\r\nContent-Type: application/vnd.docker.raw-stream\r\n\r\n")
}
if !execStartCheck.Tty && version.GreaterThanOrEqualTo("1.6") {
errStream = stdcopy.NewStdWriter(outStream, stdcopy.Stderr)
outStream = stdcopy.NewStdWriter(outStream, stdcopy.Stdout)
} else {
errStream = outStream
}
stdin = inStream
stdout = outStream
stderr = errStream
}
// Now run the user process in container.
if err := s.daemon.ContainerExecStart(execName, stdin, stdout, stderr); err != nil {
logrus.Errorf("Error starting exec command in container %s: %s", execName, err)
return err
}
w.WriteHeader(http.StatusNoContent)
return nil
}
开发者ID:pbx0,项目名称:docker,代码行数:53,代码来源:server.go
示例12: StartExec
func (daemon *Daemon) StartExec(stdin io.ReadCloser, stdout io.WriteCloser, containerId, execId string) error {
tty := &hypervisor.TtyIO{
Stdin: stdin,
Stdout: stdout,
Callback: make(chan *types.VmResponse, 1),
}
glog.V(1).Infof("Get container id is %s", containerId)
pod, _, err := daemon.GetPodByContainerIdOrName(containerId)
if err != nil {
return err
}
status := pod.Status()
if status == nil || status.Status != types.S_POD_RUNNING {
return fmt.Errorf("container %s is not running", containerId)
}
es := status.GetExec(execId)
if es == nil {
return fmt.Errorf("Can not find exec %s", execId)
}
vmId, err := daemon.GetVmByPodId(pod.Id)
if err != nil {
return err
}
vm, ok := daemon.VmList.Get(vmId)
if !ok {
err = fmt.Errorf("Can not find VM whose Id is %s!", vmId)
return err
}
if !es.Terminal {
tty.Stderr = stdcopy.NewStdWriter(stdout, stdcopy.Stderr)
tty.Stdout = stdcopy.NewStdWriter(stdout, stdcopy.Stdout)
tty.OutCloser = stdout
}
if err := vm.Exec(es.Container, es.Id, es.Cmds, es.Terminal, tty); err != nil {
return err
}
defer func() {
glog.V(2).Info("Defer function for exec!")
}()
return nil
}
开发者ID:juito,项目名称:hyper,代码行数:50,代码来源:exec.go
示例13: postContainerExecStart
// TODO(vishh): Refactor the code to avoid having to specify stream config as part of both create and start.
func (s *Server) postContainerExecStart(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
if err := parseForm(r); err != nil {
return err
}
if err := checkForJSON(r); err != nil {
return err
}
var (
execName = vars["name"]
stdin, inStream io.ReadCloser
stdout, stderr, outStream io.Writer
)
execStartCheck := &types.ExecStartCheck{}
if err := json.NewDecoder(r.Body).Decode(execStartCheck); err != nil {
return err
}
if !execStartCheck.Detach {
var err error
// Setting up the streaming http interface.
inStream, outStream, err = hijackServer(w)
if err != nil {
return err
}
defer closeStreams(inStream, outStream)
if _, ok := r.Header["Upgrade"]; ok {
fmt.Fprintf(outStream, "HTTP/1.1 101 UPGRADED\r\nContent-Type: application/vnd.docker.raw-stream\r\nConnection: Upgrade\r\nUpgrade: tcp\r\n\r\n")
} else {
fmt.Fprintf(outStream, "HTTP/1.1 200 OK\r\nContent-Type: application/vnd.docker.raw-stream\r\n\r\n")
}
stdin = inStream
stdout = outStream
if !execStartCheck.Tty {
stderr = stdcopy.NewStdWriter(outStream, stdcopy.Stderr)
stdout = stdcopy.NewStdWriter(outStream, stdcopy.Stdout)
}
} else {
outStream = w
}
// Now run the user process in container.
if err := s.daemon.ContainerExecStart(execName, stdin, stdout, stderr); err != nil {
fmt.Fprintf(outStream, "Error running exec in container: %v\n", err)
}
return nil
}
开发者ID:matthewvalimaki,项目名称:docker,代码行数:50,代码来源:exec.go
示例14: ContainerAttach
// ContainerAttach attaches to logs according to the config passed in. See ContainerAttachConfig.
func (daemon *Daemon) ContainerAttach(prefixOrName string, c *backend.ContainerAttachConfig) error {
keys := []byte{}
var err error
if c.DetachKeys != "" {
keys, err = term.ToBytes(c.DetachKeys)
if err != nil {
return fmt.Errorf("Invalid escape keys (%s) provided", c.DetachKeys)
}
}
container, err := daemon.GetContainer(prefixOrName)
if err != nil {
return err
}
if container.IsPaused() {
err := fmt.Errorf("Container %s is paused. Unpause the container before attach", prefixOrName)
return errors.NewRequestConflictError(err)
}
inStream, outStream, errStream, err := c.GetStreams()
if err != nil {
return err
}
defer inStream.Close()
if !container.Config.Tty && c.MuxStreams {
errStream = stdcopy.NewStdWriter(errStream, stdcopy.Stderr)
outStream = stdcopy.NewStdWriter(outStream, stdcopy.Stdout)
}
var stdin io.ReadCloser
var stdout, stderr io.Writer
if c.UseStdin {
stdin = inStream
}
if c.UseStdout {
stdout = outStream
}
if c.UseStderr {
stderr = errStream
}
if err := daemon.containerAttach(container, stdin, stdout, stderr, c.Logs, c.Stream, keys); err != nil {
fmt.Fprintf(outStream, "Error attaching: %s\n", err)
}
return nil
}
开发者ID:SUSE,项目名称:docker.mirror,代码行数:49,代码来源:attach.go
示例15: ContainerLogs
// ContainerLogs hooks up a container's stdout and stderr streams
// configured with the given struct.
func (c *Container) ContainerLogs(name string, config *backend.ContainerLogsConfig, started chan struct{}) error {
defer trace.End(trace.Begin(""))
// Look up the container name in the metadata cache to get long ID
vc := cache.ContainerCache().GetContainer(name)
if vc == nil {
return NotFoundError(name)
}
name = vc.ContainerID
tailLines, since, err := c.validateContainerLogsConfig(vc, config)
if err != nil {
return err
}
// Outstream modification (from Docker's code) so the stream is streamed with the
// necessary headers that the CLI expects. This is Docker's scheme.
wf := ioutils.NewWriteFlusher(config.OutStream)
defer wf.Close()
wf.Flush()
outStream := io.Writer(wf)
if !vc.Config.Tty {
outStream = stdcopy.NewStdWriter(outStream, stdcopy.Stdout)
}
// Make a call to our proxy to handle the remoting
err = c.containerProxy.StreamContainerLogs(name, outStream, started, config.Timestamps, config.Follow, since, tailLines)
return err
}
开发者ID:vmware,项目名称:vic,代码行数:34,代码来源:container.go
示例16: getContainersLogs
func getContainersLogs(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
if err := parseForm(r); err != nil {
return err
}
if vars == nil {
return fmt.Errorf("Missing parameter")
}
var (
inspectJob = eng.Job("container_inspect", vars["name"])
logsJob = eng.Job("logs", vars["name"])
c, err = inspectJob.Stdout.AddEnv()
)
if err != nil {
return err
}
logsJob.Setenv("follow", r.Form.Get("follow"))
logsJob.Setenv("tail", r.Form.Get("tail"))
logsJob.Setenv("stdout", r.Form.Get("stdout"))
logsJob.Setenv("stderr", r.Form.Get("stderr"))
logsJob.Setenv("timestamps", r.Form.Get("timestamps"))
// Validate args here, because we can't return not StatusOK after job.Run() call
stdout, stderr := logsJob.GetenvBool("stdout"), logsJob.GetenvBool("stderr")
if !(stdout || stderr) {
return fmt.Errorf("Bad parameters: you must choose at least one stream")
}
if err = inspectJob.Run(); err != nil {
return err
}
var outStream, errStream io.Writer
outStream = utils.NewWriteFlusher(w)
if c.GetSubEnv("Config") != nil && !c.GetSubEnv("Config").GetBool("Tty") && version.GreaterThanOrEqualTo("1.6") {
errStream = stdcopy.NewStdWriter(outStream, stdcopy.Stderr)
outStream = stdcopy.NewStdWriter(outStream, stdcopy.Stdout)
} else {
errStream = outStream
}
logsJob.Stdout.Add(outStream)
logsJob.Stderr.Set(errStream)
if err := logsJob.Run(); err != nil {
fmt.Fprintf(outStream, "Error running logs job: %s\n", err)
}
return nil
}
开发者ID:pombredanne,项目名称:docker,代码行数:47,代码来源:server.go
示例17: Attach
func (daemon *Daemon) Attach(stdin io.ReadCloser, stdout io.WriteCloser, container string) error {
var (
vmId string
err error
)
tty := &hypervisor.TtyIO{
Stdin: stdin,
Stdout: stdout,
Callback: make(chan *types.VmResponse, 1),
}
pod, idx, err := daemon.GetPodByContainerIdOrName(container)
if err != nil {
return err
}
vmId, err = daemon.GetVmByPodId(pod.Id)
if err != nil {
return err
}
vm, ok := daemon.VmList.Get(vmId)
if !ok {
err = fmt.Errorf("Can find VM whose Id is %s!", vmId)
return err
}
if !pod.Spec.Containers[idx].Tty {
tty.Stderr = stdcopy.NewStdWriter(stdout, stdcopy.Stderr)
tty.Stdout = stdcopy.NewStdWriter(stdout, stdcopy.Stdout)
tty.OutCloser = stdout
}
err = vm.Attach(tty, container, nil)
if err != nil {
return err
}
defer func() {
glog.V(2).Info("Defer function for attach!")
}()
err = tty.WaitForFinish()
return err
}
开发者ID:juito,项目名称:hyper,代码行数:47,代码来源:attach.go
示例18: StartPod
func (daemon *Daemon) StartPod(stdin io.ReadCloser, stdout io.WriteCloser, podId, vmId string, attach bool) (int, string, error) {
var ttys []*hypervisor.TtyIO = []*hypervisor.TtyIO{}
glog.Infof("pod:%s, vm:%s", podId, vmId)
p, ok := daemon.PodList.Get(podId)
if !ok {
return -1, "", fmt.Errorf("The pod(%s) can not be found, please create it first", podId)
}
var lazy bool = hypervisor.HDriver.SupportLazyMode() && vmId == ""
if attach {
glog.V(1).Info("Run pod with tty attached")
tty := &hypervisor.TtyIO{
Stdin: stdin,
Stdout: stdout,
Callback: make(chan *types.VmResponse, 1),
}
if !p.Spec.Containers[0].Tty {
tty.Stderr = stdcopy.NewStdWriter(stdout, stdcopy.Stderr)
tty.Stdout = stdcopy.NewStdWriter(stdout, stdcopy.Stdout)
tty.OutCloser = stdout
}
ttys = append(ttys, tty)
}
code, cause, err := daemon.StartInternal(p, vmId, nil, lazy, ttys)
if err != nil {
glog.Error(err.Error())
return -1, "", err
}
if err := p.InitializeFinished(daemon); err != nil {
glog.Error(err.Error())
return -1, "", err
}
if len(ttys) > 0 {
ttys[0].WaitForFinish()
}
return code, cause, nil
}
开发者ID:juito,项目名称:hyper,代码行数:43,代码来源:run.go
示例19: ContainerAttach
// ContainerAttach attaches to logs according to the config passed in. See ContainerAttachConfig.
func (daemon *Daemon) ContainerAttach(prefixOrName string, c *backend.ContainerAttachConfig) error {
container, err := daemon.GetContainer(prefixOrName)
if err != nil {
return derr.ErrorCodeNoSuchContainer.WithArgs(prefixOrName)
}
if container.IsPaused() {
return derr.ErrorCodePausedContainer.WithArgs(prefixOrName)
}
inStream, outStream, errStream, err := c.GetStreams()
if err != nil {
return err
}
defer inStream.Close()
if !container.Config.Tty && c.MuxStreams {
errStream = stdcopy.NewStdWriter(errStream, stdcopy.Stderr)
outStream = stdcopy.NewStdWriter(outStream, stdcopy.Stdout)
}
var stdin io.ReadCloser
var stdout, stderr io.Writer
if c.UseStdin {
stdin = inStream
}
if c.UseStdout {
stdout = outStream
}
if c.UseStderr {
stderr = errStream
}
if err := daemon.containerAttach(container, stdin, stdout, stderr, c.Logs, c.Stream, c.DetachKeys); err != nil {
fmt.Fprintf(outStream, "Error attaching: %s\n", err)
}
return nil
}
开发者ID:gao-feng,项目名称:docker,代码行数:39,代码来源:attach.go
示例20: attachContainer
func (s *DockerServer) attachContainer(w http.ResponseWriter, r *http.Request) {
id := mux.Vars(r)["id"]
container, _, err := s.findContainer(id)
if err != nil {
http.Error(w, err.Error(), http.StatusNotFound)
return
}
hijacker, ok := w.(http.Hijacker)
if !ok {
http.Error(w, "cannot hijack connection", http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/vnd.docker.raw-stream")
w.WriteHeader(http.StatusOK)
conn, _, err := hijacker.Hijack()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
wg := sync.WaitGroup{}
if r.URL.Query().Get("stdin") == "1" {
wg.Add(1)
go func() {
ioutil.ReadAll(conn)
wg.Done()
}()
}
outStream := stdcopy.NewStdWriter(conn, stdcopy.Stdout)
if container.State.Running {
fmt.Fprintf(outStream, "Container is running\n")
} else {
fmt.Fprintf(outStream, "Container is not running\n")
}
fmt.Fprintln(outStream, "What happened?")
fmt.Fprintln(outStream, "Something happened")
wg.Wait()
if r.URL.Query().Get("stream") == "1" {
for {
time.Sleep(1e6)
s.cMut.RLock()
if !container.State.StartedAt.IsZero() && !container.State.Running {
s.cMut.RUnlock()
break
}
s.cMut.RUnlock()
}
}
conn.Close()
}
开发者ID:rawlingsj,项目名称:gofabric8,代码行数:49,代码来源:server.go
注:本文中的github.com/docker/docker/pkg/stdcopy.NewStdWriter函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论