forked from docker/machine
/
vbox_create.go
54 lines (40 loc) · 1.1 KB
/
vbox_create.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
// Sample Virtualbox create independent of Machine CLI.
import (
"fmt"
"os"
"github.com/docker/machine/drivers/virtualbox"
"github.com/docker/machine/libmachine"
"github.com/docker/machine/libmachine/log"
)
func main() {
libmachine.SetDebug(true)
log.SetOutWriter(os.Stdout)
log.SetErrWriter(os.Stderr)
// returns the familiar store at $HOME/.docker/machine
store := libmachine.GetDefaultStore()
// over-ride this for now (don't want to muck with my default store)
store.Path = "/tmp/automatic"
hostName := "myfunhost"
// Set some options on the provider...
driver := virtualbox.NewDriver(hostName, "/tmp/automatic")
driver.CPU = 2
driver.Memory = 2048
h, err := store.NewHost(driver)
if err != nil {
log.Fatal(err)
}
h.HostOptions.EngineOptions.StorageDriver = "overlay"
if err := libmachine.Create(store, h); err != nil {
log.Fatal(err)
}
out, err := h.RunSSHCommand("df -h")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Results of your disk space query:\n%s\n", out)
fmt.Println("Powering down machine now...")
if err := h.Stop(); err != nil {
log.Fatal(err)
}
}