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
8bb5d405
Commit
8bb5d405
authored
Aug 08, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/vmware: use new template stuff
parent
191520bc
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
82 additions
and
13 deletions
+82
-13
builder/vmware/builder.go
builder/vmware/builder.go
+72
-0
builder/vmware/step_type_boot_command.go
builder/vmware/step_type_boot_command.go
+8
-6
builder/vmware/step_upload_tools.go
builder/vmware/step_upload_tools.go
+2
-7
No files found.
builder/vmware/builder.go
View file @
8bb5d405
...
...
@@ -58,6 +58,7 @@ type config struct {
bootWait
time
.
Duration
``
shutdownTimeout
time
.
Duration
``
sshWaitTimeout
time
.
Duration
``
tpl
*
common
.
Template
}
func
(
b
*
Builder
)
Prepare
(
raws
...
interface
{})
error
{
...
...
@@ -66,6 +67,11 @@ func (b *Builder) Prepare(raws ...interface{}) error {
return
err
}
b
.
config
.
tpl
,
err
=
common
.
NewTemplate
()
if
err
!=
nil
{
return
err
}
// Accumulate any errors
errs
:=
common
.
CheckUnusedConfig
(
md
)
...
...
@@ -121,6 +127,72 @@ func (b *Builder) Prepare(raws ...interface{}) error {
b
.
config
.
ToolsUploadPath
=
"{{ .Flavor }}.iso"
}
// Errors
templates
:=
map
[
string
]
*
string
{
"disk_name"
:
&
b
.
config
.
DiskName
,
"guest_os_type"
:
&
b
.
config
.
GuestOSType
,
"http_directory"
:
&
b
.
config
.
HTTPDir
,
"iso_checksum"
:
&
b
.
config
.
ISOChecksum
,
"iso_checksum_type"
:
&
b
.
config
.
ISOChecksumType
,
"iso_url"
:
&
b
.
config
.
ISOUrl
,
"output_directory"
:
&
b
.
config
.
OutputDir
,
"shutdown_command"
:
&
b
.
config
.
ShutdownCommand
,
"ssh_password"
:
&
b
.
config
.
SSHPassword
,
"ssh_username"
:
&
b
.
config
.
SSHUser
,
"tools_upload_flavor"
:
&
b
.
config
.
ToolsUploadFlavor
,
"vm_name"
:
&
b
.
config
.
VMName
,
"boot_wait"
:
&
b
.
config
.
RawBootWait
,
"shutdown_timeout"
:
&
b
.
config
.
RawShutdownTimeout
,
"ssh_wait_timeout"
:
&
b
.
config
.
RawSSHWaitTimeout
,
}
for
n
,
ptr
:=
range
templates
{
var
err
error
*
ptr
,
err
=
b
.
config
.
tpl
.
Process
(
*
ptr
,
nil
)
if
err
!=
nil
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"Error processing %s: %s"
,
n
,
err
))
}
}
for
i
,
command
:=
range
b
.
config
.
BootCommand
{
if
err
:=
b
.
config
.
tpl
.
Validate
(
command
);
err
!=
nil
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"Error processing boot_command[%d]: %s"
,
i
,
err
))
}
}
for
i
,
file
:=
range
b
.
config
.
FloppyFiles
{
var
err
error
b
.
config
.
FloppyFiles
[
i
],
err
=
b
.
config
.
tpl
.
Process
(
file
,
nil
)
if
err
!=
nil
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"Error processing floppy_files[%d]: %s"
,
i
,
err
))
}
}
newVMXData
:=
make
(
map
[
string
]
string
)
for
k
,
v
:=
range
b
.
config
.
VMXData
{
k
,
err
=
b
.
config
.
tpl
.
Process
(
k
,
nil
)
if
err
!=
nil
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"Error processing VMX data key %s: %s"
,
k
,
err
))
continue
}
v
,
err
=
b
.
config
.
tpl
.
Process
(
v
,
nil
)
if
err
!=
nil
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"Error processing VMX data value '%s': %s"
,
v
,
err
))
continue
}
newVMXData
[
k
]
=
v
}
b
.
config
.
VMXData
=
newVMXData
if
b
.
config
.
HTTPPortMin
>
b
.
config
.
HTTPPortMax
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
errors
.
New
(
"http_port_min must be less than http_port_max"
))
...
...
builder/vmware/step_type_boot_command.go
View file @
8bb5d405
package
vmware
import
(
"bytes"
"fmt"
"github.com/mitchellh/go-vnc"
"github.com/mitchellh/multistep"
...
...
@@ -10,7 +9,6 @@ import (
"net"
"runtime"
"strings"
"text/template"
"time"
"unicode"
"unicode/utf8"
...
...
@@ -90,11 +88,15 @@ func (s *stepTypeBootCommand) Run(state map[string]interface{}) multistep.StepAc
ui
.
Say
(
"Typing the boot command over VNC..."
)
for
_
,
command
:=
range
config
.
BootCommand
{
var
buf
bytes
.
Buffer
t
:=
template
.
Must
(
template
.
New
(
"boot"
)
.
Parse
(
command
))
t
.
Execute
(
&
buf
,
tplData
)
command
,
err
:=
config
.
tpl
.
Process
(
command
,
tplData
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error preparing boot command: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
vncSendString
(
c
,
buf
.
String
()
)
vncSendString
(
c
,
command
)
}
return
multistep
.
ActionContinue
...
...
builder/vmware/step_upload_tools.go
View file @
8bb5d405
package
vmware
import
(
"bytes"
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"os"
"text/template"
)
type
toolsUploadPathTemplate
struct
{
...
...
@@ -34,11 +32,8 @@ func (*stepUploadTools) Run(state map[string]interface{}) multistep.StepAction {
defer
f
.
Close
()
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
{
config
.
ToolsUploadPath
,
err
=
config
.
tpl
.
Process
(
config
.
ToolsUploadPath
,
tplData
)
if
err
:=
comm
.
Upload
(
config
.
ToolsUploadPath
,
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