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
d31d5436
Commit
d31d5436
authored
Jun 11, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/virtualbox: Suppress some messages
parent
99af93f8
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
150 additions
and
0 deletions
+150
-0
builder/virtualbox/builder.go
builder/virtualbox/builder.go
+50
-0
builder/virtualbox/driver.go
builder/virtualbox/driver.go
+53
-0
builder/virtualbox/step_prepare_output_dir.go
builder/virtualbox/step_prepare_output_dir.go
+20
-0
builder/virtualbox/step_suppress_messages.go
builder/virtualbox/step_suppress_messages.go
+27
-0
No files found.
builder/virtualbox/builder.go
View file @
d31d5436
package
virtualbox
package
virtualbox
import
(
import
(
"fmt"
"github.com/mitchellh/mapstructure"
"github.com/mitchellh/mapstructure"
"github.com/mitchellh/multistep"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/packer"
"log"
)
)
const
BuilderId
=
"mitchellh.virtualbox"
const
BuilderId
=
"mitchellh.virtualbox"
type
Builder
struct
{
type
Builder
struct
{
config
config
config
config
driver
Driver
runner
multistep
.
Runner
runner
multistep
.
Runner
}
}
...
@@ -18,16 +21,63 @@ type config struct {
...
@@ -18,16 +21,63 @@ type config struct {
}
}
func
(
b
*
Builder
)
Prepare
(
raw
interface
{})
error
{
func
(
b
*
Builder
)
Prepare
(
raw
interface
{})
error
{
var
err
error
if
err
:=
mapstructure
.
Decode
(
raw
,
&
b
.
config
);
err
!=
nil
{
if
err
:=
mapstructure
.
Decode
(
raw
,
&
b
.
config
);
err
!=
nil
{
return
err
return
err
}
}
if
b
.
config
.
OutputDir
==
""
{
b
.
config
.
OutputDir
=
"virtualbox"
}
errs
:=
make
([]
error
,
0
)
b
.
driver
,
err
=
b
.
newDriver
()
if
err
!=
nil
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"Failed creating VirtualBox driver: %s"
,
err
))
}
if
len
(
errs
)
>
0
{
return
&
packer
.
MultiError
{
errs
}
}
return
nil
return
nil
}
}
func
(
b
*
Builder
)
Run
(
ui
packer
.
Ui
,
hook
packer
.
Hook
,
cache
packer
.
Cache
)
packer
.
Artifact
{
func
(
b
*
Builder
)
Run
(
ui
packer
.
Ui
,
hook
packer
.
Hook
,
cache
packer
.
Cache
)
packer
.
Artifact
{
steps
:=
[]
multistep
.
Step
{
new
(
stepPrepareOutputDir
),
new
(
stepSuppressMessages
),
}
// Setup the state bag
state
:=
make
(
map
[
string
]
interface
{})
state
[
"cache"
]
=
cache
state
[
"config"
]
=
&
b
.
config
state
[
"driver"
]
=
b
.
driver
state
[
"hook"
]
=
hook
state
[
"ui"
]
=
ui
// Run
b
.
runner
=
&
multistep
.
BasicRunner
{
Steps
:
steps
}
b
.
runner
.
Run
(
state
)
return
nil
return
nil
}
}
func
(
b
*
Builder
)
Cancel
()
{
func
(
b
*
Builder
)
Cancel
()
{
if
b
.
runner
!=
nil
{
log
.
Println
(
"Cancelling the step runner..."
)
b
.
runner
.
Cancel
()
}
}
func
(
b
*
Builder
)
newDriver
()
(
Driver
,
error
)
{
vboxmanagePath
:=
"VBoxManage"
driver
:=
&
VBox42Driver
{
vboxmanagePath
}
if
err
:=
driver
.
Verify
();
err
!=
nil
{
return
nil
,
err
}
return
driver
,
nil
}
}
builder/virtualbox/driver.go
0 → 100644
View file @
d31d5436
package
virtualbox
import
(
"log"
"os/exec"
)
// A driver is able to talk to VirtualBox and perform certain
// operations with it.
type
Driver
interface
{
// SuppressMessages should do what needs to be done in order to
// suppress any annoying popups from VirtualBox.
SuppressMessages
()
error
// Verify checks to make sure that this driver should function
// properly. If there is any indication the driver can't function,
// this will return an error.
Verify
()
error
}
type
VBox42Driver
struct
{
// This is the path to the "VBoxManage" application.
VBoxManagePath
string
}
func
(
d
*
VBox42Driver
)
SuppressMessages
()
error
{
extraData
:=
map
[
string
]
string
{
"GUI/RegistrationData"
:
"triesLeft=0"
,
"GUI/SuppressMessages"
:
"confirmInputCapture,remindAboutAutoCapture,remindAboutMouseIntegrationOff,remindAboutMouseIntegrationOn,remindAboutWrongColorDepth"
,
}
for
k
,
v
:=
range
extraData
{
if
err
:=
d
.
vboxmanage
(
"setextradata"
,
"global"
,
k
,
v
);
err
!=
nil
{
return
err
}
}
return
nil
}
func
(
d
*
VBox42Driver
)
Verify
()
error
{
return
nil
}
func
(
d
*
VBox42Driver
)
vboxmanage
(
args
...
string
)
error
{
log
.
Printf
(
"Executing VBoxManage: %#v"
,
args
)
cmd
:=
exec
.
Command
(
d
.
VBoxManagePath
,
args
...
)
if
err
:=
cmd
.
Run
();
err
!=
nil
{
return
err
}
return
nil
}
builder/virtualbox/step_prepare_output_dir.go
0 → 100644
View file @
d31d5436
package
virtualbox
import
(
"github.com/mitchellh/multistep"
"os"
)
type
stepPrepareOutputDir
struct
{}
func
(
stepPrepareOutputDir
)
Run
(
state
map
[
string
]
interface
{})
multistep
.
StepAction
{
config
:=
state
[
"config"
]
.
(
*
config
)
if
err
:=
os
.
MkdirAll
(
config
.
OutputDir
,
0755
);
err
!=
nil
{
return
multistep
.
ActionHalt
}
return
multistep
.
ActionContinue
}
func
(
stepPrepareOutputDir
)
Cleanup
(
map
[
string
]
interface
{})
{}
builder/virtualbox/step_suppress_messages.go
0 → 100644
View file @
d31d5436
package
virtualbox
import
(
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"log"
)
// This step sets some variables in VirtualBox so that annoying
// pop-up messages don't exist.
type
stepSuppressMessages
struct
{}
func
(
stepSuppressMessages
)
Run
(
state
map
[
string
]
interface
{})
multistep
.
StepAction
{
driver
:=
state
[
"driver"
]
.
(
Driver
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
log
.
Println
(
"Suppressing annoying messages in VirtualBox"
)
if
err
:=
driver
.
SuppressMessages
();
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error configuring VirtualBox to suppress messages: %s"
,
err
))
return
multistep
.
ActionHalt
}
return
multistep
.
ActionContinue
}
func
(
stepSuppressMessages
)
Cleanup
(
map
[
string
]
interface
{})
{}
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