/
vmx.go
51 lines (47 loc) · 982 Bytes
/
vmx.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
package vmware
import (
"bufio"
"os"
"strconv"
"strings"
)
type Vmx struct {
MacAddress string
CleanShutdown bool
SoftPowerOff bool
Memory int
Cpus int
}
func (vmx *Vmx) Parse(path string) error {
f, e := os.Open(path)
if e != nil {
return e
}
defer f.Close()
scan := bufio.NewScanner(f)
vmx.Cpus = 1
for scan.Scan() {
parts := strings.SplitN(scan.Text(), " = ", 2)
if len(parts) == 2 {
switch parts[0] {
case "ethernet0.generatedAddress":
vmx.MacAddress = strings.Replace(parts[1], `"`, "", -1)
case "cleanShutdown":
vmx.CleanShutdown = parts[1] == `"TRUE"`
case "softPowerOff":
vmx.SoftPowerOff = parts[1] == `"TRUE"`
case "memsize":
vmx.Memory, e = strconv.Atoi(strings.Replace(parts[1], `"`, "", -1))
if e != nil {
return e
}
case "numvcpus":
vmx.Cpus, e = strconv.Atoi(strings.Replace(parts[1], `"`, "", -1))
if e != nil {
return e
}
}
}
}
return scan.Err()
}