forked from adamlaska/machine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvirtualbox_windows.go
More file actions
100 lines (80 loc) · 2.69 KB
/
virtualbox_windows.go
File metadata and controls
100 lines (80 loc) · 2.69 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package virtualbox
import (
"strings"
"fmt"
"os"
"os/exec"
"path/filepath"
"github.com/docker/machine/libmachine/log"
"golang.org/x/sys/windows/registry"
)
// IsVTXDisabled checks if VT-X is disabled in the BIOS. If it is, the vm will fail to start.
// If we can't be sure it is disabled, we carry on and will check the vm logs after it's started.
func (d *Driver) IsVTXDisabled() bool {
errmsg := "Couldn't check that VT-X/AMD-v is enabled. Will check that the vm is properly created: %v"
output, err := cmdOutput("wmic", "cpu", "get", "VirtualizationFirmwareEnabled")
if err != nil {
log.Debugf(errmsg, err)
return false
}
disabled := strings.Contains(output, "FALSE")
return disabled
}
// cmdOutput runs a shell command and returns its output.
func cmdOutput(name string, args ...string) (string, error) {
cmd := exec.Command(name, args...)
log.Debugf("COMMAND: %v %v", name, strings.Join(args, " "))
stdout, err := cmd.Output()
if err != nil {
return "", err
}
log.Debugf("STDOUT:\n{\n%v}", string(stdout))
return string(stdout), nil
}
func detectVBoxManageCmd() string {
cmd := "VBoxManage"
if p := os.Getenv("VBOX_INSTALL_PATH"); p != "" {
if path, err := exec.LookPath(filepath.Join(p, cmd)); err == nil {
return path
}
}
if p := os.Getenv("VBOX_MSI_INSTALL_PATH"); p != "" {
if path, err := exec.LookPath(filepath.Join(p, cmd)); err == nil {
return path
}
}
// Look in default installation path for VirtualBox version > 5
if path, err := exec.LookPath(filepath.Join("C:\\Program Files\\Oracle\\VirtualBox", cmd)); err == nil {
return path
}
// Look in windows registry
if p, err := findVBoxInstallDirInRegistry(); err == nil {
if path, err := exec.LookPath(filepath.Join(p, cmd)); err == nil {
return path
}
}
return detectVBoxManageCmdInPath() //fallback to path
}
func findVBoxInstallDirInRegistry() (string, error) {
registryKey, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Oracle\VirtualBox`, registry.QUERY_VALUE)
if err != nil {
errorMessage := fmt.Sprintf("Can't find VirtualBox registry entries, is VirtualBox really installed properly? %s", err)
log.Debugf(errorMessage)
return "", fmt.Errorf(errorMessage)
}
defer registryKey.Close()
installDir, _, err := registryKey.GetStringValue("InstallDir")
if err != nil {
errorMessage := fmt.Sprintf("Can't find InstallDir registry key within VirtualBox registries entries, is VirtualBox really installed properly? %s", err)
log.Debugf(errorMessage)
return "", fmt.Errorf(errorMessage)
}
return installDir, nil
}
func getShareDriveAndName() (string, string) {
return "c/Users", "c:\\Users"
}
func isHyperVInstalled() bool {
_, err := exec.LookPath("vmms.exe")
return err == nil
}