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
6d3b09c5
Commit
6d3b09c5
authored
Jun 19, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/vmware: properly handle errors
parent
64aed2b3
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
52 additions
and
16 deletions
+52
-16
builder/vmware/builder.go
builder/vmware/builder.go
+8
-2
builder/vmware/step_configure_vnc.go
builder/vmware/step_configure_vnc.go
+9
-3
builder/vmware/step_create_disk.go
builder/vmware/step_create_disk.go
+3
-1
builder/vmware/step_create_vmx.go
builder/vmware/step_create_vmx.go
+3
-1
builder/vmware/step_download_iso.go
builder/vmware/step_download_iso.go
+6
-2
builder/vmware/step_prepare_output_dir.go
builder/vmware/step_prepare_output_dir.go
+1
-0
builder/vmware/step_run.go
builder/vmware/step_run.go
+3
-1
builder/vmware/step_shutdown.go
builder/vmware/step_shutdown.go
+10
-3
builder/vmware/step_type_boot_command.go
builder/vmware/step_type_boot_command.go
+9
-3
No files found.
builder/vmware/builder.go
View file @
6d3b09c5
...
@@ -225,15 +225,21 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
...
@@ -225,15 +225,21 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
}
else
{
}
else
{
b
.
runner
=
&
multistep
.
BasicRunner
{
Steps
:
steps
}
b
.
runner
=
&
multistep
.
BasicRunner
{
Steps
:
steps
}
}
}
b
.
runner
.
Run
(
state
)
b
.
runner
.
Run
(
state
)
// If there was an error, return that
if
rawErr
,
ok
:=
state
[
"error"
];
ok
{
return
nil
,
rawErr
.
(
error
)
}
// If we were interrupted or cancelled, then just exit.
// If we were interrupted or cancelled, then just exit.
if
_
,
ok
:=
state
[
multistep
.
StateCancelled
];
ok
{
if
_
,
ok
:=
state
[
multistep
.
StateCancelled
];
ok
{
return
nil
,
nil
return
nil
,
errors
.
New
(
"Build was cancelled."
)
}
}
if
_
,
ok
:=
state
[
multistep
.
StateHalted
];
ok
{
if
_
,
ok
:=
state
[
multistep
.
StateHalted
];
ok
{
return
nil
,
nil
return
nil
,
errors
.
New
(
"Build was halted."
)
}
}
// Compile the artifact list
// Compile the artifact list
...
...
builder/vmware/step_configure_vnc.go
View file @
6d3b09c5
...
@@ -29,13 +29,17 @@ func (stepConfigureVNC) Run(state map[string]interface{}) multistep.StepAction {
...
@@ -29,13 +29,17 @@ func (stepConfigureVNC) Run(state map[string]interface{}) multistep.StepAction {
f
,
err
:=
os
.
Open
(
vmxPath
)
f
,
err
:=
os
.
Open
(
vmxPath
)
if
err
!=
nil
{
if
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error while reading VMX data: %s"
,
err
))
err
:=
fmt
.
Errorf
(
"Error reading VMX data: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
vmxBytes
,
err
:=
ioutil
.
ReadAll
(
f
)
vmxBytes
,
err
:=
ioutil
.
ReadAll
(
f
)
if
err
!=
nil
{
if
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error reading VMX data: %s"
,
err
))
err
:=
fmt
.
Errorf
(
"Error reading VMX data: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
@@ -62,7 +66,9 @@ func (stepConfigureVNC) Run(state map[string]interface{}) multistep.StepAction {
...
@@ -62,7 +66,9 @@ func (stepConfigureVNC) Run(state map[string]interface{}) multistep.StepAction {
vmxData
[
"RemoteDisplay.vnc.port"
]
=
fmt
.
Sprintf
(
"%d"
,
vncPort
)
vmxData
[
"RemoteDisplay.vnc.port"
]
=
fmt
.
Sprintf
(
"%d"
,
vncPort
)
if
err
:=
WriteVMX
(
vmxPath
,
vmxData
);
err
!=
nil
{
if
err
:=
WriteVMX
(
vmxPath
,
vmxData
);
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error writing VMX data: %s"
,
err
))
err
:=
fmt
.
Errorf
(
"Error writing VMX data: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
...
builder/vmware/step_create_disk.go
View file @
6d3b09c5
...
@@ -29,7 +29,9 @@ func (stepCreateDisk) Run(state map[string]interface{}) multistep.StepAction {
...
@@ -29,7 +29,9 @@ func (stepCreateDisk) Run(state map[string]interface{}) multistep.StepAction {
ui
.
Say
(
"Creating virtual machine disk"
)
ui
.
Say
(
"Creating virtual machine disk"
)
output
:=
filepath
.
Join
(
config
.
OutputDir
,
config
.
DiskName
+
".vmdk"
)
output
:=
filepath
.
Join
(
config
.
OutputDir
,
config
.
DiskName
+
".vmdk"
)
if
err
:=
driver
.
CreateDisk
(
output
,
"40000M"
);
err
!=
nil
{
if
err
:=
driver
.
CreateDisk
(
output
,
"40000M"
);
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error creating VMware disk: %s"
,
err
))
err
:=
fmt
.
Errorf
(
"Error creating disk: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
...
builder/vmware/step_create_vmx.go
View file @
6d3b09c5
...
@@ -57,7 +57,9 @@ func (stepCreateVMX) Run(state map[string]interface{}) multistep.StepAction {
...
@@ -57,7 +57,9 @@ func (stepCreateVMX) Run(state map[string]interface{}) multistep.StepAction {
vmxPath
:=
filepath
.
Join
(
config
.
OutputDir
,
config
.
VMName
+
".vmx"
)
vmxPath
:=
filepath
.
Join
(
config
.
OutputDir
,
config
.
VMName
+
".vmx"
)
if
err
:=
WriteVMX
(
vmxPath
,
vmxData
);
err
!=
nil
{
if
err
:=
WriteVMX
(
vmxPath
,
vmxData
);
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error creating VMX: %s"
,
err
))
err
:=
fmt
.
Errorf
(
"Error creating VMX file: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
...
builder/vmware/step_download_iso.go
View file @
6d3b09c5
...
@@ -29,7 +29,9 @@ func (s stepDownloadISO) Run(state map[string]interface{}) multistep.StepAction
...
@@ -29,7 +29,9 @@ func (s stepDownloadISO) Run(state map[string]interface{}) multistep.StepAction
checksum
,
err
:=
hex
.
DecodeString
(
config
.
ISOMD5
)
checksum
,
err
:=
hex
.
DecodeString
(
config
.
ISOMD5
)
if
err
!=
nil
{
if
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error parsing checksum: %s"
,
err
))
err
:=
fmt
.
Errorf
(
"Error parsing checksum: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
@@ -62,7 +64,9 @@ DownloadWaitLoop:
...
@@ -62,7 +64,9 @@ DownloadWaitLoop:
select
{
select
{
case
err
:=
<-
downloadCompleteCh
:
case
err
:=
<-
downloadCompleteCh
:
if
err
!=
nil
{
if
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error downloading ISO: %s"
,
err
))
err
:=
fmt
.
Errorf
(
"Error downloading ISO: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
}
}
break
DownloadWaitLoop
break
DownloadWaitLoop
...
...
builder/vmware/step_prepare_output_dir.go
View file @
6d3b09c5
...
@@ -11,6 +11,7 @@ func (stepPrepareOutputDir) Run(state map[string]interface{}) multistep.StepActi
...
@@ -11,6 +11,7 @@ func (stepPrepareOutputDir) Run(state map[string]interface{}) multistep.StepActi
config
:=
state
[
"config"
]
.
(
*
config
)
config
:=
state
[
"config"
]
.
(
*
config
)
if
err
:=
os
.
MkdirAll
(
config
.
OutputDir
,
0755
);
err
!=
nil
{
if
err
:=
os
.
MkdirAll
(
config
.
OutputDir
,
0755
);
err
!=
nil
{
state
[
"error"
]
=
err
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
...
builder/vmware/step_run.go
View file @
6d3b09c5
...
@@ -34,7 +34,9 @@ func (s *stepRun) Run(state map[string]interface{}) multistep.StepAction {
...
@@ -34,7 +34,9 @@ func (s *stepRun) Run(state map[string]interface{}) multistep.StepAction {
ui
.
Say
(
"Starting virtual machine..."
)
ui
.
Say
(
"Starting virtual machine..."
)
if
err
:=
driver
.
Start
(
vmxPath
);
err
!=
nil
{
if
err
:=
driver
.
Start
(
vmxPath
);
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error starting VM: %s"
,
err
))
err
:=
fmt
.
Errorf
(
"Error starting VM: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
...
builder/vmware/step_shutdown.go
View file @
6d3b09c5
package
vmware
package
vmware
import
(
import
(
"errors"
"fmt"
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/packer"
...
@@ -34,7 +35,9 @@ func (s *stepShutdown) Run(state map[string]interface{}) multistep.StepAction {
...
@@ -34,7 +35,9 @@ func (s *stepShutdown) Run(state map[string]interface{}) multistep.StepAction {
log
.
Printf
(
"Executing shutdown command: %s"
,
config
.
ShutdownCommand
)
log
.
Printf
(
"Executing shutdown command: %s"
,
config
.
ShutdownCommand
)
cmd
:=
&
packer
.
RemoteCmd
{
Command
:
config
.
ShutdownCommand
}
cmd
:=
&
packer
.
RemoteCmd
{
Command
:
config
.
ShutdownCommand
}
if
err
:=
comm
.
Start
(
cmd
);
err
!=
nil
{
if
err
:=
comm
.
Start
(
cmd
);
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Failed to send shutdown command: %s"
,
err
))
err
:=
fmt
.
Errorf
(
"Failed to send shutdown command: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
@@ -52,7 +55,9 @@ func (s *stepShutdown) Run(state map[string]interface{}) multistep.StepAction {
...
@@ -52,7 +55,9 @@ func (s *stepShutdown) Run(state map[string]interface{}) multistep.StepAction {
select
{
select
{
case
<-
shutdownTimer
:
case
<-
shutdownTimer
:
ui
.
Error
(
"Timeout while waiting for machine to shut down."
)
err
:=
errors
.
New
(
"Timeout while waiting for machine to shut down."
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
default
:
default
:
time
.
Sleep
(
1
*
time
.
Second
)
time
.
Sleep
(
1
*
time
.
Second
)
...
@@ -60,7 +65,9 @@ func (s *stepShutdown) Run(state map[string]interface{}) multistep.StepAction {
...
@@ -60,7 +65,9 @@ func (s *stepShutdown) Run(state map[string]interface{}) multistep.StepAction {
}
}
}
else
{
}
else
{
if
err
:=
driver
.
Stop
(
vmxPath
);
err
!=
nil
{
if
err
:=
driver
.
Stop
(
vmxPath
);
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error stopping VM: %s"
,
err
))
err
:=
fmt
.
Errorf
(
"Error stopping VM: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
}
}
...
...
builder/vmware/step_type_boot_command.go
View file @
6d3b09c5
...
@@ -45,14 +45,18 @@ func (s *stepTypeBootCommand) Run(state map[string]interface{}) multistep.StepAc
...
@@ -45,14 +45,18 @@ func (s *stepTypeBootCommand) Run(state map[string]interface{}) multistep.StepAc
ui
.
Say
(
"Connecting to VM via VNC"
)
ui
.
Say
(
"Connecting to VM via VNC"
)
nc
,
err
:=
net
.
Dial
(
"tcp"
,
fmt
.
Sprintf
(
"127.0.0.1:%d"
,
vncPort
))
nc
,
err
:=
net
.
Dial
(
"tcp"
,
fmt
.
Sprintf
(
"127.0.0.1:%d"
,
vncPort
))
if
err
!=
nil
{
if
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error connecting to VNC: %s"
,
err
))
err
:=
fmt
.
Errorf
(
"Error connecting to VNC: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
defer
nc
.
Close
()
defer
nc
.
Close
()
c
,
err
:=
vnc
.
Client
(
nc
,
&
vnc
.
ClientConfig
{
Exclusive
:
true
})
c
,
err
:=
vnc
.
Client
(
nc
,
&
vnc
.
ClientConfig
{
Exclusive
:
true
})
if
err
!=
nil
{
if
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error handshaking with VNC: %s"
,
err
))
err
:=
fmt
.
Errorf
(
"Error handshaking with VNC: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
defer
c
.
Close
()
defer
c
.
Close
()
...
@@ -63,7 +67,9 @@ func (s *stepTypeBootCommand) Run(state map[string]interface{}) multistep.StepAc
...
@@ -63,7 +67,9 @@ func (s *stepTypeBootCommand) Run(state map[string]interface{}) multistep.StepAc
ipFinder
:=
&
IfconfigIPFinder
{
"vmnet8"
}
ipFinder
:=
&
IfconfigIPFinder
{
"vmnet8"
}
hostIp
,
err
:=
ipFinder
.
HostIP
()
hostIp
,
err
:=
ipFinder
.
HostIP
()
if
err
!=
nil
{
if
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error detecting host IP: %s"
,
err
))
err
:=
fmt
.
Errorf
(
"Error detecting host IP: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
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