• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang garden.Container类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: checkHostAccess

func checkHostAccess(container garden.Container, permitted bool) {
	info1, ierr := container.Info()
	Expect(ierr).ToNot(HaveOccurred())

	listener, err := net.Listen("tcp", fmt.Sprintf("%s:0", info1.HostIP))
	Expect(err).ToNot(HaveOccurred())
	defer listener.Close()

	mux := http.NewServeMux()
	mux.HandleFunc("/test", func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprintf(w, "Hello")
	})

	go (&http.Server{Handler: mux}).Serve(listener)

	port, err := strconv.Atoi(strings.Split(listener.Addr().String(), ":")[1])
	Expect(err).ToNot(HaveOccurred())
	err = checkConnection(container, info1.HostIP, port)

	if permitted {
		Expect(err).ToNot(HaveOccurred())
	} else {
		Expect(err).To(HaveOccurred())
	}
}
开发者ID:guanglinlv,项目名称:garden-linux,代码行数:25,代码来源:ip_test.go


示例2: transitionToComplete

func (store *GardenStore) transitionToComplete(logger lager.Logger, gardenContainer garden.Container, result executor.ContainerRunResult) error {
	resultJson, err := json.Marshal(result)
	if err != nil {
		return err
	}

	err = gardenContainer.SetProperty(ContainerResultProperty, string(resultJson))
	if err != nil {
		return err
	}

	err = gardenContainer.SetProperty(ContainerStateProperty, string(executor.StateCompleted))
	if err != nil {
		return err
	}

	executorContainer, err := store.exchanger.Info(logger, gardenContainer)
	if err != nil {
		return err
	}

	store.eventEmitter.Emit(executor.NewContainerCompleteEvent(executorContainer))

	return nil
}
开发者ID:snowsnail,项目名称:executor,代码行数:25,代码来源:garden_store.go


示例3: run

func (c *checker) run(logger lager.Logger, container garden.Container) (garden.Process, error) {
	logger = logger.Session("run", lager.Data{
		"processPath": c.healthcheckSpec.Path,
		"processArgs": c.healthcheckSpec.Args,
		"processUser": c.healthcheckSpec.User,
		"processEnv":  c.healthcheckSpec.Env,
		"processDir":  c.healthcheckSpec.Dir,
	})
	logger.Debug("starting")
	defer logger.Debug("finished")

	var proc garden.Process
	err := retryOnFail(c.retryInterval, func(attempt uint) (runErr error) {
		proc, runErr = container.Run(c.healthcheckSpec, garden.ProcessIO{})
		if runErr != nil {
			logger.Error("failed", runErr, lager.Data{"attempt": attempt})
			return runErr
		}

		logger.Debug("succeeded", lager.Data{"attempt": attempt})
		return nil
	})

	return proc, err
}
开发者ID:snowsnail,项目名称:executor,代码行数:25,代码来源:checker.go


示例4: 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


示例5: reapContainer

func (s *GardenServer) reapContainer(container garden.Container) {
	s.logger.Info("reaping", lager.Data{
		"handle":     container.Handle(),
		"grace-time": s.backend.GraceTime(container).String(),
	})

	s.backend.Destroy(container.Handle())
}
开发者ID:emc-xchallenge,项目名称:garden,代码行数:8,代码来源:server.go


示例6: runCommand

func runCommand(container garden.Container, path string, args []string) {
	proc, err := container.Run(
		garden.ProcessSpec{
			Path: path,
			Args: args,
		},
		ginkgoIO)
	Expect(err).NotTo(HaveOccurred())

	exitCode, err := proc.Wait()
	Expect(err).NotTo(HaveOccurred())
	Expect(exitCode).To(Equal(0))
}
开发者ID:digideskio,项目名称:guardian,代码行数:13,代码来源:create_test.go


示例7: ApplyLimits

func (b *LinuxBackend) ApplyLimits(container garden.Container, limits garden.Limits) error {
	if limits.CPU != (garden.CPULimits{}) {
		if err := container.LimitCPU(limits.CPU); err != nil {
			return err
		}
	}

	if limits.Disk != (garden.DiskLimits{}) {
		if err := container.LimitDisk(limits.Disk); err != nil {
			return err
		}
	}

	if limits.Bandwidth != (garden.BandwidthLimits{}) {
		if err := container.LimitBandwidth(limits.Bandwidth); err != nil {
			return err
		}
	}

	if limits.Memory != (garden.MemoryLimits{}) {
		if err := container.LimitMemory(limits.Memory); err != nil {
			return err
		}
	}

	return nil
}
开发者ID:guanglinlv,项目名称:garden-linux,代码行数:27,代码来源:linux_backend.go


