gitee.com/leisunstar/runtime@v0.0.0-20200521203717-5cef3e7b53f9/virtcontainers/example_pod_run_test.go (about) 1 // Copyright (c) 2016 Intel Corporation 2 // 3 // SPDX-License-Identifier: Apache-2.0 4 // 5 6 package virtcontainers_test 7 8 import ( 9 "context" 10 "fmt" 11 "strings" 12 13 vc "github.com/kata-containers/runtime/virtcontainers" 14 "github.com/kata-containers/runtime/virtcontainers/types" 15 ) 16 17 var containerRootfs = vc.RootFs{Target: "/var/lib/container/bundle/", Mounted: true} 18 19 // This example creates and starts a single container sandbox, 20 // using qemu as the hypervisor and kata as the VM agent. 21 func Example_createAndStartSandbox() { 22 envs := []types.EnvVar{ 23 { 24 Var: "PATH", 25 Value: "/bin:/usr/bin:/sbin:/usr/sbin", 26 }, 27 } 28 29 cmd := types.Cmd{ 30 Args: strings.Split("/bin/sh", " "), 31 Envs: envs, 32 WorkDir: "/", 33 } 34 35 // Define the container command and bundle. 36 container := vc.ContainerConfig{ 37 ID: "1", 38 RootFs: containerRootfs, 39 Cmd: cmd, 40 } 41 42 // Sets the hypervisor configuration. 43 hypervisorConfig := vc.HypervisorConfig{ 44 KernelPath: "/usr/share/kata-containers/vmlinux.container", 45 ImagePath: "/usr/share/kata-containers/kata-containers.img", 46 HypervisorPath: "/usr/bin/qemu-system-x86_64", 47 MemorySize: 1024, 48 } 49 50 // Use kata default values for the agent. 51 agConfig := vc.KataAgentConfig{} 52 53 // The sandbox configuration: 54 // - One container 55 // - Hypervisor is QEMU 56 // - Agent is kata 57 sandboxConfig := vc.SandboxConfig{ 58 HypervisorType: vc.QemuHypervisor, 59 HypervisorConfig: hypervisorConfig, 60 61 AgentType: vc.KataContainersAgent, 62 AgentConfig: agConfig, 63 64 Containers: []vc.ContainerConfig{container}, 65 } 66 67 _, err := vc.RunSandbox(context.Background(), sandboxConfig, nil) 68 if err != nil { 69 fmt.Printf("Could not run sandbox: %s", err) 70 } 71 }