本文整理汇总了Golang中github.com/cloudfoundry-incubator/garden.Container.Handle方法的典型用法代码示例。如果您正苦于以下问题:Golang Container.Handle方法的具体用法?Golang Container.Handle怎么用?Golang Container.Handle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cloudfoundry-incubator/garden.Container
的用法示例。
在下文中一共展示了Container.Handle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: reapContainer
func (s *GardenServer) reapContainer(container garden.Container) {
s.logger.Info("reaping", lager.Data{
"handle": container.Handle(),
"grace-time": s.backend.GraceTime(container).String(),
})
s.backend.Destroy(container.Handle())
}
示例2: Info
func (exchanger exchanger) Info(logger lager.Logger, gardenContainer garden.Container) (executor.Container, error) {
logger = logger.Session("info", lager.Data{"handle": gardenContainer.Handle()})
logger.Debug("getting-info")
info, err := gardenContainer.Info()
if err != nil {
logger.Error("failed-getting-info", err)
return executor.Container{}, err
}
logger.Debug("succeeded-getting-info")
return garden2executor(gardenContainer.Handle(), info)
}
示例3:
}, ","),
"-allowNetworks", allowedListenerIP+"/32",
)
// check that the IPs were preserved over restart
Expect(containerIP(blockedListener)).To(Equal(blockedListenerIP))
Expect(containerIP(unblockedListener)).To(Equal(unblockedListenerIP))
Expect(containerIP(allowedListener)).To(Equal(allowedListenerIP))
// create a container with the new deny network configuration
sender, err = client.Create(garden.ContainerSpec{})
Expect(err).ToNot(HaveOccurred())
})
AfterEach(func() {
err := client.Destroy(sender.Handle())
Expect(err).ToNot(HaveOccurred())
err = client.Destroy(blockedListener.Handle())
Expect(err).ToNot(HaveOccurred())
err = client.Destroy(unblockedListener.Handle())
Expect(err).ToNot(HaveOccurred())
err = client.Destroy(allowedListener.Handle())
Expect(err).ToNot(HaveOccurred())
})
runInContainer := func(container garden.Container, script string) garden.Process {
process, err := container.Run(garden.ProcessSpec{
User: "alice",
示例4:
}
process, err := os.FindProcess(pingProcess.Pid())
if err == nil {
process.Kill()
}
})
It("is not allowed", func() {
// TODO: make the executable name unique so to avoid test pollution
_, err := container.Run(garden.ProcessSpec{
Path: "bin/JobBreakoutTest.exe",
Args: []string{"ping 192.0.2.2 -n 1 -w 10000"},
}, garden.ProcessIO{})
Expect(err).ShouldNot(HaveOccurred())
err = client.Destroy(container.Handle())
Expect(err).ShouldNot(HaveOccurred())
processes, err := ps.Processes()
Expect(err).ShouldNot(HaveOccurred())
for _, proc := range processes {
fmt.Println(proc.Executable())
if proc.Executable() == "PING.EXE" {
pingProcess = proc
Expect(proc.Executable()).NotTo(Equal("PING.EXE"))
}
}
})
})
})
示例5:
}, garden.ProcessIO{
Stdout: byteCounter,
})
Expect(err).ToNot(HaveOccurred())
spawned <- true
}()
}
for j := 0; j < numToSpawn; j++ {
<-spawned
}
})
AfterEach(func() {
err := client.Destroy(container.Handle())
Expect(err).ToNot(HaveOccurred())
})
Measure("it should not adversely affect the rest of the API", func(b Benchmarker) {
var newContainer garden.Container
b.Time("creating another container", func() {
var err error
newContainer, err = client.Create(garden.ContainerSpec{})
Expect(err).ToNot(HaveOccurred())
})
for i := 0; i < repeats; i++ {
b.Time("getting container info ("+strconv.Itoa(repeats)+"x)", func() {
示例6:
)
BeforeEach(func() {
var err error
container, err = gdnr.Lookup("banana")
Expect(err).NotTo(HaveOccurred())
})
It("asks the netwoker to forward the correct ports", func() {
_, _, err := container.NetIn(externalPort, contianerPort)
Expect(err).NotTo(HaveOccurred())
Expect(networker.NetInCallCount()).To(Equal(1))
actualHandle, actualExtPort, actualContainerPort := networker.NetInArgsForCall(0)
Expect(actualHandle).To(Equal(container.Handle()))
Expect(actualExtPort).To(Equal(externalPort))
Expect(actualContainerPort).To(Equal(contianerPort))
})
Context("when networker returns an error", func() {
It("returns the error", func() {
networker.NetInReturns(uint32(0), uint32(0), fmt.Errorf("error"))
_, _, err := container.NetIn(externalPort, contianerPort)
Expect(err).To(MatchError("error"))
})
})
})
})
示例7:
var _ = Describe("Rootfs container create parameter", func() {
var container garden.Container
var args []string
BeforeEach(func() {
container = nil
args = []string{}
})
JustBeforeEach(func() {
client = startGarden(args...)
})
AfterEach(func() {
if container != nil {
Expect(client.Destroy(container.Handle())).To(Succeed())
}
})
// Temporarily pended until #102455044 is delivered to avoid slow tests
PDescribe("Garbage Collection", func() {
Context("when container is deleted", func() {
It("the graph path is emptied", func() {
container, err := client.Create(garden.ContainerSpec{RootFSPath: ""})
Expect(err).ToNot(HaveOccurred())
err = client.Destroy(container.Handle())
Expect(err).ToNot(HaveOccurred())
var size int
session, err := gexec.Start(exec.Command("sh", "-c", fmt.Sprintf(" du -d0 %s", client.GraphPath)), GinkgoWriter, GinkgoWriter)
示例8:
gardenParms = []string{}
})
JustBeforeEach(func() {
client = startGarden(gardenParms...)
var err error
container1, err = client.Create(garden.ContainerSpec{Network: containerNetwork1})
Expect(err).ToNot(HaveOccurred())
if len(containerNetwork2) > 0 {
container2, err = client.Create(garden.ContainerSpec{Network: containerNetwork2})
Expect(err).ToNot(HaveOccurred())
}
containerInterface = "w" + strconv.Itoa(GinkgoParallelNode()) + container1.Handle() + "-1"
})
AfterEach(func() {
if container1 != nil {
err := client.Destroy(container1.Handle())
Expect(err).ToNot(HaveOccurred())
}
if container2 != nil {
err := client.Destroy(container2.Handle())
Expect(err).ToNot(HaveOccurred())
}
})
Context("when the Network parameter is a subnet address", func() {
示例9:
var container garden.Container
BeforeEach(func() {
var err error
container, err = client.Create(garden.ContainerSpec{
Properties: garden.Properties{
"foo": "bar",
"a": "b",
},
})
Expect(err).ToNot(HaveOccurred())
})
AfterEach(func() {
client.Destroy(container.Handle())
})
Describe("info for one container", func() {
It("includes the properties", func() {
info, err := container.Info()
Expect(err).ToNot(HaveOccurred())
Expect(info.Properties["foo"]).To(Equal("bar"))
Expect(info.Properties["a"]).To(Equal("b"))
Expect(info.Properties).To(HaveLen(2))
})
})
Describe("getting container properties without getting info", func() {
示例10:
container = createContainer(gardenClient, garden.ContainerSpec{Privileged: false})
})
PIt("allows containers to be destroyed when wshd isn't running", func() {
info, _ := container.Info()
pidFile, err := os.Open(filepath.Join(info.ContainerPath, "run", "wshd.pid"))
Ω(err).ShouldNot(HaveOccurred())
var pid int
_, err = fmt.Fscanf(pidFile, "%d", &pid)
Ω(err).ShouldNot(HaveOccurred())
_, _, err = runCommand("sudo kill -9 " + strconv.Itoa(pid))
Ω(err).ShouldNot(HaveOccurred())
err = gardenClient.Destroy(container.Handle())
Ω(err).ShouldNot(HaveOccurred())
})
It("can send TERM and KILL signals to processes (#83231270)", func() {
buffer := gbytes.NewBuffer()
process, err := container.Run(garden.ProcessSpec{
User: "root",
Path: "sh",
Args: []string{"-c", `
trap 'echo "TERM received"' TERM
echo trapping
while true; do echo waiting; sleep 1; done
`},
}, recordedProcessIO(buffer))
Ω(err).ShouldNot(HaveOccurred())
示例11:
var _ = Describe("Creating a Container", func() {
var client *runner.RunningGarden
var container garden.Container
Context("after creating a container", func() {
BeforeEach(func() {
client = startGarden()
var err error
container, err = client.Create(garden.ContainerSpec{})
Expect(err).NotTo(HaveOccurred())
})
It("should create a depot subdirectory based on the container handle", func() {
Expect(container.Handle()).NotTo(BeEmpty())
Expect(filepath.Join(client.DepotDir, container.Handle())).To(BeADirectory())
Expect(filepath.Join(client.DepotDir, container.Handle(), "config.json")).To(BeARegularFile())
})
DescribeTable("placing the container in to all namespaces", func(ns string) {
pid := initProcessPID(container.Handle())
hostNS, err := gexec.Start(exec.Command("ls", "-l", fmt.Sprintf("/proc/1/ns/%s", ns)), GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
containerNS, err := gexec.Start(exec.Command("ls", "-l", fmt.Sprintf("/proc/%d/ns/%s", pid, ns)), GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
Eventually(containerNS).Should(gexec.Exit(0))
Eventually(hostNS).Should(gexec.Exit(0))
示例12:
client = startGarden()
})
AfterEach(func() {
Expect(client.DestroyAndStop()).To(Succeed())
})
Context("after creating a container without a specified handle", func() {
var initProcPid int
BeforeEach(func() {
var err error
container, err = client.Create(garden.ContainerSpec{})
Expect(err).NotTo(HaveOccurred())
initProcPid = initProcessPID(container.Handle())
})
It("should create a depot subdirectory based on the container handle", func() {
Expect(container.Handle()).NotTo(BeEmpty())
Expect(filepath.Join(client.DepotDir, container.Handle())).To(BeADirectory())
Expect(filepath.Join(client.DepotDir, container.Handle(), "config.json")).To(BeARegularFile())
})
It("should lookup the right container", func() {
lookupContainer, lookupError := client.Lookup(container.Handle())
Expect(lookupError).NotTo(HaveOccurred())
Expect(lookupContainer).To(Equal(container))
})
示例13:
gardenArgs = []string{}
privileged = false
})
JustBeforeEach(func() {
client = startGarden(gardenArgs...)
var err error
container, err = client.Create(garden.ContainerSpec{Privileged: privileged})
Expect(err).ToNot(HaveOccurred())
})
AfterEach(func() {
if container != nil {
err := client.Destroy(container.Handle())
Expect(err).ToNot(HaveOccurred())
}
})
It("retains the container list", func() {
restartGarden(gardenArgs...)
handles := getContainerHandles()
Expect(handles).To(ContainElement(container.Handle()))
})
It("allows us to run processes in the same container before and after restart", func() {
By("running a process before restart")
runEcho(container)
示例14:
"executor:owner": ownerName,
},
})
Expect(err).NotTo(HaveOccurred())
container2, err = gardenClient.Create(garden.ContainerSpec{
Properties: garden.Properties{
"executor:owner": ownerName,
},
})
Expect(err).NotTo(HaveOccurred())
})
It("deletes those containers (and only those containers)", func() {
Eventually(func() error {
_, err := gardenClient.Lookup(container1.Handle())
return err
}).Should(HaveOccurred())
Eventually(func() error {
_, err := gardenClient.Lookup(container2.Handle())
return err
}).Should(HaveOccurred())
})
})
})
Describe("when started", func() {
JustBeforeEach(func() {
process = ginkgomon.Invoke(runner)
})
示例15:
Expect(err).ToNot(HaveOccurred())
Expect(containerizer.RunCallCount()).To(Equal(1))
id, spec, io := containerizer.RunArgsForCall(0)
Expect(id).To(Equal("banana"))
Expect(spec).To(Equal(origSpec))
Expect(io).To(Equal(origIO))
})
Context("when the containerizer fails to run a process", func() {
BeforeEach(func() {
containerizer.RunReturns(nil, errors.New("lost my banana"))
})
It("returns the error", func() {
_, err := container.Run(garden.ProcessSpec{}, garden.ProcessIO{})
Expect(err).To(MatchError("lost my banana"))
})
})
})
Describe("destroying a container", func() {
It("asks the containerizer to destroy the container", func() {
Expect(gdnr.Destroy(container.Handle())).To(Succeed())
Expect(containerizer.DestroyCallCount()).To(Equal(1))
Expect(containerizer.DestroyArgsForCall(0)).To(Equal(container.Handle()))
})
})
})
})