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
c559ec7d
Commit
c559ec7d
authored
Jun 06, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/vmware: check if running prior to shutting down
parent
f851e56d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
14 deletions
+41
-14
builder/vmware/artifact_test.go
builder/vmware/artifact_test.go
+1
-1
builder/vmware/builder.go
builder/vmware/builder.go
+11
-10
builder/vmware/driver.go
builder/vmware/driver.go
+22
-0
builder/vmware/step_run.go
builder/vmware/step_run.go
+7
-3
No files found.
builder/vmware/artifact_test.go
View file @
c559ec7d
package
vmware
package
vmware
import
(
import
(
"testing"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/packer"
"testing"
)
)
func
TestArtifact_Impl
(
t
*
testing
.
T
)
{
func
TestArtifact_Impl
(
t
*
testing
.
T
)
{
...
...
builder/vmware/builder.go
View file @
c559ec7d
...
@@ -21,16 +21,17 @@ type Builder struct {
...
@@ -21,16 +21,17 @@ type Builder struct {
}
}
type
config
struct
{
type
config
struct
{
DiskName
string
`mapstructure:"vmdk_name"`
DiskName
string
`mapstructure:"vmdk_name"`
ISOUrl
string
`mapstructure:"iso_url"`
ISOUrl
string
`mapstructure:"iso_url"`
VMName
string
`mapstructure:"vm_name"`
VMName
string
`mapstructure:"vm_name"`
OutputDir
string
`mapstructure:"output_directory"`
OutputDir
string
`mapstructure:"output_directory"`
HTTPDir
string
`mapstructure:"http_directory"`
HTTPDir
string
`mapstructure:"http_directory"`
BootCommand
[]
string
`mapstructure:"boot_command"`
BootCommand
[]
string
`mapstructure:"boot_command"`
BootWait
time
.
Duration
BootWait
time
.
Duration
SSHUser
string
`mapstructure:"ssh_username"`
ShutdownCommand
string
`mapstructure:"shutdown_command"`
SSHPassword
string
`mapstructure:"ssh_password"`
SSHUser
string
`mapstructure:"ssh_username"`
SSHWaitTimeout
time
.
Duration
SSHPassword
string
`mapstructure:"ssh_password"`
SSHWaitTimeout
time
.
Duration
RawBootWait
string
`mapstructure:"boot_wait"`
RawBootWait
string
`mapstructure:"boot_wait"`
RawSSHWaitTimeout
string
`mapstructure:"ssh_wait_timeout"`
RawSSHWaitTimeout
string
`mapstructure:"ssh_wait_timeout"`
...
...
builder/vmware/driver.go
View file @
c559ec7d
package
vmware
package
vmware
import
(
import
(
"bytes"
"os/exec"
"os/exec"
"path/filepath"
"path/filepath"
"strings"
)
)
// A driver is able to talk to VMware, control virtual machines, etc.
// A driver is able to talk to VMware, control virtual machines, etc.
...
@@ -10,6 +12,9 @@ type Driver interface {
...
@@ -10,6 +12,9 @@ type Driver interface {
// CreateDisk creates a virtual disk with the given size.
// CreateDisk creates a virtual disk with the given size.
CreateDisk
(
string
,
string
)
error
CreateDisk
(
string
,
string
)
error
// Checks if the VMX file at the given path is running.
IsRunning
(
string
)
(
bool
,
error
)
// Start starts a VM specified by the path to the VMX given.
// Start starts a VM specified by the path to the VMX given.
Start
(
string
)
error
Start
(
string
)
error
...
@@ -33,6 +38,23 @@ func (d *Fusion5Driver) CreateDisk(output string, size string) error {
...
@@ -33,6 +38,23 @@ func (d *Fusion5Driver) CreateDisk(output string, size string) error {
return
nil
return
nil
}
}
func
(
d
*
Fusion5Driver
)
IsRunning
(
vmxPath
string
)
(
bool
,
error
)
{
stdout
:=
new
(
bytes
.
Buffer
)
cmd
:=
exec
.
Command
(
d
.
vmrunPath
(),
"-T"
,
"fusion"
,
"list"
)
cmd
.
Stdout
=
stdout
if
err
:=
cmd
.
Run
();
err
!=
nil
{
return
false
,
err
}
for
_
,
line
:=
range
strings
.
Split
(
stdout
.
String
(),
"
\n
"
)
{
if
line
==
vmxPath
{
return
true
,
nil
}
}
return
false
,
nil
}
func
(
d
*
Fusion5Driver
)
Start
(
vmxPath
string
)
error
{
func
(
d
*
Fusion5Driver
)
Start
(
vmxPath
string
)
error
{
cmd
:=
exec
.
Command
(
d
.
vmrunPath
(),
"-T"
,
"fusion"
,
"start"
,
vmxPath
,
"gui"
)
cmd
:=
exec
.
Command
(
d
.
vmrunPath
(),
"-T"
,
"fusion"
,
"start"
,
vmxPath
,
"gui"
)
if
err
:=
cmd
.
Run
();
err
!=
nil
{
if
err
:=
cmd
.
Run
();
err
!=
nil
{
...
...
builder/vmware/step_run.go
View file @
c559ec7d
...
@@ -62,9 +62,13 @@ func (s *stepRun) Cleanup(state map[string]interface{}) {
...
@@ -62,9 +62,13 @@ func (s *stepRun) Cleanup(state map[string]interface{}) {
time
.
Sleep
(
sleepTime
)
time
.
Sleep
(
sleepTime
)
}
}
ui
.
Say
(
"Stopping virtual machine..."
)
// See if it is running
if
err
:=
driver
.
Stop
(
s
.
vmxPath
);
err
!=
nil
{
running
,
_
:=
driver
.
IsRunning
(
s
.
vmxPath
)
ui
.
Error
(
fmt
.
Sprintf
(
"Error stopping VM: %s"
,
err
))
if
running
{
ui
.
Say
(
"Stopping virtual machine..."
)
if
err
:=
driver
.
Stop
(
s
.
vmxPath
);
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error stopping VM: %s"
,
err
))
}
}
}
}
}
}
}
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