Commit 170e2459 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

builder/qemu: remove constructor, more Go-like

parent 3bc0c4aa
...@@ -469,8 +469,10 @@ func (b *Builder) newDriver() (Driver, error) { ...@@ -469,8 +469,10 @@ func (b *Builder) newDriver() (Driver, error) {
} }
log.Printf("Qemu path: %s, Qemu Image page: %s", qemuPath, qemuImgPath) log.Printf("Qemu path: %s, Qemu Image page: %s", qemuPath, qemuImgPath)
driver := &QemuDriver{} driver := &QemuDriver{
driver.Initialize(qemuPath, qemuImgPath) QemuPath: qemuPath,
QemuImgPath: qemuImgPath,
}
if err := driver.Verify(); err != nil { if err := driver.Verify(); err != nil {
return nil, err return nil, err
......
...@@ -20,11 +20,6 @@ type DriverCancelCallback func(state multistep.StateBag) bool ...@@ -20,11 +20,6 @@ type DriverCancelCallback func(state multistep.StateBag) bool
// A driver is able to talk to qemu-system-x86_64 and perform certain // A driver is able to talk to qemu-system-x86_64 and perform certain
// operations with it. // operations with it.
type Driver interface { type Driver interface {
// Initializes the driver with the given values:
// Arguments: qemuPath - string value for the qemu-system-x86_64 executable
// qemuImgPath - string value for the qemu-img executable
Initialize(string, string)
// Stop stops a running machine, forcefully. // Stop stops a running machine, forcefully.
Stop() error Stop() error
...@@ -47,19 +42,14 @@ type Driver interface { ...@@ -47,19 +42,14 @@ type Driver interface {
} }
type QemuDriver struct { type QemuDriver struct {
qemuPath string QemuPath string
qemuImgPath string QemuImgPath string
vmCmd *exec.Cmd vmCmd *exec.Cmd
vmEndCh <-chan int vmEndCh <-chan int
lock sync.Mutex lock sync.Mutex
} }
func (d *QemuDriver) Initialize(qemuPath string, qemuImgPath string) {
d.qemuPath = qemuPath
d.qemuImgPath = qemuImgPath
}
func (d *QemuDriver) Stop() error { func (d *QemuDriver) Stop() error {
d.lock.Lock() d.lock.Lock()
defer d.lock.Unlock() defer d.lock.Unlock()
...@@ -84,8 +74,8 @@ func (d *QemuDriver) Qemu(qemuArgs ...string) error { ...@@ -84,8 +74,8 @@ func (d *QemuDriver) Qemu(qemuArgs ...string) error {
stdout_r, stdout_w := io.Pipe() stdout_r, stdout_w := io.Pipe()
stderr_r, stderr_w := io.Pipe() stderr_r, stderr_w := io.Pipe()
log.Printf("Executing %s: %#v", d.qemuPath, qemuArgs) log.Printf("Executing %s: %#v", d.QemuPath, qemuArgs)
cmd := exec.Command(d.qemuPath, qemuArgs...) cmd := exec.Command(d.QemuPath, qemuArgs...)
cmd.Stdout = stdout_w cmd.Stdout = stdout_w
cmd.Stderr = stderr_w cmd.Stderr = stderr_w
...@@ -154,7 +144,7 @@ func (d *QemuDriver) QemuImg(args ...string) error { ...@@ -154,7 +144,7 @@ func (d *QemuDriver) QemuImg(args ...string) error {
var stdout, stderr bytes.Buffer var stdout, stderr bytes.Buffer
log.Printf("Executing qemu-img: %#v", args) log.Printf("Executing qemu-img: %#v", args)
cmd := exec.Command(d.qemuImgPath, args...) cmd := exec.Command(d.QemuImgPath, args...)
cmd.Stdout = &stdout cmd.Stdout = &stdout
cmd.Stderr = &stderr cmd.Stderr = &stderr
err := cmd.Run() err := cmd.Run()
...@@ -179,7 +169,7 @@ func (d *QemuDriver) Verify() error { ...@@ -179,7 +169,7 @@ func (d *QemuDriver) Verify() error {
func (d *QemuDriver) Version() (string, error) { func (d *QemuDriver) Version() (string, error) {
var stdout bytes.Buffer var stdout bytes.Buffer
cmd := exec.Command(d.qemuPath, "-version") cmd := exec.Command(d.QemuPath, "-version")
cmd.Stdout = &stdout cmd.Stdout = &stdout
if err := cmd.Run(); err != nil { if err := cmd.Run(); err != nil {
return "", err return "", err
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment