本文整理匯總了Golang中github.com/cloudfoundry-incubator/executor.Container.Ports方法的典型用法代碼示例。如果您正苦於以下問題:Golang Container.Ports方法的具體用法?Golang Container.Ports怎麽用?Golang Container.Ports使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cloudfoundry-incubator/executor.Container
的用法示例。
在下文中一共展示了Container.Ports方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1:
Ports: []*models.PortMapping{
{
ContainerPort: 1234,
HostPort: 6789,
},
},
Address: "some-external-ip",
}
Expect(*lrpNetInfo).To(Equal(expectedNetInfo))
})
})
Context("when there are no exposed ports", func() {
BeforeEach(func() {
container.Ports = nil
})
It("does not return an error", func() {
Expect(netInfoConversionErr).NotTo(HaveOccurred())
})
})
Context("when the executor host is invalid", func() {
BeforeEach(func() {
container.ExternalIP = ""
})
It("returns an invalid host error", func() {
Expect(netInfoConversionErr.Error()).To(ContainSubstring("address"))
})
示例2:
})
Context("and the container is CREATED", func() {
BeforeEach(func() {
container.State = executor.StateCreated
})
itClaimsTheLRPOrDeletesTheContainer(sessionPrefix + "process-created-container")
})
Context("and the container is RUNNING", func() {
BeforeEach(func() {
expectedSessionName = sessionPrefix + "process-running-container"
container.State = executor.StateRunning
container.ExternalIP = "1.2.3.4"
container.Ports = []executor.PortMapping{{ContainerPort: 8080, HostPort: 61999}}
})
It("starts the lrp", func() {
Expect(bbsClient.StartActualLRPCallCount()).To(Equal(1))
lrpKey, instanceKey, netInfo := bbsClient.StartActualLRPArgsForCall(0)
Expect(*lrpKey).To(Equal(expectedLrpKey))
Expect(*instanceKey).To(Equal(expectedInstanceKey))
Expect(*netInfo).To(Equal(expectedNetInfo))
})
Context("when starting fails because ErrActualLRPCannotBeStarted", func() {
BeforeEach(func() {
bbsClient.StartActualLRPReturns(models.ErrActualLRPCannotBeStarted)
})
示例3: CreateInGarden
func (exchanger exchanger) CreateInGarden(logger lager.Logger, gardenClient GardenClient, executorContainer executor.Container) (executor.Container, error) {
logger = logger.Session("create-in-garden", lager.Data{"container-guid": executorContainer.Guid})
containerSpec := garden.ContainerSpec{
Handle: executorContainer.Guid,
Privileged: executorContainer.Privileged,
RootFSPath: executorContainer.RootFSPath,
}
if executorContainer.MemoryMB != 0 {
logger.Debug("setting-up-memory-limits")
containerSpec.Limits.Memory.LimitInBytes = uint64(executorContainer.MemoryMB * 1024 * 1024)
}
logger.Debug("setting-up-disk-limits")
gardenScope := garden.DiskLimitScopeExclusive
if executorContainer.DiskScope == executor.TotalDiskLimit {
gardenScope = garden.DiskLimitScopeTotal
}
containerSpec.Limits.Disk = garden.DiskLimits{
ByteHard: uint64(executorContainer.DiskMB * 1024 * 1024),
InodeHard: exchanger.containerInodeLimit,
Scope: gardenScope,
}
logger.Debug("setting-up-cpu-limits")
containerSpec.Limits.CPU.LimitInShares = uint64(float64(exchanger.containerMaxCPUShares) * float64(executorContainer.CPUWeight) / 100.0)
logJson, err := json.Marshal(executorContainer.LogConfig)
if err != nil {
logger.Error("failed-marshal-log", err)
return executor.Container{}, err
}
metricsConfigJson, err := json.Marshal(executorContainer.MetricsConfig)
if err != nil {
logger.Error("failed-marshal-metrics-config", err)
return executor.Container{}, err
}
resultJson, err := json.Marshal(executorContainer.RunResult)
if err != nil {
logger.Error("failed-marshal-run-result", err)
return executor.Container{}, err
}
containerSpec.Properties = garden.Properties{
ContainerOwnerProperty: exchanger.containerOwnerName,
ContainerStateProperty: string(executorContainer.State),
ContainerAllocatedAtProperty: fmt.Sprintf("%d", executorContainer.AllocatedAt),
ContainerStartTimeoutProperty: fmt.Sprintf("%d", executorContainer.StartTimeout),
ContainerRootfsProperty: executorContainer.RootFSPath,
ContainerLogProperty: string(logJson),
ContainerMetricsConfigProperty: string(metricsConfigJson),
ContainerResultProperty: string(resultJson),
ContainerMemoryMBProperty: fmt.Sprintf("%d", executorContainer.MemoryMB),
ContainerDiskMBProperty: fmt.Sprintf("%d", executorContainer.DiskMB),
ContainerCPUWeightProperty: fmt.Sprintf("%d", executorContainer.CPUWeight),
}
for name, value := range executorContainer.Tags {
containerSpec.Properties[TagPropertyPrefix+name] = value
}
for _, env := range executorContainer.Env {
containerSpec.Env = append(containerSpec.Env, env.Name+"="+env.Value)
}
for _, securityRule := range executorContainer.EgressRules {
if err := securityRule.Validate(); err != nil {
logger.Error("invalid-security-rule", err, lager.Data{"security_group_rule": securityRule})
return executor.Container{}, executor.ErrInvalidSecurityGroup
}
}
logger.Debug("creating-garden-container")
gardenContainer, err := gardenClient.Create(containerSpec)
if err != nil {
logger.Error("failed-creating-garden-container", err)
return executor.Container{}, err
}
logger.Debug("succeeded-creating-garden-container")
if executorContainer.Ports != nil {
actualPortMappings := make([]executor.PortMapping, len(executorContainer.Ports))
logger.Debug("setting-up-ports")
for i, ports := range executorContainer.Ports {
actualHostPort, actualContainerPort, err := gardenContainer.NetIn(uint32(ports.HostPort), uint32(ports.ContainerPort))
if err != nil {
logger.Error("failed-setting-up-ports", err)
exchanger.destroyContainer(logger, gardenClient, gardenContainer)
return executor.Container{}, err
}
actualPortMappings[i].ContainerPort = uint16(actualContainerPort)
actualPortMappings[i].HostPort = uint16(actualHostPort)
}
logger.Debug("succeeded-setting-up-ports")
executorContainer.Ports = actualPortMappings
//.........這裏部分代碼省略.........
示例4:
It("deletes the container", func() {
Expect(fakeContainerDelegate.DeleteContainerCallCount()).To(Equal(1))
_, actualContainerGuid := fakeContainerDelegate.DeleteContainerArgsForCall(0)
Expect(actualContainerGuid).To(Equal(container.Guid))
})
})
})
Context("when the container is Running", func() {
var lrpNetInfo models.ActualLRPNetInfo
BeforeEach(func() {
container.State = executor.StateRunning
externalIP := "executor-ip"
container.ExternalIP = externalIP
container.Ports = []executor.PortMapping{{ContainerPort: 1357, HostPort: 8642}}
lrpNetInfo = models.NewActualLRPNetInfo(externalIP, models.NewPortMapping(8642, 1357))
})
It("evacuates the lrp", func() {
Expect(fakeBBS.EvacuateRunningActualLRPCallCount()).To(Equal(1))
actualLRPKey, actualLRPContainerKey, actualLRPNetInfo, actualTTL := fakeBBS.EvacuateRunningActualLRPArgsForCall(0)
Expect(*actualLRPKey).To(Equal(lrpKey))
Expect(*actualLRPContainerKey).To(Equal(lrpInstanceKey))
Expect(*actualLRPNetInfo).To(Equal(lrpNetInfo))
Expect(actualTTL).To(Equal(uint64(evacuationTTL)))
})
Context("when the evacuation returns successfully", func() {
BeforeEach(func() {
fakeBBS.EvacuateRunningActualLRPReturns(true, nil)
示例5: 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)
//.........這裏部分代碼省略.........