MCPcopy Index your code
hub / github.com/linuxkit/linuxkit / runVBoxCmd

Function runVBoxCmd

src/cmd/linuxkit/run_vbox.go:61–322  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

59}
60
61func runVBoxCmd() *cobra.Command {
62 var (
63 enableGUI bool
64 vboxmanageFlag string
65 keep bool
66 vmName string
67 state string
68 isoBoot bool
69 uefiBoot bool
70 networks VBNetworks
71 )
72
73 cmd := &cobra.Command{
74 Use: "vbox",
75 Short: "launch a vbox VM using an existing image",
76 Long: `Launch a vbox VM using an existing image.
77 'path' specifies the path to the VM image.
78 `,
79 Args: cobra.ExactArgs(1),
80 Example: "linuxkit run vbox [options] path",
81 RunE: func(cmd *cobra.Command, args []string) error {
82 path := args[0]
83 if runtime.GOOS == "windows" {
84 return fmt.Errorf("TODO: Windows is not yet supported")
85 }
86
87 if strings.HasSuffix(path, ".iso") {
88 isoBoot = true
89 }
90
91 vboxmanage, err := exec.LookPath(vboxmanageFlag)
92 if err != nil {
93 return fmt.Errorf("cannot find management binary %s: %v", vboxmanageFlag, err)
94 }
95
96 name := vmName
97 if name == "" {
98 name = strings.TrimSuffix(filepath.Base(path), filepath.Ext(path))
99 }
100
101 if state == "" {
102 prefix := strings.TrimSuffix(path, filepath.Ext(path))
103 state = prefix + "-state"
104 }
105 if err := os.MkdirAll(state, 0755); err != nil {
106 return fmt.Errorf("could not create state directory: %v", err)
107 }
108
109 // remove machine in case it already exists
110 cleanup(vboxmanage, name, false)
111
112 _, out, err := manage(vboxmanage, "createvm", "--name", name, "--register")
113 if err != nil {
114 return fmt.Errorf("createvm error: %v\n%s", err, out)
115 }
116
117 _, out, err = manage(vboxmanage, "modifyvm", name, "--acpi", "on")
118 if err != nil {

Callers 1

runCmdFunction · 0.85

Calls 3

manageFunction · 0.85
RemoveMethod · 0.80
cleanupFunction · 0.70

Tested by

no test coverage detected