Add support to vmware-vmx builder for linked clones.
This commit is contained in:
parent
6226992757
commit
d05a601d00
|
@ -41,6 +41,7 @@ func (s *stepRun) Run(_ context.Context, state multistep.StateBag) multistep.Ste
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ui.Message(fmt.Sprintf("command:=%s", command))
|
||||||
if err := driver.Qemu(command...); err != nil {
|
if err := driver.Qemu(command...); err != nil {
|
||||||
err := fmt.Errorf("Error launching VM: %s", err)
|
err := fmt.Errorf("Error launching VM: %s", err)
|
||||||
ui.Error(err.Error())
|
ui.Error(err.Error())
|
||||||
|
@ -104,6 +105,9 @@ func getCommandArgs(bootDrive string, state multistep.StateBag) ([]string, error
|
||||||
} else {
|
} else {
|
||||||
driveArgs = append(driveArgs, fmt.Sprintf("file=%s,if=%s,cache=%s,format=%s", imgPath, config.DiskInterface, config.DiskCache, config.Format))
|
driveArgs = append(driveArgs, fmt.Sprintf("file=%s,if=%s,cache=%s,format=%s", imgPath, config.DiskInterface, config.DiskCache, config.Format))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ui.Message(fmt.Sprintf("config.NetDevice:=%s", config.NetDevice))
|
||||||
|
|
||||||
deviceArgs = append(deviceArgs, fmt.Sprintf("%s,netdev=user.0", config.NetDevice))
|
deviceArgs = append(deviceArgs, fmt.Sprintf("%s,netdev=user.0", config.NetDevice))
|
||||||
|
|
||||||
if config.Headless == true {
|
if config.Headless == true {
|
||||||
|
|
|
@ -23,7 +23,7 @@ type Driver interface {
|
||||||
// Clone clones the VMX and the disk to the destination path. The
|
// 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
|
// destination is a path to the VMX file. The disk will be copied
|
||||||
// to that same directory.
|
// to that same directory.
|
||||||
Clone(dst string, src string) error
|
Clone(dst string, src string, cloneType bool) error
|
||||||
|
|
||||||
// CompactDisk compacts a virtual disk.
|
// CompactDisk compacts a virtual disk.
|
||||||
CompactDisk(string) error
|
CompactDisk(string) error
|
||||||
|
|
|
@ -24,7 +24,7 @@ type Fusion5Driver struct {
|
||||||
SSHConfig *SSHConfig
|
SSHConfig *SSHConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Fusion5Driver) Clone(dst, src string) error {
|
func (d *Fusion5Driver) Clone(dst, src string, linked bool) error {
|
||||||
return errors.New("Cloning is not supported with Fusion 5. Please use Fusion 6+.")
|
return errors.New("Cloning is not supported with Fusion 5. Please use Fusion 6+.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ type Fusion6Driver struct {
|
||||||
Fusion5Driver
|
Fusion5Driver
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Fusion6Driver) Clone(dst, src string) error {
|
func (d *Fusion6Driver) Clone(dst, src string, linked bool) error {
|
||||||
cmd := exec.Command(d.vmrunPath(),
|
cmd := exec.Command(d.vmrunPath(),
|
||||||
"-T", "fusion",
|
"-T", "fusion",
|
||||||
"clone", src, dst,
|
"clone", src, dst,
|
||||||
|
|
|
@ -13,6 +13,7 @@ type DriverMock struct {
|
||||||
CloneCalled bool
|
CloneCalled bool
|
||||||
CloneDst string
|
CloneDst string
|
||||||
CloneSrc string
|
CloneSrc string
|
||||||
|
Linked bool
|
||||||
CloneErr error
|
CloneErr error
|
||||||
|
|
||||||
CompactDiskCalled bool
|
CompactDiskCalled bool
|
||||||
|
@ -107,10 +108,11 @@ func (m NetworkMapperMock) DeviceIntoName(device string) (string, error) {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DriverMock) Clone(dst string, src string) error {
|
func (d *DriverMock) Clone(dst string, src string, linked bool) error {
|
||||||
d.CloneCalled = true
|
d.CloneCalled = true
|
||||||
d.CloneDst = dst
|
d.CloneDst = dst
|
||||||
d.CloneSrc = src
|
d.CloneSrc = src
|
||||||
|
d.Linked = linked
|
||||||
return d.CloneErr
|
return d.CloneErr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ type Player5Driver struct {
|
||||||
SSHConfig *SSHConfig
|
SSHConfig *SSHConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Player5Driver) Clone(dst, src string) error {
|
func (d *Player5Driver) Clone(dst, src string, linked bool) error {
|
||||||
return errors.New("Cloning is not supported with VMWare Player version 5. Please use VMWare Player version 6, or greater.")
|
return errors.New("Cloning is not supported with VMWare Player version 5. Please use VMWare Player version 6, or greater.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ type Player6Driver struct {
|
||||||
Player5Driver
|
Player5Driver
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Player6Driver) Clone(dst, src string) error {
|
func (d *Player6Driver) Clone(dst, src string, linked bool) error {
|
||||||
// TODO(rasa) check if running player+, not just player
|
// TODO(rasa) check if running player+, not just player
|
||||||
|
|
||||||
cmd := exec.Command(d.Player5Driver.VmrunPath,
|
cmd := exec.Command(d.Player5Driver.VmrunPath,
|
||||||
|
|
|
@ -13,11 +13,19 @@ type Workstation10Driver struct {
|
||||||
Workstation9Driver
|
Workstation9Driver
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Workstation10Driver) Clone(dst, src string) error {
|
func (d *Workstation10Driver) Clone(dst, src string, linked bool) error {
|
||||||
|
|
||||||
|
var cloneType string
|
||||||
|
if linked {
|
||||||
|
cloneType = "linked"
|
||||||
|
} else {
|
||||||
|
cloneType = "full"
|
||||||
|
}
|
||||||
|
|
||||||
cmd := exec.Command(d.Workstation9Driver.VmrunPath,
|
cmd := exec.Command(d.Workstation9Driver.VmrunPath,
|
||||||
"-T", "ws",
|
"-T", "ws",
|
||||||
"clone", src, dst,
|
"clone", src, dst,
|
||||||
"full")
|
cloneType)
|
||||||
|
|
||||||
if _, _, err := runAndLog(cmd); err != nil {
|
if _, _, err := runAndLog(cmd); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -24,7 +24,7 @@ type Workstation9Driver struct {
|
||||||
SSHConfig *SSHConfig
|
SSHConfig *SSHConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Workstation9Driver) Clone(dst, src string) error {
|
func (d *Workstation9Driver) Clone(dst, src string, linked bool) error {
|
||||||
return errors.New("Cloning is not supported with VMware WS version 9. Please use VMware WS version 10, or greater.")
|
return errors.New("Cloning is not supported with VMware WS version 9. Please use VMware WS version 10, or greater.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ type ESX5Driver struct {
|
||||||
vmId string
|
vmId string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *ESX5Driver) Clone(dst, src string) error {
|
func (d *ESX5Driver) Clone(dst, src string, linked bool) error {
|
||||||
return errors.New("Cloning is not supported with the ESX driver.")
|
return errors.New("Cloning is not supported with the ESX driver.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,6 +69,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
||||||
OutputDir: b.config.OutputDir,
|
OutputDir: b.config.OutputDir,
|
||||||
Path: b.config.SourcePath,
|
Path: b.config.SourcePath,
|
||||||
VMName: b.config.VMName,
|
VMName: b.config.VMName,
|
||||||
|
Linked: b.config.Linked,
|
||||||
},
|
},
|
||||||
&vmwcommon.StepConfigureVMX{
|
&vmwcommon.StepConfigureVMX{
|
||||||
CustomData: b.config.VMXData,
|
CustomData: b.config.VMXData,
|
||||||
|
|
|
@ -26,6 +26,7 @@ type Config struct {
|
||||||
vmwcommon.ToolsConfig `mapstructure:",squash"`
|
vmwcommon.ToolsConfig `mapstructure:",squash"`
|
||||||
vmwcommon.VMXConfig `mapstructure:",squash"`
|
vmwcommon.VMXConfig `mapstructure:",squash"`
|
||||||
|
|
||||||
|
Linked bool `mapstructure:"linked"`
|
||||||
RemoteType string `mapstructure:"remote_type"`
|
RemoteType string `mapstructure:"remote_type"`
|
||||||
SkipCompaction bool `mapstructure:"skip_compaction"`
|
SkipCompaction bool `mapstructure:"skip_compaction"`
|
||||||
SourcePath string `mapstructure:"source_path"`
|
SourcePath string `mapstructure:"source_path"`
|
||||||
|
|
|
@ -17,6 +17,7 @@ type StepCloneVMX struct {
|
||||||
OutputDir string
|
OutputDir string
|
||||||
Path string
|
Path string
|
||||||
VMName string
|
VMName string
|
||||||
|
Linked bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type vmxAdapter struct {
|
type vmxAdapter struct {
|
||||||
|
@ -64,7 +65,7 @@ func (s *StepCloneVMX) Run(_ context.Context, state multistep.StateBag) multiste
|
||||||
ui.Say("Cloning source VM...")
|
ui.Say("Cloning source VM...")
|
||||||
log.Printf("Cloning from: %s", s.Path)
|
log.Printf("Cloning from: %s", s.Path)
|
||||||
log.Printf("Cloning to: %s", vmxPath)
|
log.Printf("Cloning to: %s", vmxPath)
|
||||||
if err := driver.Clone(vmxPath, s.Path); err != nil {
|
if err := driver.Clone(vmxPath, s.Path, s.Linked); err != nil {
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
|
|
|
@ -137,6 +137,9 @@ builder.
|
||||||
doesn't shut down in this time, it is an error. By default, the timeout is
|
doesn't shut down in this time, it is an error. By default, the timeout is
|
||||||
`5m` or five minutes.
|
`5m` or five minutes.
|
||||||
|
|
||||||
|
- `linked` (boolean) - Virtual machine is created a linked clone.
|
||||||
|
Defaults to `false`.
|
||||||
|
|
||||||
- `skip_compaction` (boolean) - VMware-created disks are defragmented and
|
- `skip_compaction` (boolean) - VMware-created disks are defragmented and
|
||||||
compacted at the end of the build process using `vmware-vdiskmanager`. In
|
compacted at the end of the build process using `vmware-vdiskmanager`. In
|
||||||
certain rare cases, this might actually end up making the resulting disks
|
certain rare cases, this might actually end up making the resulting disks
|
||||||
|
|
Loading…
Reference in New Issue