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
141cfeb4
Commit
141cfeb4
authored
Dec 25, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/vmware/vmx: outputdir
parent
6fdcb0f8
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
151 additions
and
19 deletions
+151
-19
builder/vmware/common/output_config.go
builder/vmware/common/output_config.go
+40
-0
builder/vmware/common/output_config_test.go
builder/vmware/common/output_config_test.go
+65
-0
builder/vmware/iso/builder.go
builder/vmware/iso/builder.go
+5
-16
builder/vmware/vmx/builder.go
builder/vmware/vmx/builder.go
+10
-1
builder/vmware/vmx/config.go
builder/vmware/vmx/config.go
+4
-2
builder/vmware/vmx/config_test.go
builder/vmware/vmx/config_test.go
+27
-0
No files found.
builder/vmware/common/output_config.go
0 → 100644
View file @
141cfeb4
package
common
import
(
"fmt"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/packer"
"os"
)
type
OutputConfig
struct
{
OutputDir
string
`mapstructure:"output_directory"`
}
func
(
c
*
OutputConfig
)
Prepare
(
t
*
packer
.
ConfigTemplate
,
pc
*
common
.
PackerConfig
)
[]
error
{
if
c
.
OutputDir
==
""
{
c
.
OutputDir
=
fmt
.
Sprintf
(
"output-%s"
,
pc
.
PackerBuildName
)
}
templates
:=
map
[
string
]
*
string
{
"output_directory"
:
&
c
.
OutputDir
,
}
errs
:=
make
([]
error
,
0
)
for
n
,
ptr
:=
range
templates
{
var
err
error
*
ptr
,
err
=
t
.
Process
(
*
ptr
,
nil
)
if
err
!=
nil
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"Error processing %s: %s"
,
n
,
err
))
}
}
if
!
pc
.
PackerForce
{
if
_
,
err
:=
os
.
Stat
(
c
.
OutputDir
);
err
==
nil
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"Output directory '%s' already exists. It must not exist."
,
c
.
OutputDir
))
}
}
return
errs
}
builder/vmware/common/output_config_test.go
0 → 100644
View file @
141cfeb4
package
common
import
(
"github.com/mitchellh/packer/common"
"io/ioutil"
"os"
"testing"
)
func
TestOutputConfigPrepare
(
t
*
testing
.
T
)
{
c
:=
new
(
OutputConfig
)
if
c
.
OutputDir
!=
""
{
t
.
Fatalf
(
"what: %s"
,
c
.
OutputDir
)
}
pc
:=
&
common
.
PackerConfig
{
PackerBuildName
:
"foo"
}
errs
:=
c
.
Prepare
(
testConfigTemplate
(
t
),
pc
)
if
len
(
errs
)
>
0
{
t
.
Fatalf
(
"err: %#v"
,
errs
)
}
if
c
.
OutputDir
==
""
{
t
.
Fatal
(
"should have output dir"
)
}
}
func
TestOutputConfigPrepare_exists
(
t
*
testing
.
T
)
{
td
,
err
:=
ioutil
.
TempDir
(
""
,
"packer"
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
defer
os
.
RemoveAll
(
td
)
c
:=
new
(
OutputConfig
)
c
.
OutputDir
=
td
pc
:=
&
common
.
PackerConfig
{
PackerBuildName
:
"foo"
,
PackerForce
:
false
,
}
errs
:=
c
.
Prepare
(
testConfigTemplate
(
t
),
pc
)
if
len
(
errs
)
==
0
{
t
.
Fatal
(
"should have errors"
)
}
}
func
TestOutputConfigPrepare_forceExists
(
t
*
testing
.
T
)
{
td
,
err
:=
ioutil
.
TempDir
(
""
,
"packer"
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
defer
os
.
RemoveAll
(
td
)
c
:=
new
(
OutputConfig
)
c
.
OutputDir
=
td
pc
:=
&
common
.
PackerConfig
{
PackerBuildName
:
"foo"
,
PackerForce
:
true
,
}
errs
:=
c
.
Prepare
(
testConfigTemplate
(
t
),
pc
)
if
len
(
errs
)
>
0
{
t
.
Fatal
(
"should not have errors"
)
}
}
builder/vmware/iso/builder.go
View file @
141cfeb4
...
...
@@ -24,8 +24,9 @@ type Builder struct {
}
type
config
struct
{
common
.
PackerConfig
`mapstructure:",squash"`
vmwcommon
.
SSHConfig
`mapstructure:",squash"`
common
.
PackerConfig
`mapstructure:",squash"`
vmwcommon
.
OutputConfig
`mapstructure:",squash"`
vmwcommon
.
SSHConfig
`mapstructure:",squash"`
DiskName
string
`mapstructure:"vmdk_name"`
DiskSize
uint
`mapstructure:"disk_size"`
...
...
@@ -36,7 +37,6 @@ type config struct {
ISOChecksumType
string
`mapstructure:"iso_checksum_type"`
ISOUrls
[]
string
`mapstructure:"iso_urls"`
VMName
string
`mapstructure:"vm_name"`
OutputDir
string
`mapstructure:"output_directory"`
Headless
bool
`mapstructure:"headless"`
HTTPDir
string
`mapstructure:"http_directory"`
HTTPPortMin
uint
`mapstructure:"http_port_min"`
...
...
@@ -81,6 +81,8 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
// Accumulate any errors
errs
:=
common
.
CheckUnusedConfig
(
md
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
b
.
config
.
OutputConfig
.
Prepare
(
b
.
config
.
tpl
,
&
b
.
config
.
PackerConfig
)
...
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
b
.
config
.
SSHConfig
.
Prepare
(
b
.
config
.
tpl
)
...
)
warnings
:=
make
([]
string
,
0
)
...
...
@@ -133,10 +135,6 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
b
.
config
.
VNCPortMax
=
6000
}
if
b
.
config
.
OutputDir
==
""
{
b
.
config
.
OutputDir
=
fmt
.
Sprintf
(
"output-%s"
,
b
.
config
.
PackerBuildName
)
}
if
b
.
config
.
RemoteUser
==
""
{
b
.
config
.
RemoteUser
=
"root"
}
...
...
@@ -161,7 +159,6 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
"iso_checksum"
:
&
b
.
config
.
ISOChecksum
,
"iso_checksum_type"
:
&
b
.
config
.
ISOChecksumType
,
"iso_url"
:
&
b
.
config
.
RawSingleISOUrl
,
"output_directory"
:
&
b
.
config
.
OutputDir
,
"shutdown_command"
:
&
b
.
config
.
ShutdownCommand
,
"tools_upload_flavor"
:
&
b
.
config
.
ToolsUploadFlavor
,
"vm_name"
:
&
b
.
config
.
VMName
,
...
...
@@ -273,14 +270,6 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
}
}
if
!
b
.
config
.
PackerForce
{
if
_
,
err
:=
os
.
Stat
(
b
.
config
.
OutputDir
);
err
==
nil
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"Output directory '%s' already exists. It must not exist."
,
b
.
config
.
OutputDir
))
}
}
if
b
.
config
.
RawBootWait
!=
""
{
b
.
config
.
bootWait
,
err
=
time
.
ParseDuration
(
b
.
config
.
RawBootWait
)
if
err
!=
nil
{
...
...
builder/vmware/vmx/builder.go
View file @
141cfeb4
...
...
@@ -36,15 +36,24 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
return
nil
,
fmt
.
Errorf
(
"Failed creating VMware driver: %s"
,
err
)
}
// Setup the directory
dir
:=
new
(
vmwcommon
.
LocalOutputDir
)
dir
.
SetOutputDir
(
b
.
config
.
OutputDir
)
// Set up the state.
state
:=
new
(
multistep
.
BasicStateBag
)
state
.
Put
(
"config"
,
b
.
config
)
state
.
Put
(
"dir"
,
dir
)
state
.
Put
(
"driver"
,
driver
)
state
.
Put
(
"hook"
,
hook
)
state
.
Put
(
"ui"
,
ui
)
// Build the steps.
steps
:=
[]
multistep
.
Step
{}
steps
:=
[]
multistep
.
Step
{
&
vmwcommon
.
StepOutputDir
{
Force
:
b
.
config
.
PackerForce
,
},
}
// Run the steps.
if
b
.
config
.
PackerDebug
{
...
...
builder/vmware/vmx/config.go
View file @
141cfeb4
...
...
@@ -10,8 +10,9 @@ import (
// Config is the configuration structure for the builder.
type
Config
struct
{
common
.
PackerConfig
`mapstructure:",squash"`
vmwcommon
.
SSHConfig
`mapstructure:",squash"`
common
.
PackerConfig
`mapstructure:",squash"`
vmwcommon
.
OutputConfig
`mapstructure:",squash"`
vmwcommon
.
SSHConfig
`mapstructure:",squash"`
tpl
*
packer
.
ConfigTemplate
}
...
...
@@ -33,6 +34,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
.
SSHConfig
.
Prepare
(
c
.
tpl
)
...
)
templates
:=
map
[
string
]
*
string
{}
...
...
builder/vmware/vmx/config_test.go
0 → 100644
View file @
141cfeb4
package
vmx
import
(
"testing"
)
func
testConfig
(
t
*
testing
.
T
)
map
[
string
]
interface
{}
{
return
map
[
string
]
interface
{}{}
}
func
testConfigErr
(
t
*
testing
.
T
,
warns
[]
string
,
err
error
)
{
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
==
nil
{
t
.
Fatal
(
"should error"
)
}
}
func
testConfigOk
(
t
*
testing
.
T
,
warns
[]
string
,
err
error
)
{
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
!=
nil
{
t
.
Fatalf
(
"bad: %s"
,
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