forked from Parallels/docker-machine-parallels
-
Notifications
You must be signed in to change notification settings - Fork 1
/
prlctl.go
65 lines (53 loc) · 1.8 KB
/
prlctl.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
package parallels
import (
"bytes"
"errors"
"os"
"os/exec"
"strings"
"github.com/docker/machine/libmachine/log"
)
var (
prlctlCmd = detectCmdInPath("prlctl")
prlsrvctlCmd = detectCmdInPath("prlsrvctl")
prldisktoolCmd = detectCmdInPath("prl_disk_tool")
errPrlctlNotFound = errors.New("Could not detect `prlctl` binary! Make sure Parallels Desktop Pro or Business edition is installed")
errPrlsrvctlNotFound = errors.New("Could not detect `prlsrvctl` binary! Make sure Parallels Desktop Pro or Business edition is installed")
errPrldisktoolNotFound = errors.New("Could not detect `prl_disk_tool` binary! Make sure Parallels Desktop Pro or Business edition is installed")
)
func runCmd(cmdName string, args []string, notFound error) (string, string, error) {
cmd := exec.Command(cmdName, args...)
if os.Getenv("MACHINE_DEBUG") != "" {
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
}
var stdout bytes.Buffer
var stderr bytes.Buffer
cmd.Stdout, cmd.Stderr = &stdout, &stderr
log.Debugf("executing: %v %v", cmdName, strings.Join(args, " "))
err := cmd.Run()
if err != nil {
if ee, ok := err.(*exec.Error); ok && ee.Err == exec.ErrNotFound {
err = notFound
}
}
return stdout.String(), stderr.String(), err
}
func prlctl(args ...string) error {
_, _, err := runCmd(prlctlCmd, args, errPrlctlNotFound)
return err
}
func prlctlOutErr(args ...string) (string, string, error) {
return runCmd(prlctlCmd, args, errPrlctlNotFound)
}
func prlsrvctl(args ...string) error {
_, _, err := runCmd(prlsrvctlCmd, args, errPrlsrvctlNotFound)
return err
}
func prlsrvctlOutErr(args ...string) (string, string, error) {
return runCmd(prlsrvctlCmd, args, errPrlsrvctlNotFound)
}
func prldisktool(args ...string) error {
_, _, err := runCmd(prldisktoolCmd, args, errPrldisktoolNotFound)
return err
}