aboutsummaryrefslogtreecommitdiffstats
path: root/vm/vmm/vmm.go
diff options
context:
space:
mode:
Diffstat (limited to 'vm/vmm/vmm.go')
-rw-r--r--vm/vmm/vmm.go51
1 files changed, 25 insertions, 26 deletions
diff --git a/vm/vmm/vmm.go b/vm/vmm/vmm.go
index 90ec66ad7..35fdf7650 100644
--- a/vm/vmm/vmm.go
+++ b/vm/vmm/vmm.go
@@ -44,14 +44,11 @@ type Pool struct {
}
type instance struct {
- cfg *Config
- image string
- debug bool
- os string
- sshkey string
- sshuser string
- sshhost string
- sshport int
+ cfg *Config
+ image string
+ debug bool
+ os string
+ vmimpl.SSHOptions
merger *vmimpl.OutputMerger
vmName string
vmm *exec.Cmd
@@ -101,15 +98,17 @@ func (pool *Pool) Create(workdir string, index int) (vmimpl.Instance, error) {
tee = os.Stdout
}
inst := &instance{
- cfg: pool.cfg,
- image: filepath.Join(workdir, "disk.qcow2"),
- debug: pool.env.Debug,
- os: pool.env.OS,
- sshkey: pool.env.SSHKey,
- sshuser: pool.env.SSHUser,
- sshport: 22,
- vmName: fmt.Sprintf("%v-%v", pool.env.Name, index),
- merger: vmimpl.NewOutputMerger(tee),
+ cfg: pool.cfg,
+ image: filepath.Join(workdir, "disk.qcow2"),
+ debug: pool.env.Debug,
+ os: pool.env.OS,
+ SSHOptions: vmimpl.SSHOptions{
+ Key: pool.env.SSHKey,
+ User: pool.env.SSHUser,
+ Port: 22,
+ },
+ vmName: fmt.Sprintf("%v-%v", pool.env.Name, index),
+ merger: vmimpl.NewOutputMerger(tee),
}
// Stop the instance from the previous run in case it's still running.
@@ -180,13 +179,13 @@ func (inst *instance) Boot() error {
inr.Close()
inst.merger.Add("console", outr)
- inst.sshhost, err = inst.lookupSSHAddress()
+ inst.Addr, err = inst.lookupSSHAddress()
if err != nil {
return err
}
- if err := vmimpl.WaitForSSH(inst.debug, 20*time.Minute, inst.sshhost,
- inst.sshkey, inst.sshuser, inst.os, inst.sshport, nil, false); err != nil {
+ if err := vmimpl.WaitForSSH(20*time.Minute, inst.SSHOptions,
+ inst.os, nil, false, inst.debug); err != nil {
out := <-inst.merger.Output
return vmimpl.BootError{Title: err.Error(), Output: out}
}
@@ -229,9 +228,9 @@ func (inst *instance) Close() error {
}
func (inst *instance) Forward(port int) (string, error) {
- octets := strings.Split(inst.sshhost, ".")
+ octets := strings.Split(inst.Addr, ".")
if len(octets) < 3 {
- return "", fmt.Errorf("too few octets in hostname %v", inst.sshhost)
+ return "", fmt.Errorf("too few octets in hostname %v", inst.Addr)
}
addr := fmt.Sprintf("%v.%v.%v.2:%v", octets[0], octets[1], octets[2], port)
return addr, nil
@@ -239,8 +238,8 @@ func (inst *instance) Forward(port int) (string, error) {
func (inst *instance) Copy(hostSrc string) (string, error) {
vmDst := filepath.Join("/root", filepath.Base(hostSrc))
- args := append(vmimpl.SCPArgs(inst.debug, inst.sshkey, inst.sshport, false),
- hostSrc, inst.sshuser+"@"+inst.sshhost+":"+vmDst)
+ args := append(vmimpl.SCPArgs(inst.debug, inst.Key, inst.Port, false),
+ hostSrc, inst.User+"@"+inst.Addr+":"+vmDst)
if inst.debug {
log.Logf(0, "running command: scp %#v", args)
}
@@ -259,8 +258,8 @@ func (inst *instance) Run(timeout time.Duration, stop <-chan bool, command strin
}
inst.merger.Add("ssh", rpipe)
- args := append(vmimpl.SSHArgs(inst.debug, inst.sshkey, inst.sshport, false),
- inst.sshuser+"@"+inst.sshhost, command)
+ args := append(vmimpl.SSHArgs(inst.debug, inst.Key, inst.Port, false),
+ inst.User+"@"+inst.Addr, command)
if inst.debug {
log.Logf(0, "running command: ssh %#v", args)
}