コード例 #1
0
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
}
コード例 #2
0
ファイル: container_test.go プロジェクト: guanglinlv/garden
				fakeConnection.StreamOutReturns(nil, disaster)
			})

			It("returns the error", func() {
				_, err := container.StreamOut(garden.StreamOutSpec{
					Path: "from",
				})
				Ω(err).Should(Equal(disaster))
			})
		})
	})

	Describe("LimitBandwidth", func() {
		It("sends a limit bandwidth request", func() {
			err := container.LimitBandwidth(garden.BandwidthLimits{
				RateInBytesPerSecond: 1,
			})
			Ω(err).ShouldNot(HaveOccurred())

			handle, limits := fakeConnection.LimitBandwidthArgsForCall(0)
			Ω(handle).Should(Equal("some-handle"))
			Ω(limits).Should(Equal(garden.BandwidthLimits{RateInBytesPerSecond: 1}))
		})

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

			BeforeEach(func() {
				fakeConnection.LimitBandwidthReturns(garden.BandwidthLimits{}, disaster)
			})
コード例 #3
0
				It("returns an error", func() {
					_, err := container.StreamOut("/src/path")
					Ω(err).Should(HaveOccurred())
				})
			})
		})

		Describe("limiting bandwidth", func() {
			It("sets the container's bandwidth limits", func() {
				setLimits := garden.BandwidthLimits{
					RateInBytesPerSecond:      123,
					BurstRateInBytesPerSecond: 456,
				}

				err := container.LimitBandwidth(setLimits)
				Ω(err).ShouldNot(HaveOccurred())

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

			itResetsGraceTimeWhenHandling(func() {
				err := container.LimitBandwidth(garden.BandwidthLimits{
					RateInBytesPerSecond:      123,
					BurstRateInBytesPerSecond: 456,
				})
				Ω(err).ShouldNot(HaveOccurred())
			})

			itFailsWhenTheContainerIsNotFound(func() error {
				return container.LimitBandwidth(garden.BandwidthLimits{