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 ( ...@@ -16,7 +16,7 @@ import (
// extremely specific. // extremely specific.
type Driver interface { type Driver interface {
// Import a VM // Import a VM
Import(string, string, string) error Import(string, string, string, bool) error
// Checks if the VM with the given name is running. // Checks if the VM with the given name is running.
IsRunning(string) (bool, error) IsRunning(string) (bool, error)
......
...@@ -19,7 +19,7 @@ type Parallels9Driver struct { ...@@ -19,7 +19,7 @@ type Parallels9Driver struct {
PrlctlPath string 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") err := d.Prlctl("register", srcPath, "--preserve-uuid")
if err != nil { if err != nil {
...@@ -31,10 +31,13 @@ func (d *Parallels9Driver) Import(name, srcPath, dstDir string) error { ...@@ -31,10 +31,13 @@ func (d *Parallels9Driver) Import(name, srcPath, dstDir string) error {
return err return err
} }
srcMac, err := getFirtsMacAddress(srcPath) srcMac := "auto"
if !reassignMac {
srcMac, err = getFirtsMacAddress(srcPath)
if err != nil { if err != nil {
return err return err
} }
}
err = d.Prlctl("clone", srcId, "--name", name, "--dst", dstDir) err = d.Prlctl("clone", srcId, "--name", name, "--dst", dstDir)
if err != nil { if err != nil {
......
...@@ -45,7 +45,7 @@ type DriverMock struct { ...@@ -45,7 +45,7 @@ type DriverMock struct {
IpAddressError error 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.ImportCalled = true
d.ImportName = name d.ImportName = name
d.ImportSrcPath = srcPath d.ImportSrcPath = srcPath
......
...@@ -2,10 +2,11 @@ package pvm ...@@ -2,10 +2,11 @@ package pvm
import ( import (
"fmt" "fmt"
"os"
parallelscommon "github.com/mitchellh/packer/builder/parallels/common" parallelscommon "github.com/mitchellh/packer/builder/parallels/common"
"github.com/mitchellh/packer/common" "github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
"os"
) )
// Config is the configuration structure for the builder. // Config is the configuration structure for the builder.
...@@ -23,6 +24,7 @@ type Config struct { ...@@ -23,6 +24,7 @@ type Config struct {
BootCommand []string `mapstructure:"boot_command"` BootCommand []string `mapstructure:"boot_command"`
SourcePath string `mapstructure:"source_path"` SourcePath string `mapstructure:"source_path"`
VMName string `mapstructure:"vm_name"` VMName string `mapstructure:"vm_name"`
ReassignMac bool `mapstructure:"reassign_mac"`
tpl *packer.ConfigTemplate tpl *packer.ConfigTemplate
} }
......
...@@ -20,7 +20,7 @@ func (s *StepImport) Run(state multistep.StateBag) multistep.StepAction { ...@@ -20,7 +20,7 @@ func (s *StepImport) Run(state multistep.StateBag) multistep.StepAction {
config := state.Get("config").(*Config) config := state.Get("config").(*Config)
ui.Say(fmt.Sprintf("Importing VM: %s", s.SourcePath)) 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) err := fmt.Errorf("Error importing VM: %s", err)
state.Put("error", err) state.Put("error", err)
ui.Error(err.Error()) ui.Error(err.Error())
......
...@@ -78,6 +78,10 @@ each category, the available options are alphabetized and described. ...@@ -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 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. 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 * `output_directory` (string) - This is the path to the directory where the
resulting virtual machine will be created. This may be relative or absolute. resulting virtual machine will be created. This may be relative or absolute.
If relative, the path is relative to the working directory when `packer` 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