本文整理匯總了Golang中github.com/cloudfoundry-incubator/executor.Container.MemoryMB方法的典型用法代碼示例。如果您正苦於以下問題:Golang Container.MemoryMB方法的具體用法?Golang Container.MemoryMB怎麽用?Golang Container.MemoryMB使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cloudfoundry-incubator/executor.Container
的用法示例。
在下文中一共展示了Container.MemoryMB方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1:
Expect(err).NotTo(HaveOccurred())
Expect(containers).To(HaveLen(1))
Expect(containers[0].State).To(Equal(executor.StateReserved))
Expect(containers[0].Guid).To(Equal(guid))
Expect(containers[0].MemoryMB).To(Equal(0))
Expect(containers[0].DiskMB).To(Equal(0))
Expect(containers[0].Tags).To(Equal(executor.Tags{"some-tag": "some-value"}))
Expect(containers[0].State).To(Equal(executor.StateReserved))
Expect(containers[0].AllocatedAt).To(BeNumerically("~", time.Now().UnixNano(), time.Second))
})
Context("when allocated with memory and disk limits", func() {
BeforeEach(func() {
container.MemoryMB = 256
container.DiskMB = 256
})
It("returns the limits on the container", func() {
containers, err := executorClient.ListContainers(nil)
Expect(err).NotTo(HaveOccurred())
Expect(containers).To(HaveLen(1))
Expect(containers[0].MemoryMB).To(Equal(256))
Expect(containers[0].DiskMB).To(Equal(256))
})
It("reduces the capacity by the amount reserved", func() {
Expect(executorClient.RemainingResources()).To(Equal(executor.ExecutorResources{
MemoryMB: int(gardenCapacity.MemoryInBytes/1024/1024) - 256,
DiskMB: int(gardenCapacity.DiskInBytes/1024/1024) - 256,
示例2: garden2executor
func garden2executor(handle string, info garden.ContainerInfo) (executor.Container, error) {
executorContainer := executor.Container{
Guid: handle,
Tags: executor.Tags{},
ExternalIP: info.ExternalIP,
}
executorContainer.Ports = make([]executor.PortMapping, len(info.MappedPorts))
for key, value := range info.Properties {
switch key {
case ContainerStateProperty:
state := executor.State(value)
if state == executor.StateReserved ||
state == executor.StateInitializing ||
state == executor.StateCreated ||
state == executor.StateRunning ||
state == executor.StateCompleted {
executorContainer.State = state
} else {
return executor.Container{}, InvalidStateError{value}
}
case ContainerAllocatedAtProperty:
_, err := fmt.Sscanf(value, "%d", &executorContainer.AllocatedAt)
if err != nil {
return executor.Container{}, MalformedPropertyError{
Property: ContainerAllocatedAtProperty,
Value: value,
}
}
case ContainerRootfsProperty:
executorContainer.RootFSPath = value
case ContainerLogProperty:
err := json.Unmarshal([]byte(value), &executorContainer.LogConfig)
if err != nil {
return executor.Container{}, InvalidJSONError{
Property: key,
Value: value,
UnmarshalErr: err,
}
}
case ContainerMetricsConfigProperty:
err := json.Unmarshal([]byte(value), &executorContainer.MetricsConfig)
if err != nil {
return executor.Container{}, InvalidJSONError{
Property: key,
Value: value,
UnmarshalErr: err,
}
}
case ContainerResultProperty:
err := json.Unmarshal([]byte(value), &executorContainer.RunResult)
if err != nil {
return executor.Container{}, InvalidJSONError{
Property: key,
Value: value,
UnmarshalErr: err,
}
}
case ContainerMemoryMBProperty:
memoryMB, err := strconv.Atoi(value)
if err != nil {
return executor.Container{}, MalformedPropertyError{
Property: key,
Value: value,
}
}
executorContainer.MemoryMB = memoryMB
case ContainerDiskMBProperty:
diskMB, err := strconv.Atoi(value)
if err != nil {
return executor.Container{}, MalformedPropertyError{
Property: key,
Value: value,
}
}
executorContainer.DiskMB = diskMB
case ContainerCPUWeightProperty:
cpuWeight, err := strconv.Atoi(value)
if err != nil {
return executor.Container{}, MalformedPropertyError{
Property: key,
Value: value,
}
}
executorContainer.CPUWeight = uint(cpuWeight)
case ContainerStartTimeoutProperty:
startTimeout, err := strconv.Atoi(value)
if err != nil {
return executor.Container{}, MalformedPropertyError{
Property: key,
Value: value,
}
}
executorContainer.StartTimeout = uint(startTimeout)
//.........這裏部分代碼省略.........