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
f23d66a1
Commit
f23d66a1
authored
Dec 26, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/vmware/vmx: clone vmx
parent
82fad98b
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
48 additions
and
49 deletions
+48
-49
builder/vmware/common/driver.go
builder/vmware/common/driver.go
+5
-0
builder/vmware/common/driver_fusion5.go
builder/vmware/common/driver_fusion5.go
+10
-2
builder/vmware/common/driver_mock.go
builder/vmware/common/driver_mock.go
+12
-0
builder/vmware/common/driver_player5.go
builder/vmware/common/driver_player5.go
+5
-0
builder/vmware/common/driver_workstation9.go
builder/vmware/common/driver_workstation9.go
+5
-0
builder/vmware/vmx/step_clone_vmx.go
builder/vmware/vmx/step_clone_vmx.go
+4
-18
builder/vmware/vmx/step_clone_vmx_test.go
builder/vmware/vmx/step_clone_vmx_test.go
+7
-29
No files found.
builder/vmware/common/driver.go
View file @
f23d66a1
...
...
@@ -13,6 +13,11 @@ import (
// A driver is able to talk to VMware, control virtual machines, etc.
type
Driver
interface
{
// Clone clones the VMX and the disk to the destination path. The
// destination is a path to the VMX file. The disk will be copied
// to that same directory.
Clone
(
dst
string
,
src
string
)
error
// CompactDisk compacts a virtual disk.
CompactDisk
(
string
)
error
...
...
builder/vmware/common/driver_fusion5.go
View file @
f23d66a1
package
common
import
(
"errors"
"fmt"
"io/ioutil"
"os"
...
...
@@ -20,6 +21,10 @@ type Fusion5Driver struct {
SSHConfig
*
SSHConfig
}
func
(
d
*
Fusion5Driver
)
Clone
(
dst
,
src
string
)
error
{
return
errors
.
New
(
"Cloning is not supported with Fusion 5. Please use Fusion 6+."
)
}
func
(
d
*
Fusion5Driver
)
CompactDisk
(
diskPath
string
)
error
{
defragCmd
:=
exec
.
Command
(
d
.
vdiskManagerPath
(),
"-d"
,
diskPath
)
if
_
,
_
,
err
:=
runAndLog
(
defragCmd
);
err
!=
nil
{
...
...
@@ -111,7 +116,8 @@ func (d *Fusion5Driver) Verify() error {
if
_
,
err
:=
os
.
Stat
(
d
.
vmrunPath
());
err
!=
nil
{
if
os
.
IsNotExist
(
err
)
{
return
fmt
.
Errorf
(
"Critical application 'vmrun' not found at path: %s"
,
d
.
vmrunPath
())
return
fmt
.
Errorf
(
"Critical application 'vmrun' not found at path: %s"
,
d
.
vmrunPath
())
}
return
err
...
...
@@ -119,7 +125,9 @@ func (d *Fusion5Driver) Verify() error {
if
_
,
err
:=
os
.
Stat
(
d
.
vdiskManagerPath
());
err
!=
nil
{
if
os
.
IsNotExist
(
err
)
{
return
fmt
.
Errorf
(
"Critical application vdisk manager not found at path: %s"
,
d
.
vdiskManagerPath
())
return
fmt
.
Errorf
(
"Critical application vdisk manager not found at path: %s"
,
d
.
vdiskManagerPath
())
}
return
err
...
...
builder/vmware/common/driver_mock.go
View file @
f23d66a1
...
...
@@ -9,6 +9,11 @@ import (
type
DriverMock
struct
{
sync
.
Mutex
CloneCalled
bool
CloneDst
string
CloneSrc
string
CloneErr
error
CompactDiskCalled
bool
CompactDiskPath
string
CompactDiskErr
error
...
...
@@ -54,6 +59,13 @@ type DriverMock struct {
VerifyErr
error
}
func
(
d
*
DriverMock
)
Clone
(
dst
string
,
src
string
)
error
{
d
.
CloneCalled
=
true
d
.
CloneDst
=
dst
d
.
CloneSrc
=
src
return
d
.
CloneErr
}
func
(
d
*
DriverMock
)
CompactDisk
(
path
string
)
error
{
d
.
CompactDiskCalled
=
true
d
.
CompactDiskPath
=
path
...
...
builder/vmware/common/driver_player5.go
View file @
f23d66a1
package
common
import
(
"errors"
"fmt"
"os"
"os/exec"
...
...
@@ -21,6 +22,10 @@ type Player5LinuxDriver struct {
SSHConfig
*
SSHConfig
}
func
(
d
*
Player5LinuxDriver
)
Clone
(
dst
,
src
string
)
error
{
return
errors
.
New
(
"Cloning is not supported with Player 5. Please use Player 6+."
)
}
func
(
d
*
Player5LinuxDriver
)
CompactDisk
(
diskPath
string
)
error
{
if
d
.
QemuImgPath
!=
""
{
return
d
.
qemuCompactDisk
(
diskPath
)
...
...
builder/vmware/common/driver_workstation9.go
View file @
f23d66a1
package
common
import
(
"errors"
"fmt"
"log"
"os"
...
...
@@ -22,6 +23,10 @@ type Workstation9Driver struct {
SSHConfig
*
SSHConfig
}
func
(
d
*
Workstation9Driver
)
Clone
(
dst
,
src
string
)
error
{
return
errors
.
New
(
"Cloning is not supported with WS 9. Please use WS 10+."
)
}
func
(
d
*
Workstation9Driver
)
CompactDisk
(
diskPath
string
)
error
{
defragCmd
:=
exec
.
Command
(
d
.
VdiskManagerPath
,
"-d"
,
diskPath
)
if
_
,
_
,
err
:=
runAndLog
(
defragCmd
);
err
!=
nil
{
...
...
builder/vmware/vmx/step_clone_vmx.go
View file @
f23d66a1
package
vmx
import
(
"io"
"log"
"os"
"path/filepath"
"github.com/mitchellh/multistep"
vmwcommon
"github.com/mitchellh/packer/builder/vmware/common"
"github.com/mitchellh/packer/packer"
)
...
...
@@ -18,29 +17,16 @@ type StepCloneVMX struct {
}
func
(
s
*
StepCloneVMX
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
driver
:=
state
.
Get
(
"driver"
)
.
(
vmwcommon
.
Driver
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
vmxPath
:=
filepath
.
Join
(
s
.
OutputDir
,
s
.
VMName
+
".vmx"
)
ui
.
Say
(
"Cloning
VMX
..."
)
ui
.
Say
(
"Cloning
source VM
..."
)
log
.
Printf
(
"Cloning from: %s"
,
s
.
Path
)
log
.
Printf
(
"Cloning to: %s"
,
vmxPath
)
from
,
err
:=
os
.
Open
(
s
.
Path
)
if
err
!=
nil
{
state
.
Put
(
"error"
,
err
)
return
multistep
.
ActionHalt
}
defer
from
.
Close
()
to
,
err
:=
os
.
Create
(
vmxPath
)
if
err
!=
nil
{
state
.
Put
(
"error"
,
err
)
return
multistep
.
ActionHalt
}
defer
to
.
Close
()
if
_
,
err
:=
io
.
Copy
(
to
,
from
);
err
!=
nil
{
if
err
:=
driver
.
Clone
(
vmxPath
,
s
.
Path
);
err
!=
nil
{
state
.
Put
(
"error"
,
err
)
return
multistep
.
ActionHalt
}
...
...
builder/vmware/vmx/step_clone_vmx_test.go
View file @
f23d66a1
package
vmx
import
(
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/mitchellh/multistep"
vmwcommon
"github.com/mitchellh/packer/builder/vmware/common"
)
func
TestStepCloneVMX_impl
(
t
*
testing
.
T
)
{
...
...
@@ -14,25 +12,14 @@ func TestStepCloneVMX_impl(t *testing.T) {
}
func
TestStepCloneVMX
(
t
*
testing
.
T
)
{
// Setup some state
td
,
err
:=
ioutil
.
TempDir
(
""
,
"packer"
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
defer
os
.
RemoveAll
(
td
)
// Create the source
sourcePath
:=
filepath
.
Join
(
td
,
"source.vmx"
)
if
err
:=
ioutil
.
WriteFile
(
sourcePath
,
[]
byte
(
"foo"
),
0644
);
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
state
:=
testState
(
t
)
step
:=
new
(
StepCloneVMX
)
step
.
OutputDir
=
td
step
.
Path
=
sourcePath
step
.
OutputDir
=
"/foo"
step
.
Path
=
"/bar/bar.vmx"
step
.
VMName
=
"foo"
driver
:=
state
.
Get
(
"driver"
)
.
(
*
vmwcommon
.
DriverMock
)
// Test the run
if
action
:=
step
.
Run
(
state
);
action
!=
multistep
.
ActionContinue
{
t
.
Fatalf
(
"bad action: %#v"
,
action
)
...
...
@@ -41,16 +28,7 @@ func TestStepCloneVMX(t *testing.T) {
t
.
Fatal
(
"should NOT have error"
)
}
// Test we have our VMX
if
_
,
err
:=
os
.
Stat
(
filepath
.
Join
(
td
,
"foo.vmx"
));
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
data
,
err
:=
ioutil
.
ReadFile
(
filepath
.
Join
(
td
,
"foo.vmx"
))
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
if
string
(
data
)
!=
"foo"
{
t
.
Fatalf
(
"bad: %#v"
,
string
(
data
))
if
!
driver
.
CloneCalled
{
t
.
Fatal
(
"clone should be called"
)
}
}
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