本文整理汇总了Golang中github.com/cloudfoundry-incubator/garden.Container类的典型用法代码示例。如果您正苦于以下问题:Golang Container类的具体用法?Golang Container怎么用?Golang Container使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Container类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: checkHostAccess
func checkHostAccess(container garden.Container, permitted bool) {
info1, ierr := container.Info()
Expect(ierr).ToNot(HaveOccurred())
listener, err := net.Listen("tcp", fmt.Sprintf("%s:0", info1.HostIP))
Expect(err).ToNot(HaveOccurred())
defer listener.Close()
mux := http.NewServeMux()
mux.HandleFunc("/test", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello")
})
go (&http.Server{Handler: mux}).Serve(listener)
port, err := strconv.Atoi(strings.Split(listener.Addr().String(), ":")[1])
Expect(err).ToNot(HaveOccurred())
err = checkConnection(container, info1.HostIP, port)
if permitted {
Expect(err).ToNot(HaveOccurred())
} else {
Expect(err).To(HaveOccurred())
}
}
示例2: transitionToComplete
func (store *GardenStore) transitionToComplete(logger lager.Logger, gardenContainer garden.Container, result executor.ContainerRunResult) error {
resultJson, err := json.Marshal(result)
if err != nil {
return err
}
err = gardenContainer.SetProperty(ContainerResultProperty, string(resultJson))
if err != nil {
return err
}
err = gardenContainer.SetProperty(ContainerStateProperty, string(executor.StateCompleted))
if err != nil {
return err
}
executorContainer, err := store.exchanger.Info(logger, gardenContainer)
if err != nil {
return err
}
store.eventEmitter.Emit(executor.NewContainerCompleteEvent(executorContainer))
return nil
}
示例3: run
func (c *checker) run(logger lager.Logger, container garden.Container) (garden.Process, error) {
logger = logger.Session("run", lager.Data{
"processPath": c.healthcheckSpec.Path,
"processArgs": c.healthcheckSpec.Args,
"processUser": c.healthcheckSpec.User,
"processEnv": c.healthcheckSpec.Env,
"processDir": c.healthcheckSpec.Dir,
})
logger.Debug("starting")
defer logger.Debug("finished")
var proc garden.Process
err := retryOnFail(c.retryInterval, func(attempt uint) (runErr error) {
proc, runErr = container.Run(c.healthcheckSpec, garden.ProcessIO{})
if runErr != nil {
logger.Error("failed", runErr, lager.Data{"attempt": attempt})
return runErr
}
logger.Debug("succeeded", lager.Data{"attempt": attempt})
return nil
})
return proc, err
}
示例4: main
func main() {
flag.Parse()
gclient := client.New(connection.New("tcp", "localhost:7777"))
var container garden.Container
containers, err := gclient.Containers(garden.Properties{})
must(err)
for _, c := range containers {
if c.Handle() == *containerHandle {
container = c
break
}
}
if container == nil {
panic("Container not found!")
}
process, err := container.Attach(uint32(*processId), garden.ProcessIO{})
must(err)
switch *signalType {
case "term":
fmt.Println("Signalling term")
must(process.Signal(garden.SignalTerminate))
break
case "kill":
fmt.Println("Signalling kill")
must(process.Signal(garden.SignalKill))
break
}
}
示例5: 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())
}
示例6: runCommand
func runCommand(container garden.Container, path string, args []string) {
proc, err := container.Run(
garden.ProcessSpec{
Path: path,
Args: args,
},
ginkgoIO)
Expect(err).NotTo(HaveOccurred())
exitCode, err := proc.Wait()
Expect(err).NotTo(HaveOccurred())
Expect(exitCode).To(Equal(0))
}
示例7: ApplyLimits
func (b *LinuxBackend) ApplyLimits(container garden.Container, limits garden.Limits) error {
if limits.CPU != (garden.CPULimits{}) {
if err := container.LimitCPU(limits.CPU); err != nil {
return err
}
}
if limits.Disk != (garden.DiskLimits{}) {
if err := container.LimitDisk(limits.Disk); err != nil {
return err
}
}
if limits.Bandwidth != (garden.BandwidthLimits{}) {
if err := container.LimitBandwidth(limits.Bandwidth); err != nil {
return err
}
}
if limits.Memory != (garden.MemoryLimits{}) {
if err := container.LimitMemory(limits.Memory); err != nil {
return err
}
}
return nil
}
示例8: runInContainer
func runInContainer(container garden.Container, script string) (garden.Process, *gbytes.Buffer) {
out := gbytes.NewBuffer()
process, err := container.Run(garden.ProcessSpec{
User: "alice",
Path: "sh",
Args: []string{"-c", script},
}, garden.ProcessIO{
Stdout: io.MultiWriter(out, GinkgoWriter),
Stderr: GinkgoWriter,
})
Expect(err).ToNot(HaveOccurred())
return process, out
}
示例9: listenInContainer
func listenInContainer(container garden.Container, containerPort uint32) error {
_, err := container.Run(garden.ProcessSpec{
User: "alice",
Path: "sh",
Args: []string{"-c", fmt.Sprintf("echo %d | nc -l -p %d", containerPort, containerPort)},
}, garden.ProcessIO{
Stdout: GinkgoWriter,
Stderr: GinkgoWriter,
})
Expect(err).ToNot(HaveOccurred())
time.Sleep(2 * time.Second)
return err
}
示例10: transitionToRunning
func (store *GardenStore) transitionToRunning(logger lager.Logger, gardenContainer garden.Container) error {
err := gardenContainer.SetProperty(ContainerStateProperty, string(executor.StateRunning))
if err != nil {
return err
}
executorContainer, err := store.exchanger.Info(logger, gardenContainer)
if err != nil {
return err
}
store.eventEmitter.Emit(executor.NewContainerRunningEvent(executorContainer))
return nil
}
示例11: AssertMemoryLimits
func AssertMemoryLimits(container garden.Container) {
buf := make([]byte, 0, 1024*1024)
stdout := bytes.NewBuffer(buf)
process, err := container.Run(garden.ProcessSpec{
Path: "bin/consume.exe",
Args: []string{"memory", "128"},
}, garden.ProcessIO{Stdout: stdout})
Expect(err).ShouldNot(HaveOccurred())
exitCode, err := process.Wait()
Expect(err).ShouldNot(HaveOccurred())
// consume script will exit 42 if it is not killed
Expect(exitCode).ToNot(Equal(42), "process did not get OOM killed")
Expect(stdout.String()).To(ContainSubstring("Consumed: 3 mb"))
}
示例12: canCreateAndUseFuseFileSystem
func canCreateAndUseFuseFileSystem(container garden.Container, user string) {
mountpoint := "/tmp/fuse-test"
process, err := container.Run(garden.ProcessSpec{
User: user,
Path: "mkdir",
Args: []string{"-p", mountpoint},
}, garden.ProcessIO{Stdout: GinkgoWriter, Stderr: GinkgoWriter})
Expect(err).ToNot(HaveOccurred())
Expect(process.Wait()).To(Equal(0), "Could not make temporary directory!")
process, err = container.Run(garden.ProcessSpec{
User: user,
Path: "/usr/bin/hellofs",
Args: []string{mountpoint},
}, garden.ProcessIO{Stdout: GinkgoWriter, Stderr: GinkgoWriter})
Expect(err).ToNot(HaveOccurred())
Expect(process.Wait()).To(Equal(0), "Failed to mount hello filesystem.")
stdout := gbytes.NewBuffer()
process, err = container.Run(garden.ProcessSpec{
User: user,
Path: "cat",
Args: []string{filepath.Join(mountpoint, "hello")},
}, garden.ProcessIO{Stdout: stdout, Stderr: GinkgoWriter})
Expect(err).ToNot(HaveOccurred())
Expect(process.Wait()).To(Equal(0), "Failed to find hello file.")
Expect(stdout).To(gbytes.Say("Hello World!"))
process, err = container.Run(garden.ProcessSpec{
User: user,
Path: "fusermount",
Args: []string{"-u", mountpoint},
}, garden.ProcessIO{Stdout: GinkgoWriter, Stderr: GinkgoWriter})
Expect(err).ToNot(HaveOccurred())
Expect(process.Wait()).To(Equal(0), "Failed to unmount user filesystem.")
stdout2 := gbytes.NewBuffer()
process, err = container.Run(garden.ProcessSpec{
User: user,
Path: "ls",
Args: []string{mountpoint},
}, garden.ProcessIO{Stdout: stdout2, Stderr: GinkgoWriter})
Expect(err).ToNot(HaveOccurred())
Expect(process.Wait()).To(Equal(0))
Expect(stdout2).ToNot(gbytes.Say("hello"), "Fuse filesystem appears still to be visible after being unmounted.")
}
示例13: ensureBuildDirExists
func (step *taskStep) ensureBuildDirExists(container garden.Container) error {
emptyTar := new(bytes.Buffer)
err := tar.NewWriter(emptyTar).Close()
if err != nil {
return err
}
err = container.StreamIn(garden.StreamInSpec{
Path: step.artifactsRoot,
TarStream: emptyTar,
})
if err != nil {
return err
}
return nil
}
示例14: createContainerDir
func createContainerDir(container garden.Container, dir string) error {
emptyTar := new(bytes.Buffer)
err := tar.NewWriter(emptyTar).Close()
if err != nil {
return err
}
err = container.StreamIn(garden.StreamInSpec{
Path: dir,
TarStream: emptyTar,
})
if err != nil {
return err
}
return nil
}
示例15: ethInterfaceName
func ethInterfaceName(container garden.Container) string {
buffer := gbytes.NewBuffer()
proc, err := container.Run(
garden.ProcessSpec{
Path: "sh",
Args: []string{"-c", "ifconfig | grep 'Ethernet' | cut -f 1 -d ' '"},
User: "root",
},
garden.ProcessIO{
Stdout: buffer,
Stderr: GinkgoWriter,
},
)
Expect(err).NotTo(HaveOccurred())
Expect(proc.Wait()).To(Equal(0))
contIfaceName := string(buffer.Contents()) // w3-abc-1
return contIfaceName[:len(contIfaceName)-2] + "0" // w3-abc-0
}