Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
170e2459
Commit
170e2459
authored
Nov 05, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/qemu: remove constructor, more Go-like
parent
3bc0c4aa
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
18 deletions
+10
-18
builder/qemu/builder.go
builder/qemu/builder.go
+4
-2
builder/qemu/driver.go
builder/qemu/driver.go
+6
-16
No files found.
builder/qemu/builder.go
View file @
170e2459
...
@@ -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
...
...
builder/qemu/driver.go
View file @
170e2459
...
@@ -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
{
q
emuPath
string
Q
emuPath
string
q
emuImgPath
string
Q
emuImgPath
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
.
q
emuPath
,
qemuArgs
)
log
.
Printf
(
"Executing %s: %#v"
,
d
.
Q
emuPath
,
qemuArgs
)
cmd
:=
exec
.
Command
(
d
.
q
emuPath
,
qemuArgs
...
)
cmd
:=
exec
.
Command
(
d
.
Q
emuPath
,
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
.
q
emuImgPath
,
args
...
)
cmd
:=
exec
.
Command
(
d
.
Q
emuImgPath
,
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
.
q
emuPath
,
"-version"
)
cmd
:=
exec
.
Command
(
d
.
Q
emuPath
,
"-version"
)
cmd
.
Stdout
=
&
stdout
cmd
.
Stdout
=
&
stdout
if
err
:=
cmd
.
Run
();
err
!=
nil
{
if
err
:=
cmd
.
Run
();
err
!=
nil
{
return
""
,
err
return
""
,
err
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment