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

Golang garden.Client类代码示例

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

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



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

示例1: cleanupContainers

func cleanupContainers(client garden.Client) {
	containers, err := client.Containers(nil)
	if err != nil {
		panic(err)
	}

	for _, container := range containers {
		err = client.Destroy(container.Handle())
		if err != nil {
			panic(err)
		}
	}

	listContainers(client)
}
开发者ID:sykesm,项目名称:container-networking-release,代码行数:15,代码来源:main.go


示例2: listContainers

func listContainers(client garden.Client) {
	containers, err := client.Containers(nil)
	if err != nil {
		panic(err)
	}

	fmt.Printf("Current containers: \n")
	for _, c := range containers {
		fmt.Printf("\t%+v\n", c)
	}
}
开发者ID:sykesm,项目名称:container-networking-release,代码行数:11,代码来源:main.go


示例3: CleanupGarden

func CleanupGarden(gardenClient garden.Client) []error {
	containers, err := gardenClient.Containers(nil)
	Expect(err).NotTo(HaveOccurred())

	fmt.Fprintf(ginkgo.GinkgoWriter, "cleaning up %d Garden containers", len(containers))

	// even if containers fail to destroy, stop garden, but still report the
	// errors
	destroyContainerErrors := []error{}
	for _, container := range containers {
		info, _ := container.Info()

		fmt.Fprintf(ginkgo.GinkgoWriter, "cleaning up container %s (%s)", container.Handle(), info.ContainerPath)

	RETRY_LOOP:
		// try to Destroy the container up to 3 times
		for i := 0; i < 3; i++ {
			err := gardenClient.Destroy(container.Handle())
			switch {
			case err == nil:
				// move on if Destroy succeeds
				break RETRY_LOOP
			case strings.Contains(err.Error(), "unknown handle"):
				// move on if container doesn't exist
				break RETRY_LOOP
			case strings.Contains(err.Error(), "container already being destroyed"):
				// move on if container is already being destroyed
				break RETRY_LOOP
			case i == 2:
				// record an error if Destroy failed 3 times
				destroyContainerErrors = append(destroyContainerErrors, err)
			default:
				// try Destroy again otherwise
				time.Sleep(50 * time.Millisecond)
			}
		}
	}

	return destroyContainerErrors
}
开发者ID:Gerg,项目名称:inigo,代码行数:40,代码来源:cleanup_garden.go


示例4: createContainer

func createContainer(gardenClient garden.Client) (string, error) {
	container, err := gardenClient.Create(garden.ContainerSpec{})
	if err != nil {
		return "", err
	}

	processSpec := garden.ProcessSpec{
		Path: "sleep",
		Args: []string{"1000000"},
		User: "root",
	}
	processIO := garden.ProcessIO{}
	_, err = container.Run(processSpec, processIO)
	if err != nil {
		panic(err)
	}

	handle := container.Handle()
	fmt.Println(handle)

	return handle, nil
}
开发者ID:sykesm,项目名称:container-networking-release,代码行数:22,代码来源:main.go


示例5: Infos

func (exchanger exchanger) Infos(logger lager.Logger, gardenClient garden.Client, gardenContainers []garden.Container) ([]executor.Container, error) {
	handles := make([]string, 0, len(gardenContainers))
	for _, c := range gardenContainers {
		handles = append(handles, c.Handle())
	}
	logger = logger.Session("infos", lager.Data{"handles": handles})

	logger.Debug("get-bulk-info")
	infos, err := gardenClient.BulkInfo(handles)
	if err != nil {
		logger.Error("failed-bulk-info", err)
		return []executor.Container{}, err
	}
	logger.Debug("succeeded-bulk-info")

	var containerInfos []executor.Container

	for handle, info := range infos {
		if info.Err != nil {
			logger.Error("failed-garden-info", info.Err, lager.Data{
				"handle": handle,
			})
			continue
		}

		container, err := garden2executor(handle, info.Info)
		if err != nil {
			logger.Error("failed-garden2executor", err, lager.Data{
				"handle": handle,
			})
			continue
		}

		containerInfos = append(containerInfos, container)
	}

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


示例6: destroyContainers

func destroyContainers(gardenClient garden.Client, containersFetcher *executorContainers, logger lager.Logger) {
	logger.Info("executor-fetching-containers-to-destroy")
	containers, err := containersFetcher.Containers()
	if err != nil {
		logger.Fatal("executor-failed-to-get-containers", err)
		return
	} else {
		logger.Info("executor-fetched-containers-to-destroy", lager.Data{"num-containers": len(containers)})
	}

	for _, container := range containers {
		logger.Info("executor-destroying-container", lager.Data{"container-handle": container.Handle()})
		err := gardenClient.Destroy(container.Handle())
		if err != nil {
			logger.Fatal("executor-failed-to-destroy-container", err, lager.Data{
				"handle": container.Handle(),
			})
		} else {
			logger.Info("executor-destroyed-stray-container", lager.Data{
				"handle": container.Handle(),
			})
		}
	}
}
开发者ID:emc-xchallenge,项目名称:executor,代码行数:24,代码来源:initializer.go


示例7: createContainer

func createContainer(client garden.Client, spec garden.ContainerSpec) garden.Container {
	container, err := client.Create(spec)
	Ω(err).ShouldNot(HaveOccurred(), fmt.Sprintf("Error while creating container with spec: %+v", spec))
	return container
}
开发者ID:cloudfoundry-incubator,项目名称:garden-acceptance,代码行数:5,代码来源:garden_acceptance_suite_test.go


示例8:

	"github.com/cloudfoundry-incubator/garden/fakes"
	"github.com/cloudfoundry-incubator/garden/server"
)

var _ = Describe("When a client connects", func() {
	var socketPath string
	var tmpdir string

	var serverBackend *fakes.FakeBackend

	var serverContainerGraceTime time.Duration

	var logger *lagertest.TestLogger

	var apiServer *server.GardenServer
	var apiClient garden.Client
	var isRunning bool

	BeforeEach(func() {
		logger = lagertest.NewTestLogger("test")

		var err error
		tmpdir, err = ioutil.TempDir(os.TempDir(), "api-server-test")
		Ω(err).ShouldNot(HaveOccurred())

		socketPath = path.Join(tmpdir, "api.sock")
		serverBackend = new(fakes.FakeBackend)
		serverContainerGraceTime = 42 * time.Second

		apiServer = server.New(
			"unix",
开发者ID:julz,项目名称:garden-runc,代码行数:31,代码来源:request_handling_test.go


示例9:

				logger,
			)

			err = apiServer.Start()
			Ω(err).Should(HaveOccurred())
		})
	})

	Describe("shutting down", func() {
		var socketPath string

		var serverBackend garden.Backend
		var fakeBackend *fakes.FakeBackend

		var apiServer *server.GardenServer
		var apiClient garden.Client

		BeforeEach(func() {
			var err error
			tmpdir, err = ioutil.TempDir(os.TempDir(), "api-server-test")
			Ω(err).ShouldNot(HaveOccurred())

			socketPath = path.Join(tmpdir, "api.sock")
			fakeBackend = new(fakes.FakeBackend)

			serverBackend = fakeBackend

			apiClient = client.New(connection.New("unix", socketPath))
		})

		JustBeforeEach(func() {
开发者ID:nagyistoce,项目名称:garden,代码行数:31,代码来源:server_test.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang garden.Container类代码示例发布时间:2022-05-23
下一篇:
Golang fakes.FakeClient类代码示例发布时间: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