當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Client.Containers方法代碼示例

本文整理匯總了Golang中github.com/cloudfoundry-incubator/garden.Client.Containers方法的典型用法代碼示例。如果您正苦於以下問題:Golang Client.Containers方法的具體用法?Golang Client.Containers怎麽用?Golang Client.Containers使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/cloudfoundry-incubator/garden.Client的用法示例。


在下文中一共展示了Client.Containers方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

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

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

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

示例4:

	Context("and the client sends a ListRequest", func() {
		BeforeEach(func() {
			c1 := new(fakes.FakeContainer)
			c1.HandleReturns("some-handle")

			c2 := new(fakes.FakeContainer)
			c2.HandleReturns("another-handle")

			c3 := new(fakes.FakeContainer)
			c3.HandleReturns("super-handle")

			serverBackend.ContainersReturns([]garden.Container{c1, c2, c3}, nil)
		})

		It("returns the containers from the backend", func() {
			containers, err := apiClient.Containers(nil)
			Ω(err).ShouldNot(HaveOccurred())

			Ω(containers).Should(HaveLen(3))

			handles := make([]string, 3)
			for i, c := range containers {
				handles[i] = c.Handle()
			}

			Ω(handles).Should(ContainElement("some-handle"))
			Ω(handles).Should(ContainElement("another-handle"))
			Ω(handles).Should(ContainElement("super-handle"))
		})

		Context("when getting the containers fails", func() {
開發者ID:julz,項目名稱:garden-runc,代碼行數:31,代碼來源:request_handling_test.go


注:本文中的github.com/cloudfoundry-incubator/garden.Client.Containers方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。