-
Notifications
You must be signed in to change notification settings - Fork 0
/
driver.go
100 lines (84 loc) · 2.1 KB
/
driver.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
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 drivervbox
import (
"fmt"
"github.com/kuttiproject/workspace"
)
const (
driverName = "vbox"
driverDescription = "Kutti driver for VirtualBox 6.0 and above"
networkNameSuffix = "kuttinet"
networkNamePattern = "*" + networkNameSuffix
dhcpaddress = "192.168.125.3"
dhcpnetmask = "255.255.255.0"
ipNetAddr = "192.168.125"
iphostbase = 10
forwardedPortBase = 10000
)
// DefaultNetCIDR is the address range used by NAT networks.
var DefaultNetCIDR = "192.168.125.0/24"
// Driver implements the drivercore.Driver interface for VirtualBox.
type Driver struct {
vboxmanagepath string
validated bool
status string
errormessage string
}
// Name returns "vbox"
func (vd *Driver) Name() string {
return driverName
}
// Description returns "Kutti driver for VirtualBox 6.0 and above"
func (vd *Driver) Description() string {
return driverDescription
}
// UsesPerClusterNetworking returns true
func (vd *Driver) UsesPerClusterNetworking() bool {
return true
}
// UsesNATNetworking returns true
func (vd *Driver) UsesNATNetworking() bool {
return true
}
func (vd *Driver) validate() bool {
if vd.validated {
return true
}
// find VBoxManage tool and set it
vbmpath, err := findvboxmanage()
if err != nil {
vd.status = "Error"
vd.errormessage = err.Error()
return false
}
vd.vboxmanagepath = vbmpath
// test VBoxManage version
vbmversion, err := workspace.RunWithResults(vbmpath, "--version")
if err != nil {
vd.status = "Error"
vd.errormessage = err.Error()
return false
}
var majorversion int
_, err = fmt.Sscanf(vbmversion, "%d", &majorversion)
if err != nil || majorversion < 6 {
err = fmt.Errorf("unsupported VBoxManage version %v. 6.0 and above are supported", vbmversion)
vd.status = "Error"
vd.errormessage = err.Error()
return false
}
vd.status = "Ready"
vd.validated = true
return true
}
// Status returns current driver status
func (vd *Driver) Status() string {
vd.validate()
return vd.status
}
func (vd *Driver) Error() string {
vd.validate()
if vd.status != "Error" {
return ""
}
return vd.errormessage
}