当前位置: 首页>>代码示例>>Golang>>正文


Golang Container.Attach方法代码示例

本文整理汇总了Golang中github.com/cloudfoundry-incubator/garden.Container.Attach方法的典型用法代码示例。如果您正苦于以下问题:Golang Container.Attach方法的具体用法?Golang Container.Attach怎么用?Golang Container.Attach使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/cloudfoundry-incubator/garden.Container的用法示例。


在下文中一共展示了Container.Attach方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: main

func main() {
	flag.Parse()

	gclient := client.New(connection.New("tcp", "localhost:7777"))

	var container garden.Container
	containers, err := gclient.Containers(garden.Properties{})
	must(err)
	for _, c := range containers {
		if c.Handle() == *containerHandle {
			container = c
			break
		}
	}
	if container == nil {
		panic("Container not found!")
	}

	process, err := container.Attach(uint32(*processId), garden.ProcessIO{})
	must(err)

	switch *signalType {
	case "term":
		fmt.Println("Signalling term")
		must(process.Signal(garden.SignalTerminate))
		break

	case "kill":
		fmt.Println("Signalling kill")
		must(process.Signal(garden.SignalKill))
		break
	}
}
开发者ID:glestaris,项目名称:garden-stuff,代码行数:33,代码来源:main.go

示例2:

			process, err := container.Run(garden.ProcessSpec{
				User: "alice",
				Path: "cat",
			}, garden.ProcessIO{})
			Expect(err).ToNot(HaveOccurred())

			processID = process.ID()
		})

		Measure("does not leak goroutines", func(b Benchmarker) {
			for i := 1; i <= iterations; i++ {
				stdoutR, stdoutW := io.Pipe()
				stdinR, stdinW := io.Pipe()

				_, err := container.Attach(processID, garden.ProcessIO{
					Stdin:  stdinR,
					Stdout: stdoutW,
				})
				Expect(err).ToNot(HaveOccurred())

				stdinData := fmt.Sprintf("hello %d", i)

				_, err = stdinW.Write([]byte(stdinData + "\n"))
				Expect(err).ToNot(HaveOccurred())

				var line []byte
				doneReading := make(chan struct{})
				go func() {
					line, _, err = bufio.NewReader(stdoutR).ReadLine()
					close(doneReading)
				}()
开发者ID:guanglinlv,项目名称:garden-linux,代码行数:31,代码来源:stream_measure_test.go

示例3:

					_, err = fmt.Fprintf(io.Stderr, "stderr data")
					Ω(err).ShouldNot(HaveOccurred())
				}()

				return process, nil
			}

			stdout := gbytes.NewBuffer()
			stderr := gbytes.NewBuffer()

			processIO := garden.ProcessIO{
				Stdout: stdout,
				Stderr: stderr,
			}

			process, err := container.Attach(42, processIO)
			Ω(err).ShouldNot(HaveOccurred())

			attachedHandle, attachedID, attachedIO := fakeConnection.AttachArgsForCall(0)
			Ω(attachedHandle).Should(Equal("some-handle"))
			Ω(attachedID).Should(Equal(uint32(42)))
			Ω(attachedIO).Should(Equal(processIO))

			Ω(process.ID()).Should(Equal(uint32(42)))

			status, err := process.Wait()
			Ω(err).ShouldNot(HaveOccurred())
			Ω(status).Should(Equal(123))

			Eventually(stdout).Should(gbytes.Say("stdout data"))
			Eventually(stderr).Should(gbytes.Say("stderr data"))
开发者ID:guanglinlv,项目名称:garden,代码行数:31,代码来源:container_test.go

示例4:

					_, err = fmt.Fprintf(io.Stderr, "stderr data")
					Ω(err).ShouldNot(HaveOccurred())
				}()

				return process, nil
			}

			stdout := gbytes.NewBuffer()
			stderr := gbytes.NewBuffer()

			processIO := garden.ProcessIO{
				Stdout: stdout,
				Stderr: stderr,
			}

			process, err := container.Attach("process-handle", processIO)
			Ω(err).ShouldNot(HaveOccurred())

			attachedHandle, attachedID, attachedIO := fakeConnection.AttachArgsForCall(0)
			Ω(attachedHandle).Should(Equal("some-handle"))
			Ω(attachedID).Should(Equal("process-handle"))
			Ω(attachedIO).Should(Equal(processIO))

			Ω(process.ID()).Should(Equal("process-handle"))

			status, err := process.Wait()
			Ω(err).ShouldNot(HaveOccurred())
			Ω(status).Should(Equal(123))

			Eventually(stdout).Should(gbytes.Say("stdout data"))
			Eventually(stderr).Should(gbytes.Say("stderr data"))
开发者ID:nagyistoce,项目名称:garden,代码行数:31,代码来源:container_test.go

示例5:

						return process, nil
					}
				})

				It("responds with a ProcessPayload for every chunk", func() {
					stdout := gbytes.NewBuffer()
					stderr := gbytes.NewBuffer()

					processIO := garden.ProcessIO{
						Stdin:  bytes.NewBufferString("stdin data"),
						Stdout: stdout,
						Stderr: stderr,
					}

					process, err := container.Attach(42, processIO)
					Ω(err).ShouldNot(HaveOccurred())

					pid, _ := fakeContainer.AttachArgsForCall(0)
					Ω(pid).Should(Equal(uint32(42)))

					Eventually(stdout).Should(gbytes.Say("stdout data"))
					Eventually(stdout).Should(gbytes.Say("mirrored stdin data"))
					Eventually(stderr).Should(gbytes.Say("stderr data"))

					status, err := process.Wait()
					Ω(err).ShouldNot(HaveOccurred())
					Ω(status).Should(Equal(123))
				})

				itResetsGraceTimeWhenHandling(func() {
开发者ID:julz,项目名称:garden-runc,代码行数:30,代码来源:request_handling_test.go

示例6:

		It("continues to stream", func() {
			process, err := container.Run(garden.ProcessSpec{
				User: "alice",
				Path: "sh",
				Args: []string{"-c", "while true; do echo hi; sleep 0.5; done"},
			}, garden.ProcessIO{})
			Expect(err).ToNot(HaveOccurred())

			restartGarden(gardenArgs...)

			_, err = process.Wait()
			Expect(err).To(HaveOccurred())

			stdout := gbytes.NewBuffer()
			_, err = container.Attach(process.ID(), garden.ProcessIO{
				Stdout: stdout,
			})
			Expect(err).ToNot(HaveOccurred())

			Eventually(stdout, 30.0).Should(gbytes.Say("hi\n"))
		})

		It("can still accept stdin", func() {
			r, w := io.Pipe()

			stdout := gbytes.NewBuffer()

			process, err := container.Run(garden.ProcessSpec{
				User: "alice",
				Path: "sh",
				Args: []string{"-c", "cat <&0"},
开发者ID:nagyistoce,项目名称:garden-linux,代码行数:31,代码来源:drain_test.go


注:本文中的github.com/cloudfoundry-incubator/garden.Container.Attach方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。