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


Golang Container.LimitCPU方法代码示例

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


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

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

示例2:

					ghttp.CombineHandlers(
						ghttp.VerifyRequest("POST", "/api/containers/containerhandle/cpu_limit"),
						ghttp.RespondWith(200, `{}`),
						func(w http.ResponseWriter, req *http.Request) {
							body, err := ioutil.ReadAll(req.Body)
							req.Body.Close()
							Expect(err).ShouldNot(HaveOccurred())
							requestBody = string(body)
						},
					),
				)
			})

			It("sets limits on the container", func() {
				limit := garden.CPULimits{LimitInShares: uint64(50)}
				err := container.LimitCPU(limit)
				Expect(err).NotTo(HaveOccurred())

				Expect(server.ReceivedRequests()).Should(HaveLen(1))
				Expect(requestBody).Should(Equal(`{"limit_in_shares":50}`))
			})
		})

		Context("Containerizer returns non 200", func() {
			BeforeEach(func() {
				server.AppendHandlers(
					ghttp.CombineHandlers(
						ghttp.VerifyRequest("POST", "/api/containers/containerhandle/cpu_limit"),
						ghttp.RespondWith(500, "{}"),
					),
				)
开发者ID:stefanschneider,项目名称:garden-windows,代码行数:31,代码来源:container_test.go

示例3:

			BeforeEach(func() {
				fakeConnection.LimitBandwidthReturns(garden.BandwidthLimits{}, disaster)
			})

			It("returns the error", func() {
				err := container.LimitBandwidth(garden.BandwidthLimits{})
				Ω(err).Should(Equal(disaster))
			})
		})
	})

	Describe("LimitCPU", func() {
		It("sends a limit cpu request", func() {
			err := container.LimitCPU(garden.CPULimits{
				LimitInShares: 1,
			})
			Ω(err).ShouldNot(HaveOccurred())

			handle, limits := fakeConnection.LimitCPUArgsForCall(0)
			Ω(handle).Should(Equal("some-handle"))
			Ω(limits).Should(Equal(garden.CPULimits{LimitInShares: 1}))
		})

		Context("when the request fails", func() {
			disaster := errors.New("oh no!")

			BeforeEach(func() {
				fakeConnection.LimitCPUReturns(garden.CPULimits{}, disaster)
			})
开发者ID:guanglinlv,项目名称:garden,代码行数:29,代码来源:container_test.go

示例4:

				BeforeEach(func() {
					fakeContainer.CurrentDiskLimitsReturns(garden.DiskLimits{}, errors.New("oh no!"))
				})

				It("fails", func() {
					_, err := container.CurrentDiskLimits()
					Ω(err).Should(HaveOccurred())
				})
			})
		})

		Describe("set the cpu limit", func() {
			setLimits := garden.CPULimits{123}

			It("sets the container's CPU shares", func() {
				err := container.LimitCPU(setLimits)
				Ω(err).ShouldNot(HaveOccurred())

				Ω(fakeContainer.LimitCPUArgsForCall(0)).Should(Equal(setLimits))
			})

			itResetsGraceTimeWhenHandling(func() {
				err := container.LimitCPU(setLimits)
				Ω(err).ShouldNot(HaveOccurred())
			})

			itFailsWhenTheContainerIsNotFound(func() error {
				return container.LimitCPU(setLimits)
			})

			Context("when limiting the CPU fails", func() {
开发者ID:julz,项目名称:garden-runc,代码行数:31,代码来源:request_handling_test.go

示例5:

				BeforeEach(func() {
					fakeContainer.CurrentDiskLimitsReturns(garden.DiskLimits{}, errors.New("oh no!"))
				})

				It("fails", func() {
					_, err := container.CurrentDiskLimits()
					Ω(err).Should(HaveOccurred())
				})
			})
		})

		Describe("set the cpu limit", func() {
			setLimits := garden.CPULimits{123}

			It("sets the container's CPU shares", func() {
				err := container.LimitCPU(setLimits)
				Ω(err).ShouldNot(HaveOccurred())

				Ω(fakeContainer.LimitCPUArgsForCall(0)).Should(Equal(setLimits))
			})

			itResetsGraceTimeWhenHandling(func() {
				err := container.LimitCPU(setLimits)
				Ω(err).ShouldNot(HaveOccurred())
			})

			itFailsWhenTheContainerIsNotFound(func() {
				err := container.LimitCPU(setLimits)
				Ω(err).Should(HaveOccurred())
			})
开发者ID:vito,项目名称:gaol,代码行数:30,代码来源:request_handling_test.go


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