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
f82aa7c9
Commit
f82aa7c9
authored
Jul 01, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/vmware: tools_upload_flavor and path
/cc @smerrill
parent
46458190
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
120 additions
and
31 deletions
+120
-31
builder/vmware/builder.go
builder/vmware/builder.go
+33
-21
builder/vmware/builder_test.go
builder/vmware/builder_test.go
+30
-0
builder/vmware/driver.go
builder/vmware/driver.go
+4
-5
builder/vmware/step_prepare_tools.go
builder/vmware/step_prepare_tools.go
+33
-0
builder/vmware/step_upload_tools.go
builder/vmware/step_upload_tools.go
+20
-5
No files found.
builder/vmware/builder.go
View file @
f82aa7c9
...
...
@@ -13,6 +13,7 @@ import (
"os"
"path/filepath"
"strings"
"text/template"
"time"
)
...
...
@@ -25,27 +26,29 @@ type Builder struct {
}
type
config
struct
{
DiskName
string
`mapstructure:"vmdk_name"`
DiskSize
uint
`mapstructure:"disk_size"`
GuestOSType
string
`mapstructure:"guest_os_type"`
ISOMD5
string
`mapstructure:"iso_md5"`
ISOUrl
string
`mapstructure:"iso_url"`
VMName
string
`mapstructure:"vm_name"`
OutputDir
string
`mapstructure:"output_directory"`
HTTPDir
string
`mapstructure:"http_directory"`
HTTPPortMin
uint
`mapstructure:"http_port_min"`
HTTPPortMax
uint
`mapstructure:"http_port_max"`
BootCommand
[]
string
`mapstructure:"boot_command"`
BootWait
time
.
Duration
``
ShutdownCommand
string
`mapstructure:"shutdown_command"`
ShutdownTimeout
time
.
Duration
``
SSHUser
string
`mapstructure:"ssh_username"`
SSHPassword
string
`mapstructure:"ssh_password"`
SSHPort
uint
`mapstructure:"ssh_port"`
SSHWaitTimeout
time
.
Duration
``
VMXData
map
[
string
]
string
`mapstructure:"vmx_data"`
VNCPortMin
uint
`mapstructure:"vnc_port_min"`
VNCPortMax
uint
`mapstructure:"vnc_port_max"`
DiskName
string
`mapstructure:"vmdk_name"`
DiskSize
uint
`mapstructure:"disk_size"`
GuestOSType
string
`mapstructure:"guest_os_type"`
ISOMD5
string
`mapstructure:"iso_md5"`
ISOUrl
string
`mapstructure:"iso_url"`
VMName
string
`mapstructure:"vm_name"`
OutputDir
string
`mapstructure:"output_directory"`
HTTPDir
string
`mapstructure:"http_directory"`
HTTPPortMin
uint
`mapstructure:"http_port_min"`
HTTPPortMax
uint
`mapstructure:"http_port_max"`
BootCommand
[]
string
`mapstructure:"boot_command"`
BootWait
time
.
Duration
``
ShutdownCommand
string
`mapstructure:"shutdown_command"`
ShutdownTimeout
time
.
Duration
``
SSHUser
string
`mapstructure:"ssh_username"`
SSHPassword
string
`mapstructure:"ssh_password"`
SSHPort
uint
`mapstructure:"ssh_port"`
SSHWaitTimeout
time
.
Duration
``
ToolsUploadFlavor
string
`mapstructure:"tools_upload_flavor"`
ToolsUploadPath
string
`mapstructure:"tools_upload_path"`
VMXData
map
[
string
]
string
`mapstructure:"vmx_data"`
VNCPortMin
uint
`mapstructure:"vnc_port_min"`
VNCPortMax
uint
`mapstructure:"vnc_port_max"`
PackerDebug
bool
`mapstructure:"packer_debug"`
...
...
@@ -106,6 +109,10 @@ func (b *Builder) Prepare(raws ...interface{}) error {
b
.
config
.
SSHPort
=
22
}
if
b
.
config
.
ToolsUploadPath
==
""
{
b
.
config
.
ToolsUploadPath
=
"{{ .Flavor }}.iso"
}
// Accumulate any errors
var
err
error
errs
:=
make
([]
error
,
0
)
...
...
@@ -192,6 +199,10 @@ func (b *Builder) Prepare(raws ...interface{}) error {
errs
=
append
(
errs
,
fmt
.
Errorf
(
"Failed parsing ssh_wait_timeout: %s"
,
err
))
}
if
_
,
err
:=
template
.
New
(
"path"
)
.
Parse
(
b
.
config
.
ToolsUploadPath
);
err
!=
nil
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"tools_upload_path invalid: %s"
,
err
))
}
if
b
.
config
.
VNCPortMin
>
b
.
config
.
VNCPortMax
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"vnc_port_min must be less than vnc_port_max"
))
}
...
...
@@ -213,6 +224,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
rand
.
Seed
(
time
.
Now
()
.
UTC
()
.
UnixNano
())
steps
:=
[]
multistep
.
Step
{
&
stepPrepareTools
{},
&
stepDownloadISO
{},
&
stepPrepareOutputDir
{},
&
stepCreateDisk
{},
...
...
builder/vmware/builder_test.go
View file @
f82aa7c9
...
...
@@ -309,6 +309,36 @@ func TestBuilderPrepare_SSHWaitTimeout(t *testing.T) {
}
}
func
TestBuilderPrepare_ToolsUploadPath
(
t
*
testing
.
T
)
{
var
b
Builder
config
:=
testConfig
()
// Test a default
delete
(
config
,
"tools_upload_path"
)
err
:=
b
.
Prepare
(
config
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
if
b
.
config
.
ToolsUploadPath
==
""
{
t
.
Fatalf
(
"bad value: %s"
,
b
.
config
.
ToolsUploadPath
)
}
// Test with a bad value
config
[
"tools_upload_path"
]
=
"{{{nope}"
err
=
b
.
Prepare
(
config
)
if
err
==
nil
{
t
.
Fatal
(
"should have error"
)
}
// Test with a good one
config
[
"tools_upload_path"
]
=
"hey"
err
=
b
.
Prepare
(
config
)
if
err
!=
nil
{
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
}
func
TestBuilderPrepare_VNCPort
(
t
*
testing
.
T
)
{
var
b
Builder
config
:=
testConfig
()
...
...
builder/vmware/driver.go
View file @
f82aa7c9
...
...
@@ -24,8 +24,8 @@ type Driver interface {
// Stop stops a VM specified by the path to the VMX given.
Stop
(
string
)
error
// Get the path to the VMware ISO.
ToolsIsoPath
()
string
// Get the path to the VMware ISO
for the given flavor
.
ToolsIsoPath
(
string
)
string
// Verify checks to make sure that this driver should function
// properly. This should check that all the files it will use
...
...
@@ -124,9 +124,8 @@ func (d *Fusion5Driver) vmrunPath() string {
return
filepath
.
Join
(
d
.
AppPath
,
"Contents"
,
"Library"
,
"vmrun"
)
}
// @TODO: Be smarter about guest type before deciding on linux.iso.
func
(
d
*
Fusion5Driver
)
ToolsIsoPath
()
string
{
return
filepath
.
Join
(
d
.
AppPath
,
"Contents"
,
"Library"
,
"isoimages"
,
"linux.iso"
)
func
(
d
*
Fusion5Driver
)
ToolsIsoPath
(
k
string
)
string
{
return
filepath
.
Join
(
d
.
AppPath
,
"Contents"
,
"Library"
,
"isoimages"
,
k
+
".iso"
)
}
func
(
d
*
Fusion5Driver
)
runAndLog
(
cmd
*
exec
.
Cmd
)
(
string
,
string
,
error
)
{
...
...
builder/vmware/step_prepare_tools.go
0 → 100644
View file @
f82aa7c9
package
vmware
import
(
"fmt"
"github.com/mitchellh/multistep"
"os"
)
type
stepPrepareTools
struct
{}
func
(
*
stepPrepareTools
)
Run
(
state
map
[
string
]
interface
{})
multistep
.
StepAction
{
config
:=
state
[
"config"
]
.
(
*
config
)
driver
:=
state
[
"driver"
]
.
(
Driver
)
if
config
.
ToolsUploadFlavor
==
""
{
return
multistep
.
ActionContinue
}
path
:=
driver
.
ToolsIsoPath
(
config
.
ToolsUploadFlavor
)
if
_
,
err
:=
os
.
Stat
(
path
);
err
!=
nil
{
state
[
"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."
,
config
.
ToolsUploadFlavor
)
return
multistep
.
ActionHalt
}
state
[
"tools_upload_source"
]
=
path
return
multistep
.
ActionContinue
}
func
(
*
stepPrepareTools
)
Cleanup
(
map
[
string
]
interface
{})
{}
builder/vmware/step_upload_tools.go
View file @
f82aa7c9
package
vmware
import
(
"bytes"
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"os"
"text/template"
)
type
toolsUploadPathTemplate
struct
{
Flavor
string
}
type
stepUploadTools
struct
{}
func
(
*
stepUploadTools
)
Run
(
state
map
[
string
]
interface
{})
multistep
.
StepAction
{
config
:=
state
[
"config"
]
.
(
*
config
)
if
config
.
ToolsUploadFlavor
==
""
{
return
multistep
.
ActionContinue
}
comm
:=
state
[
"communicator"
]
.
(
packer
.
Communicator
)
tools_source
:=
state
[
"tools_upload_source"
]
.
(
string
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
driver
:=
state
[
"driver"
]
.
(
Driver
)
ui
.
Say
(
"Uploading the VMware Tools."
)
f
,
err
:=
os
.
Open
(
driver
.
ToolsIsoPath
())
ui
.
Say
(
fmt
.
Sprintf
(
"Uploading the '%s' VMware Tools"
,
config
.
ToolsUploadFlavor
))
f
,
err
:=
os
.
Open
(
tools_source
)
if
err
!=
nil
{
state
[
"error"
]
=
fmt
.
Errorf
(
"Error opening VMware Tools ISO: %s"
,
err
)
return
multistep
.
ActionHalt
}
defer
f
.
Close
()
if
err
:=
comm
.
Upload
(
"/tmp/linux.iso"
,
f
);
err
!=
nil
{
tplData
:=
&
toolsUploadPathTemplate
{
Flavor
:
config
.
ToolsUploadFlavor
}
var
processedPath
bytes
.
Buffer
t
:=
template
.
Must
(
template
.
New
(
"path"
)
.
Parse
(
config
.
ToolsUploadPath
))
t
.
Execute
(
&
processedPath
,
tplData
)
if
err
:=
comm
.
Upload
(
processedPath
.
String
(),
f
);
err
!=
nil
{
state
[
"error"
]
=
fmt
.
Errorf
(
"Error uploading VMware Tools: %s"
,
err
)
return
multistep
.
ActionHalt
}
...
...
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