Commit 5ad7737d authored by Rickard von Essen's avatar Rickard von Essen

parallels-pvm: Optionally assign new MAC addresses to imported VMs [GH-1404]

New config option:
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".
parent dabbcd45
......@@ -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)
......
......@@ -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,9 +31,12 @@ func (d *Parallels9Driver) Import(name, srcPath, dstDir string) error {
return err
}
srcMac, err := getFirtsMacAddress(srcPath)
if err != nil {
return err
srcMac := "auto"
if !reassignMac {
srcMac, err = getFirtsMacAddress(srcPath)
if err != nil {
return err
}
}
err = d.Prlctl("clone", srcId, "--name", name, "--dst", dstDir)
......
......@@ -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
......
......@@ -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
}
......
......@@ -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())
......
......@@ -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`
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment