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
e11f655d
Commit
e11f655d
authored
Dec 26, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/vmware/vmx: run the VMs
parent
286edcb2
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
93 additions
and
58 deletions
+93
-58
builder/vmware/common/run_config.go
builder/vmware/common/run_config.go
+44
-0
builder/vmware/common/run_config_test.go
builder/vmware/common/run_config_test.go
+36
-0
builder/vmware/iso/builder.go
builder/vmware/iso/builder.go
+3
-17
builder/vmware/iso/builder_test.go
builder/vmware/iso/builder_test.go
+0
-40
builder/vmware/vmx/builder.go
builder/vmware/vmx/builder.go
+8
-1
builder/vmware/vmx/config.go
builder/vmware/vmx/config.go
+2
-0
No files found.
builder/vmware/common/run_config.go
0 → 100644
View file @
e11f655d
package
common
import
(
"fmt"
"time"
"github.com/mitchellh/packer/packer"
)
type
RunConfig
struct
{
Headless
bool
`mapstructure:"headless"`
RawBootWait
string
`mapstructure:"boot_wait"`
BootWait
time
.
Duration
``
}
func
(
c
*
RunConfig
)
Prepare
(
t
*
packer
.
ConfigTemplate
)
[]
error
{
if
c
.
RawBootWait
==
""
{
c
.
RawBootWait
=
"10s"
}
templates
:=
map
[
string
]
*
string
{
"boot_wait"
:
&
c
.
RawBootWait
,
}
var
err
error
errs
:=
make
([]
error
,
0
)
for
n
,
ptr
:=
range
templates
{
*
ptr
,
err
=
t
.
Process
(
*
ptr
,
nil
)
if
err
!=
nil
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"Error processing %s: %s"
,
n
,
err
))
}
}
if
c
.
RawBootWait
!=
""
{
c
.
BootWait
,
err
=
time
.
ParseDuration
(
c
.
RawBootWait
)
if
err
!=
nil
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"Failed parsing boot_wait: %s"
,
err
))
}
}
return
errs
}
builder/vmware/common/run_config_test.go
0 → 100644
View file @
e11f655d
package
common
import
(
"testing"
)
func
TestRunConfigPrepare
(
t
*
testing
.
T
)
{
var
c
*
RunConfig
// Test a default boot_wait
c
=
new
(
RunConfig
)
c
.
RawBootWait
=
""
errs
:=
c
.
Prepare
(
testConfigTemplate
(
t
))
if
len
(
errs
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
errs
)
}
if
c
.
RawBootWait
!=
"10s"
{
t
.
Fatalf
(
"bad value: %s"
,
c
.
RawBootWait
)
}
// Test with a bad boot_wait
c
=
new
(
RunConfig
)
c
.
RawBootWait
=
"this is not good"
errs
=
c
.
Prepare
(
testConfigTemplate
(
t
))
if
len
(
errs
)
==
0
{
t
.
Fatal
(
"should error"
)
}
// Test with a good one
c
=
new
(
RunConfig
)
c
.
RawBootWait
=
"5s"
errs
=
c
.
Prepare
(
testConfigTemplate
(
t
))
if
len
(
errs
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
errs
)
}
}
builder/vmware/iso/builder.go
View file @
e11f655d
...
...
@@ -26,6 +26,7 @@ type Builder struct {
type
config
struct
{
common
.
PackerConfig
`mapstructure:",squash"`
vmwcommon
.
OutputConfig
`mapstructure:",squash"`
vmwcommon
.
RunConfig
`mapstructure:",squash"`
vmwcommon
.
SSHConfig
`mapstructure:",squash"`
vmwcommon
.
VMXConfig
`mapstructure:",squash"`
...
...
@@ -38,7 +39,6 @@ type config struct {
ISOChecksumType
string
`mapstructure:"iso_checksum_type"`
ISOUrls
[]
string
`mapstructure:"iso_urls"`
VMName
string
`mapstructure:"vm_name"`
Headless
bool
`mapstructure:"headless"`
HTTPDir
string
`mapstructure:"http_directory"`
HTTPPortMin
uint
`mapstructure:"http_port_min"`
HTTPPortMax
uint
`mapstructure:"http_port_max"`
...
...
@@ -58,11 +58,9 @@ type config struct {
RemoteUser
string
`mapstructure:"remote_username"`
RemotePassword
string
`mapstructure:"remote_password"`
RawBootWait
string
`mapstructure:"boot_wait"`
RawSingleISOUrl
string
`mapstructure:"iso_url"`
RawShutdownTimeout
string
`mapstructure:"shutdown_timeout"`
bootWait
time
.
Duration
``
shutdownTimeout
time
.
Duration
``
tpl
*
packer
.
ConfigTemplate
}
...
...
@@ -83,6 +81,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
errs
:=
common
.
CheckUnusedConfig
(
md
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
b
.
config
.
OutputConfig
.
Prepare
(
b
.
config
.
tpl
,
&
b
.
config
.
PackerConfig
)
...
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
b
.
config
.
RunConfig
.
Prepare
(
b
.
config
.
tpl
)
...
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
b
.
config
.
SSHConfig
.
Prepare
(
b
.
config
.
tpl
)
...
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
b
.
config
.
VMXConfig
.
Prepare
(
b
.
config
.
tpl
)
...
)
warnings
:=
make
([]
string
,
0
)
...
...
@@ -124,10 +123,6 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
b
.
config
.
HTTPPortMax
=
9000
}
if
b
.
config
.
RawBootWait
==
""
{
b
.
config
.
RawBootWait
=
"10s"
}
if
b
.
config
.
VNCPortMin
==
0
{
b
.
config
.
VNCPortMin
=
5900
}
...
...
@@ -163,7 +158,6 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
"shutdown_command"
:
&
b
.
config
.
ShutdownCommand
,
"tools_upload_flavor"
:
&
b
.
config
.
ToolsUploadFlavor
,
"vm_name"
:
&
b
.
config
.
VMName
,
"boot_wait"
:
&
b
.
config
.
RawBootWait
,
"shutdown_timeout"
:
&
b
.
config
.
RawShutdownTimeout
,
"vmx_template_path"
:
&
b
.
config
.
VMXTemplatePath
,
"remote_type"
:
&
b
.
config
.
RemoteType
,
...
...
@@ -250,14 +244,6 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
}
}
if
b
.
config
.
RawBootWait
!=
""
{
b
.
config
.
bootWait
,
err
=
time
.
ParseDuration
(
b
.
config
.
RawBootWait
)
if
err
!=
nil
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"Failed parsing boot_wait: %s"
,
err
))
}
}
if
b
.
config
.
RawShutdownTimeout
==
""
{
b
.
config
.
RawShutdownTimeout
=
"5m"
}
...
...
@@ -365,7 +351,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
&
stepConfigureVNC
{},
&
StepRegister
{},
&
vmwcommon
.
StepRun
{
BootWait
:
b
.
config
.
b
ootWait
,
BootWait
:
b
.
config
.
B
ootWait
,
DurationBeforeStop
:
5
*
time
.
Second
,
Headless
:
b
.
config
.
Headless
,
},
...
...
builder/vmware/iso/builder_test.go
View file @
e11f655d
...
...
@@ -29,46 +29,6 @@ func TestBuilder_ImplementsBuilder(t *testing.T) {
}
}
func
TestBuilderPrepare_BootWait
(
t
*
testing
.
T
)
{
var
b
Builder
config
:=
testConfig
()
// Test a default boot_wait
delete
(
config
,
"boot_wait"
)
warns
,
err
:=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
if
b
.
config
.
RawBootWait
!=
"10s"
{
t
.
Fatalf
(
"bad value: %s"
,
b
.
config
.
RawBootWait
)
}
// Test with a bad boot_wait
config
[
"boot_wait"
]
=
"this is not good"
warns
,
err
=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
==
nil
{
t
.
Fatal
(
"should have error"
)
}
// Test with a good one
config
[
"boot_wait"
]
=
"5s"
b
=
Builder
{}
warns
,
err
=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
!=
nil
{
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
}
func
TestBuilderPrepare_ISOChecksum
(
t
*
testing
.
T
)
{
var
b
Builder
config
:=
testConfig
()
...
...
builder/vmware/vmx/builder.go
View file @
e11f655d
...
...
@@ -3,11 +3,13 @@ package vmx
import
(
"errors"
"fmt"
"log"
"time"
"github.com/mitchellh/multistep"
vmwcommon
"github.com/mitchellh/packer/builder/vmware/common"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/packer"
"log"
)
// Builder implements packer.Builder and builds the actual VirtualBox
...
...
@@ -62,6 +64,11 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
CustomData
:
b
.
config
.
VMXData
,
},
&
vmwcommon
.
StepSuppressMessages
{},
&
vmwcommon
.
StepRun
{
BootWait
:
b
.
config
.
BootWait
,
DurationBeforeStop
:
5
*
time
.
Second
,
Headless
:
b
.
config
.
Headless
,
},
}
// Run the steps.
...
...
builder/vmware/vmx/config.go
View file @
e11f655d
...
...
@@ -13,6 +13,7 @@ import (
type
Config
struct
{
common
.
PackerConfig
`mapstructure:",squash"`
vmwcommon
.
OutputConfig
`mapstructure:",squash"`
vmwcommon
.
RunConfig
`mapstructure:",squash"`
vmwcommon
.
SSHConfig
`mapstructure:",squash"`
vmwcommon
.
VMXConfig
`mapstructure:",squash"`
...
...
@@ -43,6 +44,7 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
// Prepare the errors
errs
:=
common
.
CheckUnusedConfig
(
md
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
c
.
OutputConfig
.
Prepare
(
c
.
tpl
,
&
c
.
PackerConfig
)
...
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
c
.
RunConfig
.
Prepare
(
c
.
tpl
)
...
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
c
.
SSHConfig
.
Prepare
(
c
.
tpl
)
...
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
c
.
VMXConfig
.
Prepare
(
c
.
tpl
)
...
)
...
...
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