本文整理汇总了Golang中github.com/cloudfoundry-incubator/garden.ContainerSpec.Handle方法的典型用法代码示例。如果您正苦于以下问题:Golang ContainerSpec.Handle方法的具体用法?Golang ContainerSpec.Handle怎么用?Golang ContainerSpec.Handle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cloudfoundry-incubator/garden.ContainerSpec
的用法示例。
在下文中一共展示了ContainerSpec.Handle方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Acquire
func (p *LinuxResourcePool) Acquire(spec garden.ContainerSpec) (linux_backend.LinuxContainerSpec, error) {
id := <-p.containerIDs
containerPath := path.Join(p.depotPath, id)
pLog := p.logger.Session(id)
pLog.Info("creating")
resources, err := p.acquirePoolResources(spec, id)
if err != nil {
return linux_backend.LinuxContainerSpec{}, err
}
defer cleanup(&err, func() {
p.releasePoolResources(resources)
})
pLog.Info("acquired-pool-resources")
handle := getHandle(spec.Handle, id)
var quota int64 = int64(spec.Limits.Disk.ByteHard)
if quota == 0 {
quota = math.MaxInt64
}
containerRootFSPath, rootFSEnv, err := p.acquireSystemResources(id, handle, containerPath, spec.RootFSPath, resources, spec.BindMounts, quota, pLog)
if err != nil {
return linux_backend.LinuxContainerSpec{}, err
}
pLog.Info("created")
specEnv, err := process.NewEnv(spec.Env)
if err != nil {
p.tryReleaseSystemResources(p.logger, id)
return linux_backend.LinuxContainerSpec{}, err
}
pLog.Debug("calculate-environment", lager.Data{
"rootfs-env": rootFSEnv,
})
spec.Env = rootFSEnv.Merge(specEnv).Array()
spec.Handle = handle
return linux_backend.LinuxContainerSpec{
ID: id,
ContainerPath: containerPath,
ContainerRootFSPath: containerRootFSPath,
Resources: resources,
Events: []string{},
Version: p.currentContainerVersion,
State: linux_backend.StateBorn,
ContainerSpec: spec,
}, nil
}
示例2: createContainer
func createContainer(containerSpec garden.ContainerSpec) garden.Container {
handle, err := uuid.NewV4()
Expect(err).ShouldNot(HaveOccurred())
containerSpec.Handle = handle.String()
container, err := client.Create(containerSpec)
Expect(err).ShouldNot(HaveOccurred())
err = StreamIn(container)
Expect(err).ShouldNot(HaveOccurred())
return container
}
示例3: Create
func (g *Gardener) Create(spec garden.ContainerSpec) (garden.Container, error) {
log := g.Logger.Session("create")
if spec.Handle == "" {
spec.Handle = g.UidGenerator.Generate()
}
networkPath, err := g.Networker.Network(log, spec.Handle, spec.Network)
if err != nil {
return nil, err
}
rootFSURL, err := url.Parse(spec.RootFSPath)
if err != nil {
g.Networker.Destroy(g.Logger, spec.Handle)
return nil, err
}
rootFSPath, _, err := g.VolumeCreator.Create(spec.Handle, rootfs_provider.Spec{RootFS: rootFSURL})
if err != nil {
g.Networker.Destroy(g.Logger, spec.Handle)
return nil, err
}
if err := g.Containerizer.Create(log, DesiredContainerSpec{
Handle: spec.Handle,
RootFSPath: rootFSPath,
NetworkPath: networkPath,
}); err != nil {
g.Networker.Destroy(g.Logger, spec.Handle)
return nil, err
}
container, err := g.Lookup(spec.Handle)
if err != nil {
return nil, err
}
for name, value := range spec.Properties {
err := container.SetProperty(name, value)
if err != nil {
return nil, err
}
}
return container, nil
}
示例4: Create
func (g *Gardener) Create(spec garden.ContainerSpec) (garden.Container, error) {
if spec.Handle == "" {
spec.Handle = g.UidGenerator.Generate()
}
networkPath, err := g.Networker.Network(spec.Network)
if err != nil {
return nil, err
}
if err := g.Containerizer.Create(DesiredContainerSpec{
Handle: spec.Handle,
NetworkPath: networkPath,
}); err != nil {
return nil, err
}
return g.Lookup(spec.Handle)
}
示例5: Create
func (backend *Backend) Create(spec garden.ContainerSpec) (garden.Container, error) {
backend.containersL.Lock()
defer backend.containersL.Unlock()
capacity, err := backend.Capacity()
if err != nil {
return nil, err
}
activeContainers := 0
for _, container := range backend.containers {
if _, ok := container.currentProperties()["concourse:exit-status"]; !ok {
activeContainers++
}
}
if activeContainers >= int(capacity.MaxContainers) {
return nil, atc.WorkerNotCreatedError{errors.New("worker already has the maximum number of active containers")}
}
id := backend.generateContainerID()
if spec.Handle == "" {
spec.Handle = id
}
dir := filepath.Join(backend.containersDir, id)
err = os.MkdirAll(dir, 0755)
if err != nil {
return nil, err
}
container := newContainer(spec, dir)
backend.containers[spec.Handle] = container
return container, nil
}
示例6: Acquire
func (p *LinuxResourcePool) Acquire(spec garden.ContainerSpec) (linux_backend.LinuxContainerSpec, error) {
id := <-p.containerIDs
containerPath := path.Join(p.depotPath, id)
handle := getHandle(spec.Handle, id)
pLog := p.logger.Session("acquire", lager.Data{"handle": handle})
iptablesCh := make(chan error, 1)
go func(iptablesCh chan error) {
pLog.Debug("setup-iptables-starting")
if err := p.filterProvider.ProvideFilter(id).Setup(handle); err != nil {
pLog.Error("setup-iptables-failed", err)
iptablesCh <- fmt.Errorf("resource_pool: set up filter: %v", err)
} else {
pLog.Debug("setup-iptables-ended")
iptablesCh <- nil
}
}(iptablesCh)
pLog.Info("creating")
resources, err := p.acquirePoolResources(spec, id, pLog)
if err != nil {
return linux_backend.LinuxContainerSpec{}, err
}
defer cleanup(&err, func() {
p.releasePoolResources(resources, pLog)
})
pLog.Info("acquired-pool-resources")
pLog.Info("running-graph-cleanup")
if err := p.rootFSProvider.GC(pLog); err != nil {
pLog.Error("graph-cleanup-failed", err)
}
containerRootFSPath, rootFSEnv, err := p.acquireSystemResources(
spec, id, resources, pLog,
)
if err != nil {
return linux_backend.LinuxContainerSpec{}, err
}
err = <-iptablesCh
if err != nil {
p.tryReleaseSystemResources(p.logger, id)
return linux_backend.LinuxContainerSpec{}, err
}
pLog.Info("created")
specEnv, err := process.NewEnv(spec.Env)
if err != nil {
p.tryReleaseSystemResources(p.logger, id)
return linux_backend.LinuxContainerSpec{}, err
}
spec.Env = rootFSEnv.Merge(specEnv).Array()
spec.Handle = handle
return linux_backend.LinuxContainerSpec{
ID: id,
ContainerPath: containerPath,
ContainerRootFSPath: containerRootFSPath,
Resources: resources,
Events: []string{},
Version: p.currentContainerVersion,
State: linux_backend.StateBorn,
ContainerSpec: spec,
}, nil
}
示例7:
JustBeforeEach(func() {
var err error
createdContainer, err = gdnr.Create(spec)
Expect(err).NotTo(HaveOccurred())
})
It("passes the rootfs provided by the volumizer to the containerizer", func() {
Expect(containerizer.CreateArgsForCall(0).RootFSPath).To(Equal("the-volumized-rootfs-path"))
})
PIt("destroys volumes when creating fails", func() {})
Context("when a handle is specified", func() {
BeforeEach(func() {
spec.Handle = "the-handle"
})
It("passes the handle to the containerizer", func() {
Expect(containerizer.CreateArgsForCall(0).Handle).To(Equal("the-handle"))
})
It("remembers the handle", func() {
Expect(createdContainer.Handle()).To(Equal("the-handle"))
})
PContext("and it is already in use", func() {})
})
Context("when a handle is not specified", func() {
PIt("assigns a handle", func() {