本文整理匯總了Golang中github.com/cloudfoundry-incubator/garden.ContainerSpec類的典型用法代碼示例。如果您正苦於以下問題:Golang ContainerSpec類的具體用法?Golang ContainerSpec怎麽用?Golang ContainerSpec使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了ContainerSpec類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: BuildTaskContainerSpec
func (factory *gardenContainerSpecFactory) BuildTaskContainerSpec(
spec TaskContainerSpec,
gardenSpec garden.ContainerSpec,
cancel <-chan os.Signal,
delegate ImageFetchingDelegate,
id Identifier,
metadata Metadata,
workerClient Client,
) (garden.ContainerSpec, error) {
if spec.ImageResourcePointer == nil {
gardenSpec.RootFSPath = spec.Image
}
gardenSpec.Privileged = spec.Privileged
var err error
gardenSpec, err = factory.createVolumes(gardenSpec, spec.Inputs)
if err != nil {
return gardenSpec, err
}
for _, mount := range spec.Outputs {
volume := mount.Volume
gardenSpec.BindMounts = append(gardenSpec.BindMounts, garden.BindMount{
SrcPath: volume.Path(),
DstPath: mount.MountPath,
Mode: garden.BindMountModeRW,
})
factory.volumeHandles = append(factory.volumeHandles, volume.Handle())
factory.volumeMounts[volume.Handle()] = mount.MountPath
}
return gardenSpec, nil
}
示例2: handleCreate
func (s *GardenServer) handleCreate(w http.ResponseWriter, r *http.Request) {
var spec garden.ContainerSpec
if !s.readRequest(&spec, w, r) {
return
}
hLog := s.logger.Session("create", lager.Data{
"request": spec,
})
if spec.GraceTime == 0 {
spec.GraceTime = s.containerGraceTime
}
hLog.Debug("creating")
container, err := s.backend.Create(spec)
if err != nil {
s.writeError(w, err, hLog)
return
}
hLog.Info("created")
s.bomberman.Strap(container)
s.writeResponse(w, &struct{ Handle string }{
Handle: container.Handle(),
})
}
示例3: 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
}
示例4: BuildResourceContainerSpec
func (factory *gardenContainerSpecFactory) BuildResourceContainerSpec(
spec ResourceTypeContainerSpec,
gardenSpec garden.ContainerSpec,
resourceTypes []atc.WorkerResourceType,
) (garden.ContainerSpec, error) {
if len(spec.Mounts) > 0 && spec.Cache.Volume != nil {
return gardenSpec, errors.New("a container may not have mounts and a cache")
}
gardenSpec.Privileged = true
gardenSpec.Env = append(gardenSpec.Env, spec.Env...)
if spec.Ephemeral {
gardenSpec.Properties[ephemeralPropertyName] = "true"
}
if spec.Cache.Volume != nil && spec.Cache.MountPath != "" {
gardenSpec.BindMounts = []garden.BindMount{
{
SrcPath: spec.Cache.Volume.Path(),
DstPath: spec.Cache.MountPath,
Mode: garden.BindMountModeRW,
},
}
factory.volumeHandles = append(factory.volumeHandles, spec.Cache.Volume.Handle())
factory.volumeMounts[spec.Cache.Volume.Handle()] = spec.Cache.MountPath
}
var err error
gardenSpec, err = factory.createVolumes(gardenSpec, spec.Mounts)
if err != nil {
return gardenSpec, err
}
if spec.ImageResourcePointer == nil {
for _, t := range resourceTypes {
if t.Type == spec.Type {
gardenSpec.RootFSPath = t.Image
return gardenSpec, nil
}
}
return gardenSpec, ErrUnsupportedResourceType
}
return gardenSpec, nil
}
示例5: createVolumes
func (factory *gardenContainerSpecFactory) createVolumes(containerSpec garden.ContainerSpec, mounts []VolumeMount) (garden.ContainerSpec, error) {
for _, mount := range mounts {
cowVolume, err := factory.baggageclaimClient.CreateVolume(factory.logger, baggageclaim.VolumeSpec{
Strategy: baggageclaim.COWStrategy{
Parent: mount.Volume,
},
Privileged: containerSpec.Privileged,
TTL: VolumeTTL,
})
if err != nil {
return containerSpec, err
}
factory.releaseAfterCreate = append(factory.releaseAfterCreate, cowVolume)
containerSpec.BindMounts = append(containerSpec.BindMounts, garden.BindMount{
SrcPath: cowVolume.Path(),
DstPath: mount.MountPath,
Mode: garden.BindMountModeRW,
})
factory.volumeHandles = append(factory.volumeHandles, cowVolume.Handle())
factory.volumeMounts[cowVolume.Handle()] = mount.MountPath
}
return containerSpec, nil
}
示例6: 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
}
示例7: handleCreate
func (s *GardenServer) handleCreate(w http.ResponseWriter, r *http.Request) {
var spec garden.ContainerSpec
if !s.readRequest(&spec, w, r) {
return
}
hLog := s.logger.Session("create", lager.Data{
"request": containerDebugInfo{
Handle: spec.Handle,
GraceTime: spec.GraceTime,
RootFSPath: spec.RootFSPath,
BindMounts: spec.BindMounts,
Network: spec.Network,
Privileged: spec.Privileged,
Limits: spec.Limits,
},
})
if spec.GraceTime == 0 {
spec.GraceTime = s.containerGraceTime
}
hLog.Debug("creating")
container, err := s.backend.Create(spec)
if err != nil {
s.writeError(w, err, hLog)
return
}
hLog.Info("created")
s.bomberman.Strap(container)
s.writeResponse(w, &struct{ Handle string }{
Handle: container.Handle(),
})
}
示例8: CreateContainer
func (worker *gardenWorker) CreateContainer(id Identifier, spec ContainerSpec) (Container, error) {
gardenSpec := garden.ContainerSpec{
Properties: id.gardenProperties(),
}
dance:
switch s := spec.(type) {
case ResourceTypeContainerSpec:
gardenSpec.Privileged = true
if s.Ephemeral {
gardenSpec.Properties[ephemeralPropertyName] = "true"
}
for _, t := range worker.resourceTypes {
if t.Type == s.Type {
gardenSpec.RootFSPath = t.Image
break dance
}
}
return nil, ErrUnsupportedResourceType
case TaskContainerSpec:
gardenSpec.RootFSPath = s.Image
gardenSpec.Privileged = s.Privileged
default:
return nil, fmt.Errorf("unknown container spec type: %T (%#v)", s, s)
}
gardenContainer, err := worker.gardenClient.Create(gardenSpec)
if err != nil {
return nil, err
}
return newGardenWorkerContainer(gardenContainer, worker.gardenClient, worker.clock), nil
}
示例9: 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
}
示例10: 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)
}
示例11: 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
}
示例12: 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
}
示例13: Create
func (c *RuncContainerCreator) Create(spec garden.ContainerSpec) (*Container, error) {
dir, err := c.Depot.Create()
if err != nil {
return nil, fmt.Errorf("create depot dir: %s", err)
}
if len(spec.RootFSPath) == 0 {
spec.RootFSPath = c.DefaultRootfs
}
rootfs, err := url.Parse(spec.RootFSPath)
if err != nil {
return nil, fmt.Errorf("create: not a valid rootfs path: %s", err)
}
if _, err := exec.Command("cp", "-r", rootfs.Path, path.Join(dir, "rootfs")).CombinedOutput(); err != nil {
return nil, fmt.Errorf("create: copy rootfs: %s", err)
}
runcSpec := runc.PortableSpec{
Version: "0.1",
OS: runtime.GOOS,
Arch: runtime.GOARCH,
Cpus: 1.1,
Memory: 1024,
Root: runc.Root{
Path: "rootfs",
Readonly: false,
},
Namespaces: []runc.Namespace{
{
Type: "process",
},
{
Type: "network",
},
{
Type: "mount",
},
{
Type: "ipc",
},
{
Type: "uts",
},
},
Devices: []string{
"null",
"random",
"full",
"tty",
"zero",
"urandom",
},
Mounts: []runc.Mount{
{
Type: "proc",
Source: "proc",
Destination: "/proc",
Options: "",
},
{
Type: "tmpfs",
Source: "tmpfs",
Destination: "/dev",
Options: "nosuid,strictatime,mode=755,size=65536k",
},
{
Type: "devpts",
Source: "devpts",
Destination: "/dev/pts",
Options: "nosuid,noexec,newinstance,ptmxmode=0666,mode=0620,gid=5",
},
{
Type: "tmpfs",
Source: "shm",
Destination: "/dev/shm",
Options: "nosuid,noexec,nodev,mode=1777,size=65536k",
},
{
Type: "mqueue",
Source: "mqueue",
Destination: "/dev/mqueue",
Options: "nosuid,noexec,nodev",
},
{
Type: "sysfs",
Source: "sysfs",
Destination: "/sys",
Options: "nosuid,noexec,nodev",
},
{
Type: "bind",
Source: c.InitdPath,
Destination: "/garden-bin/initd",
Options: "bind",
}, {
Type: "bind",
Source: path.Join(dir, "run"),
Destination: "/run/garden",
//.........這裏部分代碼省略.........
示例14:
volumizer.VolumizeReturns("the-volumized-rootfs-path", nil)
containerizer.CreateStub = func(spec gardener.DesiredContainerSpec) error {
return nil
}
gdnr = &gardener.Gardener{
Networker: networker,
Volumizer: volumizer,
Containerizer: containerizer,
}
})
Describe("creating a container", func() {
var (
createdContainer garden.Container
spec garden.ContainerSpec
)
BeforeEach(func() {
spec = garden.ContainerSpec{}
})
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"))
示例15:
package lifecycle_test
import (
"github.com/cloudfoundry-incubator/garden"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gbytes"
)
var _ = Describe("Logging", func() {
var container garden.Container
var containerSpec garden.ContainerSpec
BeforeEach(func() {
containerSpec = garden.ContainerSpec{}
})
JustBeforeEach(func() {
var err error
client = startGarden()
container, err = client.Create(containerSpec)
Expect(err).ToNot(HaveOccurred())
})
Context("when container is created", func() {
BeforeEach(func() {
containerSpec = garden.ContainerSpec{
Handle: "kumquat",
Env: []string{"PASSWORD=MY_SECRET"},
Properties: garden.Properties{