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
ba132396
Commit
ba132396
authored
May 09, 2014
by
Ross Smith II
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/vmware-vmx: Added tools_upload_flavor support
parent
c1cfd1da
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
124 additions
and
28 deletions
+124
-28
builder/vmware/common/step_prepare_tools.go
builder/vmware/common/step_prepare_tools.go
+40
-0
builder/vmware/common/step_upload_tools.go
builder/vmware/common/step_upload_tools.go
+18
-13
builder/vmware/common/tools_config.go
builder/vmware/common/tools_config.go
+38
-0
builder/vmware/iso/builder.go
builder/vmware/iso/builder.go
+13
-15
builder/vmware/vmx/builder.go
builder/vmware/vmx/builder.go
+11
-0
builder/vmware/vmx/config.go
builder/vmware/vmx/config.go
+4
-0
No files found.
builder/vmware/
iso
/step_prepare_tools.go
→
builder/vmware/
common
/step_prepare_tools.go
View file @
ba132396
package
iso
package
common
import
(
"fmt"
"github.com/mitchellh/multistep"
vmwcommon
"github.com/mitchellh/packer/builder/vmware/common"
"os"
)
type
stepPrepareTools
struct
{}
type
StepPrepareTools
struct
{
RemoteType
string
`mapstructure:"remote_type"`
ToolsUploadFlavor
string
`mapstructure:"tools_upload_flavor"`
ToolsUploadPath
string
`mapstructure:"tools_upload_path"`
}
func
(
*
stepPrepareTools
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
config
:=
state
.
Get
(
"config"
)
.
(
*
config
)
driver
:=
state
.
Get
(
"driver"
)
.
(
vmwcommon
.
Driver
)
func
(
c
*
StepPrepareTools
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
driver
:=
state
.
Get
(
"driver"
)
.
(
Driver
)
if
c
onfig
.
RemoteType
==
"esx5"
{
if
c
.
RemoteType
==
"esx5"
{
return
multistep
.
ActionContinue
}
if
c
onfig
.
ToolsUploadFlavor
==
""
{
if
c
.
ToolsUploadFlavor
==
""
{
return
multistep
.
ActionContinue
}
path
:=
driver
.
ToolsIsoPath
(
c
onfig
.
ToolsUploadFlavor
)
path
:=
driver
.
ToolsIsoPath
(
c
.
ToolsUploadFlavor
)
if
_
,
err
:=
os
.
Stat
(
path
);
err
!=
nil
{
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"Couldn't find VMware tools for '%s'! VMware often downloads these
\n
"
+
"tools on-demand. However, to do this, you need to create a fake VM
\n
"
+
"of the proper type then click the 'install tools' option in the
\n
"
+
"VMware GUI."
,
c
onfig
.
ToolsUploadFlavor
))
"VMware GUI."
,
c
.
ToolsUploadFlavor
))
return
multistep
.
ActionHalt
}
...
...
@@ -35,4 +37,4 @@ func (*stepPrepareTools) Run(state multistep.StateBag) multistep.StepAction {
return
multistep
.
ActionContinue
}
func
(
*
s
tepPrepareTools
)
Cleanup
(
multistep
.
StateBag
)
{}
func
(
c
*
S
tepPrepareTools
)
Cleanup
(
multistep
.
StateBag
)
{}
builder/vmware/
iso
/step_upload_tools.go
→
builder/vmware/
common
/step_upload_tools.go
View file @
ba132396
package
iso
package
common
import
(
"fmt"
"github.com/mitchellh/multistep"
vmwcommon
"github.com/mitchellh/packer/builder/vmware/common"
"github.com/mitchellh/packer/packer"
"os"
)
...
...
@@ -12,20 +11,24 @@ type toolsUploadPathTemplate struct {
Flavor
string
}
type
stepUploadTools
struct
{}
type
StepUploadTools
struct
{
RemoteType
string
`mapstructure:"remote_type"`
ToolsUploadFlavor
string
`mapstructure:"tools_upload_flavor"`
ToolsUploadPath
string
`mapstructure:"tools_upload_path"`
Tpl
*
packer
.
ConfigTemplate
}
func
(
*
stepUploadTools
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
config
:=
state
.
Get
(
"config"
)
.
(
*
config
)
driver
:=
state
.
Get
(
"driver"
)
.
(
vmwcommon
.
Driver
)
func
(
c
*
StepUploadTools
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
driver
:=
state
.
Get
(
"driver"
)
.
(
Driver
)
if
c
onfig
.
RemoteType
==
"esx5"
{
if
c
.
RemoteType
==
"esx5"
{
if
err
:=
driver
.
ToolsInstall
();
err
!=
nil
{
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"Couldn't mount VMware tools ISO."
))
}
return
multistep
.
ActionContinue
}
if
c
onfig
.
ToolsUploadFlavor
==
""
{
if
c
.
ToolsUploadFlavor
==
""
{
return
multistep
.
ActionContinue
}
...
...
@@ -33,7 +36,7 @@ func (*stepUploadTools) Run(state multistep.StateBag) multistep.StepAction {
tools_source
:=
state
.
Get
(
"tools_upload_source"
)
.
(
string
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
ui
.
Say
(
fmt
.
Sprintf
(
"Uploading the '%s' VMware Tools"
,
c
onfig
.
ToolsUploadFlavor
))
ui
.
Say
(
fmt
.
Sprintf
(
"Uploading the '%s' VMware Tools"
,
c
.
ToolsUploadFlavor
))
f
,
err
:=
os
.
Open
(
tools_source
)
if
err
!=
nil
{
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"Error opening VMware Tools ISO: %s"
,
err
))
...
...
@@ -41,8 +44,10 @@ func (*stepUploadTools) Run(state multistep.StateBag) multistep.StepAction {
}
defer
f
.
Close
()
tplData
:=
&
toolsUploadPathTemplate
{
Flavor
:
config
.
ToolsUploadFlavor
}
config
.
ToolsUploadPath
,
err
=
config
.
tpl
.
Process
(
config
.
ToolsUploadPath
,
tplData
)
tplData
:=
&
toolsUploadPathTemplate
{
Flavor
:
c
.
ToolsUploadFlavor
,
}
c
.
ToolsUploadPath
,
err
=
c
.
Tpl
.
Process
(
c
.
ToolsUploadPath
,
tplData
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error preparing upload path: %s"
,
err
)
state
.
Put
(
"error"
,
err
)
...
...
@@ -50,7 +55,7 @@ func (*stepUploadTools) Run(state multistep.StateBag) multistep.StepAction {
return
multistep
.
ActionHalt
}
if
err
:=
comm
.
Upload
(
c
onfig
.
ToolsUploadPath
,
f
);
err
!=
nil
{
if
err
:=
comm
.
Upload
(
c
.
ToolsUploadPath
,
f
);
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error uploading VMware Tools: %s"
,
err
)
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
...
...
@@ -60,4 +65,4 @@ func (*stepUploadTools) Run(state multistep.StateBag) multistep.StepAction {
return
multistep
.
ActionContinue
}
func
(
*
s
tepUploadTools
)
Cleanup
(
multistep
.
StateBag
)
{}
func
(
c
*
S
tepUploadTools
)
Cleanup
(
multistep
.
StateBag
)
{}
builder/vmware/common/tools_config.go
0 → 100644
View file @
ba132396
package
common
import
(
"fmt"
"text/template"
"github.com/mitchellh/packer/packer"
)
type
ToolsConfig
struct
{
ToolsUploadFlavor
string
`mapstructure:"tools_upload_flavor"`
ToolsUploadPath
string
`mapstructure:"tools_upload_path"`
}
func
(
c
*
ToolsConfig
)
Prepare
(
t
*
packer
.
ConfigTemplate
)
[]
error
{
if
c
.
ToolsUploadPath
==
""
{
c
.
ToolsUploadPath
=
"{{ .Flavor }}.iso"
}
templates
:=
map
[
string
]
*
string
{
"tools_upload_flavor"
:
&
c
.
ToolsUploadFlavor
,
}
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
_
,
err
:=
template
.
New
(
"path"
)
.
Parse
(
c
.
ToolsUploadPath
);
err
!=
nil
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"tools_upload_path invalid: %s"
,
err
))
}
return
errs
}
builder/vmware/iso/builder.go
View file @
ba132396
...
...
@@ -12,7 +12,6 @@ import (
"math/rand"
"os"
"strings"
"text/template"
"time"
)
...
...
@@ -30,6 +29,7 @@ type config struct {
vmwcommon
.
RunConfig
`mapstructure:",squash"`
vmwcommon
.
ShutdownConfig
`mapstructure:",squash"`
vmwcommon
.
SSHConfig
`mapstructure:",squash"`
vmwcommon
.
ToolsConfig
`mapstructure:",squash"`
vmwcommon
.
VMXConfig
`mapstructure:",squash"`
DiskName
string
`mapstructure:"vmdk_name"`
...
...
@@ -46,8 +46,6 @@ type config struct {
HTTPPortMax
uint
`mapstructure:"http_port_max"`
BootCommand
[]
string
`mapstructure:"boot_command"`
SkipCompaction
bool
`mapstructure:"skip_compaction"`
ToolsUploadFlavor
string
`mapstructure:"tools_upload_flavor"`
ToolsUploadPath
string
`mapstructure:"tools_upload_path"`
VMXTemplatePath
string
`mapstructure:"vmx_template_path"`
VNCPortMin
uint
`mapstructure:"vnc_port_min"`
VNCPortMax
uint
`mapstructure:"vnc_port_max"`
...
...
@@ -84,6 +82,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
errs
=
packer
.
MultiErrorAppend
(
errs
,
b
.
config
.
RunConfig
.
Prepare
(
b
.
config
.
tpl
)
...
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
b
.
config
.
ShutdownConfig
.
Prepare
(
b
.
config
.
tpl
)
...
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
b
.
config
.
SSHConfig
.
Prepare
(
b
.
config
.
tpl
)
...
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
b
.
config
.
ToolsConfig
.
Prepare
(
b
.
config
.
tpl
)
...
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
b
.
config
.
VMXConfig
.
Prepare
(
b
.
config
.
tpl
)
...
)
warnings
:=
make
([]
string
,
0
)
...
...
@@ -144,10 +143,6 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
b
.
config
.
RemotePort
=
22
}
if
b
.
config
.
ToolsUploadPath
==
""
{
b
.
config
.
ToolsUploadPath
=
"{{ .Flavor }}.iso"
}
// Errors
templates
:=
map
[
string
]
*
string
{
"disk_name"
:
&
b
.
config
.
DiskName
,
...
...
@@ -156,7 +151,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
,
"tools_upload_flavor"
:
&
b
.
config
.
ToolsUploadFlavor
,
"vm_name"
:
&
b
.
config
.
VMName
,
"vmx_template_path"
:
&
b
.
config
.
VMXTemplatePath
,
"remote_type"
:
&
b
.
config
.
RemoteType
,
...
...
@@ -245,11 +239,6 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
}
}
if
_
,
err
:=
template
.
New
(
"path"
)
.
Parse
(
b
.
config
.
ToolsUploadPath
);
err
!=
nil
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"tools_upload_path invalid: %s"
,
err
))
}
if
b
.
config
.
VMXTemplatePath
!=
""
{
if
err
:=
b
.
validateVMXTemplatePath
();
err
!=
nil
{
errs
=
packer
.
MultiErrorAppend
(
...
...
@@ -320,7 +309,11 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
rand
.
Seed
(
time
.
Now
()
.
UTC
()
.
UnixNano
())
steps
:=
[]
multistep
.
Step
{
&
stepPrepareTools
{},
&
vmwcommon
.
StepPrepareTools
{
RemoteType
:
b
.
config
.
RemoteType
,
ToolsUploadFlavor
:
b
.
config
.
ToolsUploadFlavor
,
ToolsUploadPath
:
b
.
config
.
ToolsUploadPath
,
},
&
common
.
StepDownload
{
Checksum
:
b
.
config
.
ISOChecksum
,
ChecksumType
:
b
.
config
.
ISOChecksumType
,
...
...
@@ -363,7 +356,12 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
SSHWaitTimeout
:
b
.
config
.
SSHWaitTimeout
,
NoPty
:
b
.
config
.
SSHSkipRequestPty
,
},
&
stepUploadTools
{},
&
vmwcommon
.
StepUploadTools
{
RemoteType
:
b
.
config
.
RemoteType
,
ToolsUploadFlavor
:
b
.
config
.
ToolsUploadFlavor
,
ToolsUploadPath
:
b
.
config
.
ToolsUploadPath
,
Tpl
:
b
.
config
.
tpl
,
},
&
common
.
StepProvision
{},
&
vmwcommon
.
StepShutdown
{
Command
:
b
.
config
.
ShutdownCommand
,
...
...
builder/vmware/vmx/builder.go
View file @
ba132396
...
...
@@ -52,6 +52,11 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
// Build the steps.
steps
:=
[]
multistep
.
Step
{
&
vmwcommon
.
StepPrepareTools
{
RemoteType
:
b
.
config
.
RemoteType
,
ToolsUploadFlavor
:
b
.
config
.
ToolsUploadFlavor
,
ToolsUploadPath
:
b
.
config
.
ToolsUploadPath
,
},
&
vmwcommon
.
StepOutputDir
{
Force
:
b
.
config
.
PackerForce
,
},
...
...
@@ -78,6 +83,12 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
SSHWaitTimeout
:
b
.
config
.
SSHWaitTimeout
,
NoPty
:
b
.
config
.
SSHSkipRequestPty
,
},
&
vmwcommon
.
StepUploadTools
{
RemoteType
:
b
.
config
.
RemoteType
,
ToolsUploadFlavor
:
b
.
config
.
ToolsUploadFlavor
,
ToolsUploadPath
:
b
.
config
.
ToolsUploadPath
,
Tpl
:
b
.
config
.
tpl
,
},
&
common
.
StepProvision
{},
&
vmwcommon
.
StepShutdown
{
Command
:
b
.
config
.
ShutdownCommand
,
...
...
builder/vmware/vmx/config.go
View file @
ba132396
...
...
@@ -17,9 +17,11 @@ type Config struct {
vmwcommon
.
RunConfig
`mapstructure:",squash"`
vmwcommon
.
ShutdownConfig
`mapstructure:",squash"`
vmwcommon
.
SSHConfig
`mapstructure:",squash"`
vmwcommon
.
ToolsConfig
`mapstructure:",squash"`
vmwcommon
.
VMXConfig
`mapstructure:",squash"`
FloppyFiles
[]
string
`mapstructure:"floppy_files"`
RemoteType
string
`mapstructure:"remote_type"`
SkipCompaction
bool
`mapstructure:"skip_compaction"`
SourcePath
string
`mapstructure:"source_path"`
VMName
string
`mapstructure:"vm_name"`
...
...
@@ -52,9 +54,11 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
errs
=
packer
.
MultiErrorAppend
(
errs
,
c
.
RunConfig
.
Prepare
(
c
.
tpl
)
...
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
c
.
ShutdownConfig
.
Prepare
(
c
.
tpl
)
...
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
c
.
SSHConfig
.
Prepare
(
c
.
tpl
)
...
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
c
.
ToolsConfig
.
Prepare
(
c
.
tpl
)
...
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
c
.
VMXConfig
.
Prepare
(
c
.
tpl
)
...
)
templates
:=
map
[
string
]
*
string
{
"remote_type"
:
&
c
.
RemoteType
,
"source_path"
:
&
c
.
SourcePath
,
"vm_name"
:
&
c
.
VMName
,
}
...
...
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