-
Notifications
You must be signed in to change notification settings - Fork 0
/
machine-commands.go
58 lines (48 loc) · 1.31 KB
/
machine-commands.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
package drivervbox
import (
"fmt"
"github.com/kuttiproject/drivercore"
"github.com/kuttiproject/workspace"
)
// TODO: Look at parameterizing these
var (
vboxUsername = "kuttiadmin"
vboxPassword = "Pass@word1"
)
// runwithresults allows running commands inside a VM Host.
// It does this by running the command:
// - VBoxManage guestcontrol <machiname> --username <username> --password <password> run -- <command line>
// This requires Virtual Machine Additions to be running in the guest operating system.
// The guest OS should be fully booted up.
func (vh *Machine) runwithresults(execpath string, paramarray ...string) (string, error) {
params := []string{
"guestcontrol",
vh.qname(),
"--username",
vboxUsername,
"--password",
vboxPassword,
"run",
"--",
execpath,
}
params = append(params, paramarray...)
output, err := workspace.RunWithResults(
vh.driver.vboxmanagepath,
params...,
)
return output, err
}
var vboxCommands = map[drivercore.PredefinedCommand]func(*Machine, ...string) error{
drivercore.RenameMachine: renamemachine,
}
func renamemachine(vh *Machine, params ...string) error {
newname := params[0]
execname := fmt.Sprintf("/home/%s/kutti-installscripts/set-hostname.sh", vboxUsername)
_, err := vh.runwithresults(
"/usr/bin/sudo",
execname,
newname,
)
return err
}