示例8: runInContainer

func runInContainer(container garden.Container, script string) (garden.Process, *gbytes.Buffer) {
	out := gbytes.NewBuffer()
	process, err := container.Run(garden.ProcessSpec{
		User: "alice",
		Path: "sh",
		Args: []string{"-c", script},
	}, garden.ProcessIO{
		Stdout: io.MultiWriter(out, GinkgoWriter),
		Stderr: GinkgoWriter,
	})
	Expect(err).ToNot(HaveOccurred())

	return process, out
}
开发者ID:nagyistoce,项目名称:garden-linux,代码行数:14,代码来源:drain_test.go


示例9: listenInContainer

func listenInContainer(container garden.Container, containerPort uint32) error {
	_, err := container.Run(garden.ProcessSpec{
		User: "alice",
		Path: "sh",
		Args: []string{"-c", fmt.Sprintf("echo %d | nc -l -p %d", containerPort, containerPort)},
	}, garden.ProcessIO{
		Stdout: GinkgoWriter,
		Stderr: GinkgoWriter,
	})
	Expect(err).ToNot(HaveOccurred())
	time.Sleep(2 * time.Second)

	return err
}
开发者ID:digideskio,项目名称:guardian,代码行数:14,代码来源:net_test.go


示例10: transitionToRunning

func (store *GardenStore) transitionToRunning(logger lager.Logger, gardenContainer garden.Container) error {
	err := gardenContainer.SetProperty(ContainerStateProperty, string(executor.StateRunning))
	if err != nil {
		return err
	}

	executorContainer, err := store.exchanger.Info(logger, gardenContainer)
	if err != nil {
		return err
	}

	store.eventEmitter.Emit(executor.NewContainerRunningEvent(executorContainer))

	return nil
}
开发者ID:snowsnail,项目名称:executor,代码行数:15,代码来源:garden_store.go


示例11: AssertMemoryLimits

func AssertMemoryLimits(container garden.Container) {
	buf := make([]byte, 0, 1024*1024)
	stdout := bytes.NewBuffer(buf)

	process, err := container.Run(garden.ProcessSpec{
		Path: "bin/consume.exe",
		Args: []string{"memory", "128"},
	}, garden.ProcessIO{Stdout: stdout})
	Expect(err).ShouldNot(HaveOccurred())

	exitCode, err := process.Wait()
	Expect(err).ShouldNot(HaveOccurred())
	// consume script will exit 42 if it is not killed
	Expect(exitCode).ToNot(Equal(42), "process did not get OOM killed")
	Expect(stdout.String()).To(ContainSubstring("Consumed:  3 mb"))
}
开发者ID:khassib,项目名称:garden-windows,代码行数:16,代码来源:limits_test.go


示例12: canCreateAndUseFuseFileSystem

func canCreateAndUseFuseFileSystem(container garden.Container, user string) {
	mountpoint := "/tmp/fuse-test"

	process, err := container.Run(garden.ProcessSpec{
		User: user,
		Path: "mkdir",
		Args: []string{"-p", mountpoint},
	}, garden.ProcessIO{Stdout: GinkgoWriter, Stderr: GinkgoWriter})
	Expect(err).ToNot(HaveOccurred())
	Expect(process.Wait()).To(Equal(0), "Could not make temporary directory!")

	process, err = container.Run(garden.ProcessSpec{
		User: user,
		Path: "/usr/bin/hellofs",
		Args: []string{mountpoint},
	}, garden.ProcessIO{Stdout: GinkgoWriter, Stderr: GinkgoWriter})
	Expect(err).ToNot(HaveOccurred())
	Expect(process.Wait()).To(Equal(0), "Failed to mount hello filesystem.")

	stdout := gbytes.NewBuffer()
	process, err = container.Run(garden.ProcessSpec{
		User: user,
		Path: "cat",
		Args: []string{filepath.Join(mountpoint, "hello")},
	}, garden.ProcessIO{Stdout: stdout, Stderr: GinkgoWriter})
	Expect(err).ToNot(HaveOccurred())
	Expect(process.Wait()).To(Equal(0), "Failed to find hello file.")
	Expect(stdout).To(gbytes.Say("Hello World!"))

	process, err = container.Run(garden.ProcessSpec{
		User: user,
		Path: "fusermount",
		Args: []string{"-u", mountpoint},
	}, garden.ProcessIO{Stdout: GinkgoWriter, Stderr: GinkgoWriter})
	Expect(err).ToNot(HaveOccurred())
	Expect(process.Wait()).To(Equal(0), "Failed to unmount user filesystem.")

	stdout2 := gbytes.NewBuffer()
	process, err = container.Run(garden.ProcessSpec{
		User: user,
		Path: "ls",
		Args: []string{mountpoint},
	}, garden.ProcessIO{Stdout: stdout2, Stderr: GinkgoWriter})
	Expect(err).ToNot(HaveOccurred())
	Expect(process.Wait()).To(Equal(0))
	Expect(stdout2).ToNot(gbytes.Say("hello"), "Fuse filesystem appears still to be visible after being unmounted.")
}
开发者ID:nagyistoce,项目名称:garden-linux,代码行数:47,代码来源:fuse_test.go


