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
fd42a21f
Commit
fd42a21f
authored
Jun 07, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/vmware: support custom vmx data
parent
d3ea7956
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
24 deletions
+56
-24
builder/vmware/builder.go
builder/vmware/builder.go
+17
-16
builder/vmware/builder_test.go
builder/vmware/builder_test.go
+19
-0
builder/vmware/step_create_vmx.go
builder/vmware/step_create_vmx.go
+20
-8
No files found.
builder/vmware/builder.go
View file @
fd42a21f
...
@@ -21,22 +21,23 @@ type Builder struct {
...
@@ -21,22 +21,23 @@ type Builder struct {
}
}
type
config
struct
{
type
config
struct
{
DiskName
string
`mapstructure:"vmdk_name"`
DiskName
string
`mapstructure:"vmdk_name"`
ISOUrl
string
`mapstructure:"iso_url"`
ISOUrl
string
`mapstructure:"iso_url"`
VMName
string
`mapstructure:"vm_name"`
VMName
string
`mapstructure:"vm_name"`
OutputDir
string
`mapstructure:"output_directory"`
OutputDir
string
`mapstructure:"output_directory"`
HTTPDir
string
`mapstructure:"http_directory"`
HTTPDir
string
`mapstructure:"http_directory"`
HTTPPortMin
uint
`mapstructure:"http_port_min"`
HTTPPortMin
uint
`mapstructure:"http_port_min"`
HTTPPortMax
uint
`mapstructure:"http_port_max"`
HTTPPortMax
uint
`mapstructure:"http_port_max"`
BootCommand
[]
string
`mapstructure:"boot_command"`
BootCommand
[]
string
`mapstructure:"boot_command"`
BootWait
time
.
Duration
BootWait
time
.
Duration
``
ShutdownCommand
string
`mapstructure:"shutdown_command"`
ShutdownCommand
string
`mapstructure:"shutdown_command"`
ShutdownTimeout
time
.
Duration
ShutdownTimeout
time
.
Duration
``
SSHUser
string
`mapstructure:"ssh_username"`
SSHUser
string
`mapstructure:"ssh_username"`
SSHPassword
string
`mapstructure:"ssh_password"`
SSHPassword
string
`mapstructure:"ssh_password"`
SSHWaitTimeout
time
.
Duration
SSHWaitTimeout
time
.
Duration
``
VNCPortMin
uint
`mapstructure:"vnc_port_min"`
VMXData
map
[
string
]
string
`mapstructure:"vmx_data"`
VNCPortMax
uint
`mapstructure:"vnc_port_max"`
VNCPortMin
uint
`mapstructure:"vnc_port_min"`
VNCPortMax
uint
`mapstructure:"vnc_port_max"`
RawBootWait
string
`mapstructure:"boot_wait"`
RawBootWait
string
`mapstructure:"boot_wait"`
RawShutdownTimeout
string
`mapstructure:"shutdown_timeout"`
RawShutdownTimeout
string
`mapstructure:"shutdown_timeout"`
...
...
builder/vmware/builder_test.go
View file @
fd42a21f
...
@@ -193,3 +193,22 @@ func TestBuilderPrepare_VNCPort(t *testing.T) {
...
@@ -193,3 +193,22 @@ func TestBuilderPrepare_VNCPort(t *testing.T) {
t
.
Fatalf
(
"should not have error: %s"
,
err
)
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
}
}
}
func
TestBuilderPrepare_VMXData
(
t
*
testing
.
T
)
{
var
b
Builder
config
:=
testConfig
()
config
[
"vmx_data"
]
=
map
[
interface
{}]
interface
{}{
"one"
:
"foo"
,
"two"
:
"bar"
,
}
err
:=
b
.
Prepare
(
config
)
if
err
!=
nil
{
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
if
len
(
b
.
config
.
VMXData
)
!=
2
{
t
.
Fatal
(
"should have two items in VMXData"
)
}
}
builder/vmware/step_create_vmx.go
View file @
fd42a21f
package
vmware
package
vmware
import
(
import
(
"bytes"
"fmt"
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/packer"
"
os
"
"
log
"
"path/filepath"
"path/filepath"
"text/template"
"text/template"
)
)
...
@@ -30,12 +31,7 @@ func (stepCreateVMX) Run(state map[string]interface{}) multistep.StepAction {
...
@@ -30,12 +31,7 @@ func (stepCreateVMX) Run(state map[string]interface{}) multistep.StepAction {
config
:=
state
[
"config"
]
.
(
*
config
)
config
:=
state
[
"config"
]
.
(
*
config
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
vmxPath
:=
filepath
.
Join
(
config
.
OutputDir
,
config
.
VMName
+
".vmx"
)
ui
.
Say
(
"Building and writing VMX file"
)
f
,
err
:=
os
.
Create
(
vmxPath
)
if
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error creating VMX: %s"
,
err
))
return
multistep
.
ActionHalt
}
tplData
:=
&
vmxTemplateData
{
tplData
:=
&
vmxTemplateData
{
config
.
VMName
,
config
.
VMName
,
...
@@ -44,8 +40,24 @@ func (stepCreateVMX) Run(state map[string]interface{}) multistep.StepAction {
...
@@ -44,8 +40,24 @@ func (stepCreateVMX) Run(state map[string]interface{}) multistep.StepAction {
config
.
ISOUrl
,
config
.
ISOUrl
,
}
}
var
buf
bytes
.
Buffer
t
:=
template
.
Must
(
template
.
New
(
"vmx"
)
.
Parse
(
DefaultVMXTemplate
))
t
:=
template
.
Must
(
template
.
New
(
"vmx"
)
.
Parse
(
DefaultVMXTemplate
))
t
.
Execute
(
f
,
tplData
)
t
.
Execute
(
&
buf
,
tplData
)
vmxData
:=
ParseVMX
(
buf
.
String
())
if
config
.
VMXData
!=
nil
{
log
.
Println
(
"Setting custom VMX data..."
)
for
k
,
v
:=
range
config
.
VMXData
{
log
.
Printf
(
"Setting VMX: '%s' = '%s'"
,
k
,
v
)
vmxData
[
k
]
=
v
}
}
vmxPath
:=
filepath
.
Join
(
config
.
OutputDir
,
config
.
VMName
+
".vmx"
)
if
err
:=
WriteVMX
(
vmxPath
,
vmxData
);
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error creating VMX: %s"
,
err
))
return
multistep
.
ActionHalt
}
state
[
"vmx_path"
]
=
vmxPath
state
[
"vmx_path"
]
=
vmxPath
...
...
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