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
f74ff911
Commit
f74ff911
authored
Aug 31, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/vmware: new multistep API
parent
1a3620d7
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
127 additions
and
126 deletions
+127
-126
builder/vmware/builder.go
builder/vmware/builder.go
+9
-9
builder/vmware/ssh.go
builder/vmware/ssh.go
+7
-6
builder/vmware/step_clean_files.go
builder/vmware/step_clean_files.go
+5
-5
builder/vmware/step_clean_vmx.go
builder/vmware/step_clean_vmx.go
+8
-8
builder/vmware/step_compact_disk.go
builder/vmware/step_compact_disk.go
+7
-7
builder/vmware/step_configure_vnc.go
builder/vmware/step_configure_vnc.go
+9
-9
builder/vmware/step_create_disk.go
builder/vmware/step_create_disk.go
+7
-7
builder/vmware/step_create_vmx.go
builder/vmware/step_create_vmx.go
+11
-11
builder/vmware/step_http_server.go
builder/vmware/step_http_server.go
+6
-6
builder/vmware/step_prepare_output_dir.go
builder/vmware/step_prepare_output_dir.go
+9
-9
builder/vmware/step_prepare_tools.go
builder/vmware/step_prepare_tools.go
+7
-7
builder/vmware/step_run.go
builder/vmware/step_run.go
+10
-10
builder/vmware/step_shutdown.go
builder/vmware/step_shutdown.go
+12
-12
builder/vmware/step_type_boot_command.go
builder/vmware/step_type_boot_command.go
+11
-11
builder/vmware/step_upload_tools.go
builder/vmware/step_upload_tools.go
+9
-9
No files found.
builder/vmware/builder.go
View file @
f74ff911
...
...
@@ -376,12 +376,12 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
}
// Setup the state bag
state
:=
make
(
map
[
string
]
interface
{}
)
state
[
"cache"
]
=
cache
state
[
"config"
]
=
&
b
.
config
state
[
"driver"
]
=
driver
state
[
"hook"
]
=
hook
state
[
"ui"
]
=
ui
state
:=
new
(
multistep
.
BasicStateBag
)
state
.
Put
(
"cache"
,
cache
)
state
.
Put
(
"config"
,
&
b
.
config
)
state
.
Put
(
"driver"
,
driver
)
state
.
Put
(
"hook"
,
hook
)
state
.
Put
(
"ui"
,
ui
)
// Run!
if
b
.
config
.
PackerDebug
{
...
...
@@ -396,16 +396,16 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
b
.
runner
.
Run
(
state
)
// If there was an error, return that
if
rawErr
,
ok
:=
state
[
"error"
]
;
ok
{
if
rawErr
,
ok
:=
state
.
GetOk
(
"error"
)
;
ok
{
return
nil
,
rawErr
.
(
error
)
}
// If we were interrupted or cancelled, then just exit.
if
_
,
ok
:=
state
[
multistep
.
StateCancelled
]
;
ok
{
if
_
,
ok
:=
state
.
GetOk
(
multistep
.
StateCancelled
)
;
ok
{
return
nil
,
errors
.
New
(
"Build was cancelled."
)
}
if
_
,
ok
:=
state
[
multistep
.
StateHalted
]
;
ok
{
if
_
,
ok
:=
state
.
GetOk
(
multistep
.
StateHalted
)
;
ok
{
return
nil
,
errors
.
New
(
"Build was halted."
)
}
...
...
builder/vmware/ssh.go
View file @
f74ff911
...
...
@@ -4,16 +4,17 @@ import (
gossh
"code.google.com/p/go.crypto/ssh"
"errors"
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/communicator/ssh"
"io/ioutil"
"log"
"os"
)
func
sshAddress
(
state
m
ap
[
string
]
interface
{}
)
(
string
,
error
)
{
config
:=
state
[
"config"
]
.
(
*
config
)
driver
:=
state
[
"driver"
]
.
(
Driver
)
vmxPath
:=
state
[
"vmx_path"
]
.
(
string
)
func
sshAddress
(
state
m
ultistep
.
StateBag
)
(
string
,
error
)
{
config
:=
state
.
Get
(
"config"
)
.
(
*
config
)
driver
:=
state
.
Get
(
"driver"
)
.
(
Driver
)
vmxPath
:=
state
.
Get
(
"vmx_path"
)
.
(
string
)
log
.
Println
(
"Lookup up IP information..."
)
f
,
err
:=
os
.
Open
(
vmxPath
)
...
...
@@ -58,8 +59,8 @@ func sshAddress(state map[string]interface{}) (string, error) {
return
fmt
.
Sprintf
(
"%s:%d"
,
ipAddress
,
config
.
SSHPort
),
nil
}
func
sshConfig
(
state
m
ap
[
string
]
interface
{}
)
(
*
gossh
.
ClientConfig
,
error
)
{
config
:=
state
[
"config"
]
.
(
*
config
)
func
sshConfig
(
state
m
ultistep
.
StateBag
)
(
*
gossh
.
ClientConfig
,
error
)
{
config
:=
state
.
Get
(
"config"
)
.
(
*
config
)
auth
:=
[]
gossh
.
ClientAuth
{
gossh
.
ClientAuthPassword
(
ssh
.
Password
(
config
.
SSHPassword
)),
...
...
builder/vmware/step_clean_files.go
View file @
f74ff911
...
...
@@ -23,9 +23,9 @@ var KeepFileExtensions = []string{".nvram", ".vmdk", ".vmsd", ".vmx", ".vmxf"}
// <nothing>
type
stepCleanFiles
struct
{}
func
(
stepCleanFiles
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
config
:=
state
[
"config"
]
.
(
*
config
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
func
(
stepCleanFiles
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
config
:=
state
.
Get
(
"config"
)
.
(
*
config
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
ui
.
Say
(
"Deleting unnecessary VMware files..."
)
visit
:=
func
(
path
string
,
info
os
.
FileInfo
,
err
error
)
error
{
...
...
@@ -55,11 +55,11 @@ func (stepCleanFiles) Run(state map[string]interface{}) multistep.StepAction {
}
if
err
:=
filepath
.
Walk
(
config
.
OutputDir
,
visit
);
err
!=
nil
{
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
return
multistep
.
ActionHalt
}
return
multistep
.
ActionContinue
}
func
(
stepCleanFiles
)
Cleanup
(
m
ap
[
string
]
interface
{}
)
{}
func
(
stepCleanFiles
)
Cleanup
(
m
ultistep
.
StateBag
)
{}
builder/vmware/step_clean_vmx.go
View file @
f74ff911
...
...
@@ -22,20 +22,20 @@ import (
// <nothing>
type
stepCleanVMX
struct
{}
func
(
s
stepCleanVMX
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
isoPath
:=
state
[
"iso_path"
]
.
(
string
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
vmxPath
:=
state
[
"vmx_path"
]
.
(
string
)
func
(
s
stepCleanVMX
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
isoPath
:=
state
.
Get
(
"iso_path"
)
.
(
string
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
vmxPath
:=
state
.
Get
(
"vmx_path"
)
.
(
string
)
ui
.
Say
(
"Cleaning VMX prior to finishing up..."
)
vmxData
,
err
:=
s
.
readVMX
(
vmxPath
)
if
err
!=
nil
{
state
[
"error"
]
=
fmt
.
Errorf
(
"Error reading VMX: %s"
,
err
)
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"Error reading VMX: %s"
,
err
)
)
return
multistep
.
ActionHalt
}
if
_
,
ok
:=
state
[
"floppy_path"
]
;
ok
{
if
_
,
ok
:=
state
.
GetOk
(
"floppy_path"
)
;
ok
{
// Delete the floppy0 entries so the floppy is no longer mounted
ui
.
Message
(
"Unmounting floppy from VMX..."
)
for
k
,
_
:=
range
vmxData
{
...
...
@@ -67,14 +67,14 @@ func (s stepCleanVMX) Run(state map[string]interface{}) multistep.StepAction {
// Rewrite the VMX
if
err
:=
WriteVMX
(
vmxPath
,
vmxData
);
err
!=
nil
{
state
[
"error"
]
=
fmt
.
Errorf
(
"Error writing VMX: %s"
,
err
)
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"Error writing VMX: %s"
,
err
)
)
return
multistep
.
ActionHalt
}
return
multistep
.
ActionContinue
}
func
(
stepCleanVMX
)
Cleanup
(
m
ap
[
string
]
interface
{}
)
{}
func
(
stepCleanVMX
)
Cleanup
(
m
ultistep
.
StateBag
)
{}
func
(
stepCleanVMX
)
readVMX
(
vmxPath
string
)
(
map
[
string
]
string
,
error
)
{
vmxF
,
err
:=
os
.
Open
(
vmxPath
)
...
...
builder/vmware/step_compact_disk.go
View file @
f74ff911
...
...
@@ -20,11 +20,11 @@ import (
// <nothing>
type
stepCompactDisk
struct
{}
func
(
stepCompactDisk
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
config
:=
state
[
"config"
]
.
(
*
config
)
driver
:=
state
[
"driver"
]
.
(
Driver
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
full_disk_path
:=
state
[
"full_disk_path"
]
.
(
string
)
func
(
stepCompactDisk
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
config
:=
state
.
Get
(
"config"
)
.
(
*
config
)
driver
:=
state
.
Get
(
"driver"
)
.
(
Driver
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
full_disk_path
:=
state
.
Get
(
"full_disk_path"
)
.
(
string
)
if
config
.
SkipCompaction
==
true
{
log
.
Println
(
"Skipping disk compaction step..."
)
...
...
@@ -33,11 +33,11 @@ func (stepCompactDisk) Run(state map[string]interface{}) multistep.StepAction {
ui
.
Say
(
"Compacting the disk image"
)
if
err
:=
driver
.
CompactDisk
(
full_disk_path
);
err
!=
nil
{
state
[
"error"
]
=
fmt
.
Errorf
(
"Error compacting disk: %s"
,
err
)
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"Error compacting disk: %s"
,
err
)
)
return
multistep
.
ActionHalt
}
return
multistep
.
ActionContinue
}
func
(
stepCompactDisk
)
Cleanup
(
m
ap
[
string
]
interface
{}
)
{}
func
(
stepCompactDisk
)
Cleanup
(
m
ultistep
.
StateBag
)
{}
builder/vmware/step_configure_vnc.go
View file @
f74ff911
...
...
@@ -22,15 +22,15 @@ import (
// vnc_port uint - The port that VNC is configured to listen on.
type
stepConfigureVNC
struct
{}
func
(
stepConfigureVNC
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
config
:=
state
[
"config"
]
.
(
*
config
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
vmxPath
:=
state
[
"vmx_path"
]
.
(
string
)
func
(
stepConfigureVNC
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
config
:=
state
.
Get
(
"config"
)
.
(
*
config
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
vmxPath
:=
state
.
Get
(
"vmx_path"
)
.
(
string
)
f
,
err
:=
os
.
Open
(
vmxPath
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error reading VMX data: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
...
...
@@ -38,7 +38,7 @@ func (stepConfigureVNC) Run(state map[string]interface{}) multistep.StepAction {
vmxBytes
,
err
:=
ioutil
.
ReadAll
(
f
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error reading VMX data: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
...
...
@@ -67,15 +67,15 @@ func (stepConfigureVNC) Run(state map[string]interface{}) multistep.StepAction {
if
err
:=
WriteVMX
(
vmxPath
,
vmxData
);
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error writing VMX data: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
state
[
"vnc_port"
]
=
vncPort
state
.
Put
(
"vnc_port"
,
vncPort
)
return
multistep
.
ActionContinue
}
func
(
stepConfigureVNC
)
Cleanup
(
m
ap
[
string
]
interface
{}
)
{
func
(
stepConfigureVNC
)
Cleanup
(
m
ultistep
.
StateBag
)
{
}
builder/vmware/step_create_disk.go
View file @
f74ff911
...
...
@@ -18,23 +18,23 @@ import (
// full_disk_path (string) - The full path to the created disk.
type
stepCreateDisk
struct
{}
func
(
stepCreateDisk
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
config
:=
state
[
"config"
]
.
(
*
config
)
driver
:=
state
[
"driver"
]
.
(
Driver
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
func
(
stepCreateDisk
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
config
:=
state
.
Get
(
"config"
)
.
(
*
config
)
driver
:=
state
.
Get
(
"driver"
)
.
(
Driver
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
ui
.
Say
(
"Creating virtual machine disk"
)
full_disk_path
:=
filepath
.
Join
(
config
.
OutputDir
,
config
.
DiskName
+
".vmdk"
)
if
err
:=
driver
.
CreateDisk
(
full_disk_path
,
fmt
.
Sprintf
(
"%dM"
,
config
.
DiskSize
),
config
.
DiskTypeId
);
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error creating disk: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
state
[
"full_disk_path"
]
=
full_disk_path
state
.
Put
(
"full_disk_path"
,
full_disk_path
)
return
multistep
.
ActionContinue
}
func
(
stepCreateDisk
)
Cleanup
(
m
ap
[
string
]
interface
{}
)
{}
func
(
stepCreateDisk
)
Cleanup
(
m
ultistep
.
StateBag
)
{}
builder/vmware/step_create_vmx.go
View file @
f74ff911
...
...
@@ -28,10 +28,10 @@ type vmxTemplateData struct {
// vmx_path string - The path to the VMX file.
type
stepCreateVMX
struct
{}
func
(
stepCreateVMX
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
config
:=
state
[
"config"
]
.
(
*
config
)
isoPath
:=
state
[
"iso_path"
]
.
(
string
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
func
(
stepCreateVMX
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
config
:=
state
.
Get
(
"config"
)
.
(
*
config
)
isoPath
:=
state
.
Get
(
"iso_path"
)
.
(
string
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
ui
.
Say
(
"Building and writing VMX file"
)
...
...
@@ -47,7 +47,7 @@ func (stepCreateVMX) Run(state map[string]interface{}) multistep.StepAction {
f
,
err
:=
os
.
Open
(
config
.
VMXTemplatePath
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error reading VMX template: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
...
...
@@ -56,7 +56,7 @@ func (stepCreateVMX) Run(state map[string]interface{}) multistep.StepAction {
rawBytes
,
err
:=
ioutil
.
ReadAll
(
f
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error reading VMX template: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
...
...
@@ -67,7 +67,7 @@ func (stepCreateVMX) Run(state map[string]interface{}) multistep.StepAction {
vmxContents
,
err
:=
config
.
tpl
.
Process
(
vmxTemplate
,
tplData
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error procesing VMX template: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
...
...
@@ -81,7 +81,7 @@ func (stepCreateVMX) Run(state map[string]interface{}) multistep.StepAction {
}
}
if
floppyPathRaw
,
ok
:=
state
[
"floppy_path"
]
;
ok
{
if
floppyPathRaw
,
ok
:=
state
.
GetOk
(
"floppy_path"
)
;
ok
{
log
.
Println
(
"Floppy path present, setting in VMX"
)
vmxData
[
"floppy0.present"
]
=
"TRUE"
vmxData
[
"floppy0.fileType"
]
=
"file"
...
...
@@ -91,17 +91,17 @@ func (stepCreateVMX) Run(state map[string]interface{}) multistep.StepAction {
vmxPath
:=
filepath
.
Join
(
config
.
OutputDir
,
config
.
VMName
+
".vmx"
)
if
err
:=
WriteVMX
(
vmxPath
,
vmxData
);
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error creating VMX file: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
state
[
"vmx_path"
]
=
vmxPath
state
.
Put
(
"vmx_path"
,
vmxPath
)
return
multistep
.
ActionContinue
}
func
(
stepCreateVMX
)
Cleanup
(
m
ap
[
string
]
interface
{}
)
{
func
(
stepCreateVMX
)
Cleanup
(
m
ultistep
.
StateBag
)
{
}
// This is the default VMX template used if no other template is given.
...
...
builder/vmware/step_http_server.go
View file @
f74ff911
...
...
@@ -23,13 +23,13 @@ type stepHTTPServer struct {
l
net
.
Listener
}
func
(
s
*
stepHTTPServer
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
config
:=
state
[
"config"
]
.
(
*
config
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
func
(
s
*
stepHTTPServer
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
config
:=
state
.
Get
(
"config"
)
.
(
*
config
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
var
httpPort
uint
=
0
if
config
.
HTTPDir
==
""
{
state
[
"http_port"
]
=
httpPort
state
.
Put
(
"http_port"
,
httpPort
)
return
multistep
.
ActionContinue
}
...
...
@@ -62,12 +62,12 @@ func (s *stepHTTPServer) Run(state map[string]interface{}) multistep.StepAction
go
server
.
Serve
(
s
.
l
)
// Save the address into the state so it can be accessed in the future
state
[
"http_port"
]
=
httpPort
state
.
Put
(
"http_port"
,
httpPort
)
return
multistep
.
ActionContinue
}
func
(
s
*
stepHTTPServer
)
Cleanup
(
m
ap
[
string
]
interface
{}
)
{
func
(
s
*
stepHTTPServer
)
Cleanup
(
m
ultistep
.
StateBag
)
{
if
s
.
l
!=
nil
{
// Close the listener so that the HTTP server stops
s
.
l
.
Close
()
...
...
builder/vmware/step_prepare_output_dir.go
View file @
f74ff911
...
...
@@ -10,9 +10,9 @@ import (
type
stepPrepareOutputDir
struct
{}
func
(
stepPrepareOutputDir
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
config
:=
state
[
"config"
]
.
(
*
config
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
func
(
stepPrepareOutputDir
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
config
:=
state
.
Get
(
"config"
)
.
(
*
config
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
if
_
,
err
:=
os
.
Stat
(
config
.
OutputDir
);
err
==
nil
&&
config
.
PackerForce
{
ui
.
Say
(
"Deleting previous output directory..."
)
...
...
@@ -20,20 +20,20 @@ func (stepPrepareOutputDir) Run(state map[string]interface{}) multistep.StepActi
}
if
err
:=
os
.
MkdirAll
(
config
.
OutputDir
,
0755
);
err
!=
nil
{
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
return
multistep
.
ActionHalt
}
return
multistep
.
ActionContinue
}
func
(
stepPrepareOutputDir
)
Cleanup
(
state
m
ap
[
string
]
interface
{}
)
{
_
,
cancelled
:=
state
[
multistep
.
StateCancelled
]
_
,
halted
:=
state
[
multistep
.
StateHalted
]
func
(
stepPrepareOutputDir
)
Cleanup
(
state
m
ultistep
.
StateBag
)
{
_
,
cancelled
:=
state
.
GetOk
(
multistep
.
StateCancelled
)
_
,
halted
:=
state
.
GetOk
(
multistep
.
StateHalted
)
if
cancelled
||
halted
{
config
:=
state
[
"config"
]
.
(
*
config
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
config
:=
state
.
Get
(
"config"
)
.
(
*
config
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
ui
.
Say
(
"Deleting output directory..."
)
for
i
:=
0
;
i
<
5
;
i
++
{
...
...
builder/vmware/step_prepare_tools.go
View file @
f74ff911
...
...
@@ -8,9 +8,9 @@ import (
type
stepPrepareTools
struct
{}
func
(
*
stepPrepareTools
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
config
:=
state
[
"config"
]
.
(
*
config
)
driver
:=
state
[
"driver"
]
.
(
Driver
)
func
(
*
stepPrepareTools
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
config
:=
state
.
Get
(
"config"
)
.
(
*
config
)
driver
:=
state
.
Get
(
"driver"
)
.
(
Driver
)
if
config
.
ToolsUploadFlavor
==
""
{
return
multistep
.
ActionContinue
...
...
@@ -18,16 +18,16 @@ func (*stepPrepareTools) Run(state map[string]interface{}) multistep.StepAction
path
:=
driver
.
ToolsIsoPath
(
config
.
ToolsUploadFlavor
)
if
_
,
err
:=
os
.
Stat
(
path
);
err
!=
nil
{
state
[
"error"
]
=
fmt
.
Errorf
(
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."
,
config
.
ToolsUploadFlavor
)
"VMware GUI."
,
config
.
ToolsUploadFlavor
)
)
return
multistep
.
ActionHalt
}
state
[
"tools_upload_source"
]
=
path
state
.
Put
(
"tools_upload_source"
,
path
)
return
multistep
.
ActionContinue
}
func
(
*
stepPrepareTools
)
Cleanup
(
m
ap
[
string
]
interface
{}
)
{}
func
(
*
stepPrepareTools
)
Cleanup
(
m
ultistep
.
StateBag
)
{}
builder/vmware/step_run.go
View file @
f74ff911
...
...
@@ -22,12 +22,12 @@ type stepRun struct {
vmxPath
string
}
func
(
s
*
stepRun
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
config
:=
state
[
"config"
]
.
(
*
config
)
driver
:=
state
[
"driver"
]
.
(
Driver
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
vmxPath
:=
state
[
"vmx_path"
]
.
(
string
)
vncPort
:=
state
[
"vnc_port"
]
.
(
uint
)
func
(
s
*
stepRun
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
config
:=
state
.
Get
(
"config"
)
.
(
*
config
)
driver
:=
state
.
Get
(
"driver"
)
.
(
Driver
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
vmxPath
:=
state
.
Get
(
"vmx_path"
)
.
(
string
)
vncPort
:=
state
.
Get
(
"vnc_port"
)
.
(
uint
)
// Set the VMX path so that we know we started the machine
s
.
bootTime
=
time
.
Now
()
...
...
@@ -43,7 +43,7 @@ func (s *stepRun) Run(state map[string]interface{}) multistep.StepAction {
if
err
:=
driver
.
Start
(
vmxPath
,
config
.
Headless
);
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error starting VM: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
...
...
@@ -57,9 +57,9 @@ func (s *stepRun) Run(state map[string]interface{}) multistep.StepAction {
return
multistep
.
ActionContinue
}
func
(
s
*
stepRun
)
Cleanup
(
state
m
ap
[
string
]
interface
{}
)
{
driver
:=
state
[
"driver"
]
.
(
Driver
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
func
(
s
*
stepRun
)
Cleanup
(
state
m
ultistep
.
StateBag
)
{
driver
:=
state
.
Get
(
"driver"
)
.
(
Driver
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
// If we started the machine... stop it.
if
s
.
vmxPath
!=
""
{
...
...
builder/vmware/step_shutdown.go
View file @
f74ff911
...
...
@@ -27,12 +27,12 @@ import (
// <nothing>
type
stepShutdown
struct
{}
func
(
s
*
stepShutdown
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
comm
:=
state
[
"communicator"
]
.
(
packer
.
Communicator
)
config
:=
state
[
"config"
]
.
(
*
config
)
driver
:=
state
[
"driver"
]
.
(
Driver
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
vmxPath
:=
state
[
"vmx_path"
]
.
(
string
)
func
(
s
*
stepShutdown
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
comm
:=
state
.
Get
(
"communicator"
)
.
(
packer
.
Communicator
)
config
:=
state
.
Get
(
"config"
)
.
(
*
config
)
driver
:=
state
.
Get
(
"driver"
)
.
(
Driver
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
vmxPath
:=
state
.
Get
(
"vmx_path"
)
.
(
string
)
if
config
.
ShutdownCommand
!=
""
{
ui
.
Say
(
"Gracefully halting virtual machine..."
)
...
...
@@ -46,7 +46,7 @@ func (s *stepShutdown) Run(state map[string]interface{}) multistep.StepAction {
}
if
err
:=
comm
.
Start
(
cmd
);
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Failed to send shutdown command: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
...
...
@@ -56,9 +56,9 @@ func (s *stepShutdown) Run(state map[string]interface{}) multistep.StepAction {
// If the command failed to run, notify the user in some way.
if
cmd
.
ExitStatus
!=
0
{
state
[
"error"
]
=
fmt
.
Errorf
(
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"Shutdown command has non-zero exit status.
\n\n
Stdout: %s
\n\n
Stderr: %s"
,
stdout
.
String
(),
stderr
.
String
())
stdout
.
String
(),
stderr
.
String
())
)
return
multistep
.
ActionHalt
}
...
...
@@ -77,7 +77,7 @@ func (s *stepShutdown) Run(state map[string]interface{}) multistep.StepAction {
select
{
case
<-
shutdownTimer
:
err
:=
errors
.
New
(
"Timeout while waiting for machine to shut down."
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
default
:
...
...
@@ -87,7 +87,7 @@ func (s *stepShutdown) Run(state map[string]interface{}) multistep.StepAction {
}
else
{
if
err
:=
driver
.
Stop
(
vmxPath
);
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error stopping VM: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
...
...
@@ -132,4 +132,4 @@ LockWaitLoop:
return
multistep
.
ActionContinue
}
func
(
s
*
stepShutdown
)
Cleanup
(
state
m
ap
[
string
]
interface
{}
)
{}
func
(
s
*
stepShutdown
)
Cleanup
(
state
m
ultistep
.
StateBag
)
{}
builder/vmware/step_type_boot_command.go
View file @
f74ff911
...
...
@@ -34,18 +34,18 @@ type bootCommandTemplateData struct {
// <nothing>
type
stepTypeBootCommand
struct
{}
func
(
s
*
stepTypeBootCommand
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
config
:=
state
[
"config"
]
.
(
*
config
)
httpPort
:=
state
[
"http_port"
]
.
(
uint
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
vncPort
:=
state
[
"vnc_port"
]
.
(
uint
)
func
(
s
*
stepTypeBootCommand
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
config
:=
state
.
Get
(
"config"
)
.
(
*
config
)
httpPort
:=
state
.
Get
(
"http_port"
)
.
(
uint
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
vncPort
:=
state
.
Get
(
"vnc_port"
)
.
(
uint
)
// Connect to VNC
ui
.
Say
(
"Connecting to VM via VNC"
)
nc
,
err
:=
net
.
Dial
(
"tcp"
,
fmt
.
Sprintf
(
"127.0.0.1:%d"
,
vncPort
))
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error connecting to VNC: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
...
...
@@ -54,7 +54,7 @@ func (s *stepTypeBootCommand) Run(state map[string]interface{}) multistep.StepAc
c
,
err
:=
vnc
.
Client
(
nc
,
&
vnc
.
ClientConfig
{
Exclusive
:
true
})
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error handshaking with VNC: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
...
...
@@ -73,7 +73,7 @@ func (s *stepTypeBootCommand) Run(state map[string]interface{}) multistep.StepAc
hostIp
,
err
:=
ipFinder
.
HostIP
()
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error detecting host IP: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
...
...
@@ -91,14 +91,14 @@ func (s *stepTypeBootCommand) Run(state map[string]interface{}) multistep.StepAc
command
,
err
:=
config
.
tpl
.
Process
(
command
,
tplData
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error preparing boot command: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
// Check for interrupts between typing things so we can cancel
// since this isn't the fastest thing.
if
_
,
ok
:=
state
[
multistep
.
StateCancelled
]
;
ok
{
if
_
,
ok
:=
state
.
GetOk
(
multistep
.
StateCancelled
)
;
ok
{
return
multistep
.
ActionHalt
}
...
...
@@ -108,7 +108,7 @@ func (s *stepTypeBootCommand) Run(state map[string]interface{}) multistep.StepAc
return
multistep
.
ActionContinue
}
func
(
*
stepTypeBootCommand
)
Cleanup
(
m
ap
[
string
]
interface
{}
)
{}
func
(
*
stepTypeBootCommand
)
Cleanup
(
m
ultistep
.
StateBag
)
{}
func
vncSendString
(
c
*
vnc
.
ClientConn
,
original
string
)
{
special
:=
make
(
map
[
string
]
uint32
)
...
...
builder/vmware/step_upload_tools.go
View file @
f74ff911
...
...
@@ -13,20 +13,20 @@ type toolsUploadPathTemplate struct {
type
stepUploadTools
struct
{}
func
(
*
stepUploadTools
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
config
:=
state
[
"config"
]
.
(
*
config
)
func
(
*
stepUploadTools
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
config
:=
state
.
Get
(
"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
)
comm
:=
state
.
Get
(
"communicator"
)
.
(
packer
.
Communicator
)
tools_source
:=
state
.
Get
(
"tools_upload_source"
)
.
(
string
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
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
)
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"Error opening VMware Tools ISO: %s"
,
err
)
)
return
multistep
.
ActionHalt
}
defer
f
.
Close
()
...
...
@@ -35,17 +35,17 @@ func (*stepUploadTools) Run(state map[string]interface{}) multistep.StepAction {
config
.
ToolsUploadPath
,
err
=
config
.
tpl
.
Process
(
config
.
ToolsUploadPath
,
tplData
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error preparing upload path: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
if
err
:=
comm
.
Upload
(
config
.
ToolsUploadPath
,
f
);
err
!=
nil
{
state
[
"error"
]
=
fmt
.
Errorf
(
"Error uploading VMware Tools: %s"
,
err
)
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"Error uploading VMware Tools: %s"
,
err
)
)
return
multistep
.
ActionHalt
}
return
multistep
.
ActionContinue
}
func
(
*
stepUploadTools
)
Cleanup
(
m
ap
[
string
]
interface
{}
)
{}
func
(
*
stepUploadTools
)
Cleanup
(
m
ultistep
.
StateBag
)
{}
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