Merge pull request #1461 from rickard-von-essen/issue_1404

parallels-pvm: Optionally assign new MAC addresses to imported VMs
This commit is contained in:
Mitchell Hashimoto 2014-09-05 09:27:09 -07:00
commit ba07866774
6 changed files with 17 additions and 8 deletions

View File

@ -16,7 +16,7 @@ import (
// extremely specific.
type Driver interface {
// Import a VM
Import(string, string, string) error
Import(string, string, string, bool) error
// Checks if the VM with the given name is running.
IsRunning(string) (bool, error)

View File

@ -19,7 +19,7 @@ type Parallels9Driver struct {
PrlctlPath string
}
func (d *Parallels9Driver) Import(name, srcPath, dstDir string) error {
func (d *Parallels9Driver) Import(name, srcPath, dstDir string, reassignMac bool) error {
err := d.Prlctl("register", srcPath, "--preserve-uuid")
if err != nil {
@ -31,10 +31,13 @@ func (d *Parallels9Driver) Import(name, srcPath, dstDir string) error {
return err
}
srcMac, err := getFirtsMacAddress(srcPath)
srcMac := "auto"
if !reassignMac {
srcMac, err = getFirtsMacAddress(srcPath)
if err != nil {
return err
}
}
err = d.Prlctl("clone", srcId, "--name", name, "--dst", dstDir)
if err != nil {

View File

@ -45,7 +45,7 @@ type DriverMock struct {
IpAddressError error
}
func (d *DriverMock) Import(name, srcPath, dstPath string) error {
func (d *DriverMock) Import(name, srcPath, dstPath string, reassignMac bool) error {
d.ImportCalled = true
d.ImportName = name
d.ImportSrcPath = srcPath

View File

@ -2,10 +2,11 @@ package pvm
import (
"fmt"
"os"
parallelscommon "github.com/mitchellh/packer/builder/parallels/common"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/packer"
"os"
)
// Config is the configuration structure for the builder.
@ -23,6 +24,7 @@ type Config struct {
BootCommand []string `mapstructure:"boot_command"`
SourcePath string `mapstructure:"source_path"`
VMName string `mapstructure:"vm_name"`
ReassignMac bool `mapstructure:"reassign_mac"`
tpl *packer.ConfigTemplate
}

View File

@ -20,7 +20,7 @@ func (s *StepImport) Run(state multistep.StateBag) multistep.StepAction {
config := state.Get("config").(*Config)
ui.Say(fmt.Sprintf("Importing VM: %s", s.SourcePath))
if err := driver.Import(s.Name, s.SourcePath, config.OutputDir); err != nil {
if err := driver.Import(s.Name, s.SourcePath, config.OutputDir, config.ReassignMac); err != nil {
err := fmt.Errorf("Error importing VM: %s", err)
state.Put("error", err)
ui.Error(err.Error())

View File

@ -78,6 +78,10 @@ each category, the available options are alphabetized and described.
be attached. The files listed in this configuration will all be put
into the root directory of the floppy disk; sub-directories are not supported.
* `reassign_mac` (boolean) - If this is "false" the MAC address of the first
NIC will reused when imported else a new MAC address will be generated by
Parallels. Defaults to "false".
* `output_directory` (string) - This is the path to the directory where the
resulting virtual machine will be created. This may be relative or absolute.
If relative, the path is relative to the working directory when `packer`