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
07e5a85b
Commit
07e5a85b
authored
Nov 05, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/qemu: log VM output
parent
b75a2935
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
4 deletions
+28
-4
builder/qemu/driver.go
builder/qemu/driver.go
+28
-4
No files found.
builder/qemu/driver.go
View file @
07e5a85b
package
qemu
import
(
"bufio"
"bytes"
"errors"
"fmt"
"github.com/mitchellh/multistep"
"io"
"log"
"os/exec"
"regexp"
"strings"
"time"
"unicode"
)
type
DriverCancelCallback
func
(
state
multistep
.
StateBag
)
bool
...
...
@@ -92,20 +95,24 @@ func (d *QemuDriver) Stop(name string) error {
}
func
(
d
*
QemuDriver
)
Qemu
(
vmName
string
,
qemuArgs
...
string
)
error
{
var
stdout
,
stderr
bytes
.
Buffer
stdout_r
,
stdout_w
:=
io
.
Pipe
()
stderr_r
,
stderr_w
:=
io
.
Pipe
()
log
.
Printf
(
"Executing %s: %#v"
,
d
.
qemuPath
,
qemuArgs
)
ds
:=
d
.
getDriverState
(
vmName
)
ds
.
cmd
=
exec
.
Command
(
d
.
qemuPath
,
qemuArgs
...
)
ds
.
cmd
.
Stdout
=
&
stdout
ds
.
cmd
.
Stderr
=
&
stderr
ds
.
cmd
.
Stdout
=
stdout_w
ds
.
cmd
.
Stderr
=
stderr_w
go
logReader
(
"Qemu stdout"
,
stdout_r
)
go
logReader
(
"Qemu stderr"
,
stderr_r
)
err
:=
ds
.
cmd
.
Start
()
if
err
!=
nil
{
err
=
fmt
.
Errorf
(
"Error starting VM: %s"
,
err
)
}
else
{
log
.
Printf
(
"---- Started Qemu ------- PID = "
,
ds
.
cmd
.
Process
.
Pid
)
log
.
Printf
(
"---- Started Qemu ------- PID =
%d
"
,
ds
.
cmd
.
Process
.
Pid
)
ds
.
cancelChan
=
make
(
chan
struct
{})
...
...
@@ -114,6 +121,8 @@ func (d *QemuDriver) Qemu(vmName string, qemuArgs ...string) error {
// start the virtual machine in the background
go
func
()
{
defer
stderr_w
.
Close
()
defer
stdout_w
.
Close
()
ds
.
waitDone
<-
ds
.
cmd
.
Wait
()
}()
}
...
...
@@ -242,3 +251,18 @@ func (d *QemuDriver) Version() (string, error) {
log
.
Printf
(
"Qemu version: %s"
,
matches
[
0
])
return
matches
[
0
],
nil
}
func
logReader
(
name
string
,
r
io
.
Reader
)
{
bufR
:=
bufio
.
NewReader
(
r
)
for
{
line
,
err
:=
bufR
.
ReadString
(
'\n'
)
if
line
!=
""
{
line
=
strings
.
TrimRightFunc
(
line
,
unicode
.
IsSpace
)
log
.
Printf
(
"%s: %s"
,
name
,
line
)
}
if
err
==
io
.
EOF
{
break
}
}
}
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