示例13: ensureBuildDirExists

func (step *taskStep) ensureBuildDirExists(container garden.Container) error {
	emptyTar := new(bytes.Buffer)

	err := tar.NewWriter(emptyTar).Close()
	if err != nil {
		return err
	}

	err = container.StreamIn(garden.StreamInSpec{
		Path:      step.artifactsRoot,
		TarStream: emptyTar,
	})
	if err != nil {
		return err
	}

	return nil
}
开发者ID:savaki,项目名称:atc,代码行数:18,代码来源:task_step.go


示例14: createContainerDir

func createContainerDir(container garden.Container, dir string) error {
	emptyTar := new(bytes.Buffer)

	err := tar.NewWriter(emptyTar).Close()
	if err != nil {
		return err
	}

	err = container.StreamIn(garden.StreamInSpec{
		Path:      dir,
		TarStream: emptyTar,
	})
	if err != nil {
		return err
	}

	return nil
}
开发者ID:xoebus,项目名称:checkin,代码行数:18,代码来源:task_step.go


示例15: ethInterfaceName

func ethInterfaceName(container garden.Container) string {
	buffer := gbytes.NewBuffer()
	proc, err := container.Run(
		garden.ProcessSpec{
			Path: "sh",
			Args: []string{"-c", "ifconfig | grep 'Ethernet' | cut -f 1 -d ' '"},
			User: "root",
		},
		garden.ProcessIO{
			Stdout: buffer,
			Stderr: GinkgoWriter,
		},
	)
	Expect(err).NotTo(HaveOccurred())
	Expect(proc.Wait()).To(Equal(0))

	contIfaceName := string(buffer.Contents()) // w3-abc-1

	return contIfaceName[:len(contIfaceName)-2] + "0" // w3-abc-0
}
开发者ID:digideskio,项目名称:guardian,代码行数:20,代码来源:destroy_test.go


示例16: checkConnection

func checkConnection(container garden.Container, ip string, port int) error {
	process, err := container.Run(garden.ProcessSpec{
		User: "alice",
		Path: "sh",
		Args: []string{"-c", fmt.Sprintf("echo hello | nc -w1 %s %d", ip, port)},
	}, garden.ProcessIO{Stdout: GinkgoWriter, Stderr: GinkgoWriter})
	if err != nil {
		return err
	}

	exitCode, err := process.Wait()
	if err != nil {
		return err
	}

	if exitCode == 0 {
		return nil
	} else {
		return fmt.Errorf("Request failed. Process exited with code %d", exitCode)
	}
}
开发者ID:digideskio,项目名称:guardian,代码行数:21,代码来源:net_test.go


示例17: createContainerTestFileIn

func createContainerTestFileIn(container garden.Container, dir string) string {
	fileName := "bind-mount-test-file"
	filePath := filepath.Join(dir, fileName)

	process, err := container.Run(garden.ProcessSpec{
		Path: "touch",
		Args: []string{filePath},
		User: "root",
	}, garden.ProcessIO{nil, os.Stdout, os.Stderr})
	Expect(err).ToNot(HaveOccurred())
	Expect(process.Wait()).To(Equal(0))

	process, err = container.Run(garden.ProcessSpec{
		Path: "chmod",
		Args: []string{"0777", filePath},
		User: "root",
	}, garden.ProcessIO{nil, os.Stdout, os.Stderr})
	Expect(err).ToNot(HaveOccurred())
	Expect(process.Wait()).To(Equal(0))

	return fileName
}
开发者ID:nagyistoce,项目名称:garden-linux,代码行数:22,代码来源:bind_mount_test.go


示例18: checkFileAccess

func checkFileAccess(container garden.Container, bindMountMode garden.BindMountMode, bindMountOrigin garden.BindMountOrigin, dstPath string, fileName string, privCtr, privReq bool) {
	readOnly := (garden.BindMountModeRO == bindMountMode)
	ctrOrigin := (garden.BindMountOriginContainer == bindMountOrigin)
	realRoot := (privReq && privCtr)

	// can we read a file?
	filePath := filepath.Join(dstPath, fileName)

	var user string
	if privReq {
		user = "root"
	} else {
		user = "alice"
	}

	process, err := container.Run(garden.ProcessSpec{
		Path: "cat",
		Args: []string{filePath},
		User: user,
	}, garden.ProcessIO{})
	Expect(err).ToNot(HaveOccurred())

	Expect(process.Wait()).To(Equal(0))

	// try to write a new file
	filePath = filepath.Join(dstPath, "checkFileAccess-file")

	process, err = container.Run(garden.ProcessSpec{
		Path: "touch",
		Args: []string{filePath},
		User: user,
	}, garden.ProcessIO{
		Stderr: GinkgoWriter,
		Stdout: GinkgoWriter,
	})
	Expect(err).ToNot(HaveOccurred())

	if readOnly || (!realRoot && !ctrOrigin) {
		Expect(process.Wait()).ToNot(Equal(0))
	} else {
		Expect(process.Wait()).To(Equal(0))
	}

	// try to delete an existing file
	filePath = filepath.Join(dstPath, fileName)

	process, err = container.Run(garden.ProcessSpec{
		Path: "rm",
		Args: []string{filePath},
		User: user,
	}, garden.ProcessIO{})
	Expect(err).ToNot(HaveOccurred())
	if readOnly || (!realRoot && !ctrOrigin) {
		Expect(process.Wait()).ToNot(Equal(0))
	} else {
		Expect(process.Wait()).To(Equal(0))
	}
}
开发者ID:nagyistoce,项目名称:garden-linux,代码行数:58,代码来源:bind_mount_test.go


示例19: Info

func (exchanger exchanger) Info(logger lager.Logger, gardenContainer garden.Container) (executor.Container, error) {
	logger = logger.Session("info", lager.Data{"handle": gardenContainer.Handle()})

	logger.Debug("getting-info")
	info, err := gardenContainer.Info()
	if err != nil {
		logger.Error("failed-getting-info", err)
		return executor.Container{}, err
	}
	logger.Debug("succeeded-getting-info")

	return garden2executor(gardenContainer.Handle(), info)
}
开发者ID:snowsnail,项目名称:executor,代码行数:13,代码来源:exchanger.go


示例20:

			Expect(err).ToNot(HaveOccurred())
			Expect(exitStatus).To(Equal(0))

			Expect(stdout).To(gbytes.Say(`lo:0`))

			cat := exec.Command("ifconfig")
			catSession, err := gexec.Start(cat, GinkgoWriter, GinkgoWriter)
			Expect(err).ToNot(HaveOccurred())
			Eventually(catSession).Should(gexec.Exit(0))
			Expect(catSession).ToNot(gbytes.Say("lo:0"))
		})
	})

	Describe("IPC namespace", func() {
		var sharedDir string
		var container garden.Container

		BeforeEach(func() {
			var err error
			sharedDir, err = ioutil.TempDir("", "shared-mount")
			Expect(err).ToNot(HaveOccurred())
			Expect(os.MkdirAll(sharedDir, 0755)).To(Succeed())
		})

		AfterEach(func() {
			if container != nil {
				Expect(client.Destroy(container.Handle())).To(Succeed())
			}
			if sharedDir != "" {
				Expect(os.RemoveAll(sharedDir)).To(Succeed())
			}
开发者ID:nagyistoce,项目名称:garden-linux,代码行数:31,代码来源:security_test.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang garden.ContainerSpec类代码示例发布时间:2022-05-23
下一篇:
Golang garden.Client类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap