diff --git a/builder/parallels/common/driver.go b/builder/parallels/common/driver.go index fb83e52d1..470d17f28 100644 --- a/builder/parallels/common/driver.go +++ b/builder/parallels/common/driver.go @@ -20,7 +20,7 @@ type Driver interface { CompactDisk(string) error // Adds new CD/DVD drive to the VM and returns name of this device - DeviceAddCdRom(string, string) (string, error) + DeviceAddCDROM(string, string) (string, error) // Get path to the first virtual disk image DiskPath(string) (string, error) @@ -38,7 +38,7 @@ type Driver interface { Prlctl(...string) error // Get the path to the Parallels Tools ISO for the given flavor. - ToolsIsoPath(string) (string, error) + ToolsISOPath(string) (string, error) // Verify checks to make sure that this driver should function // properly. If there is any indication the driver can't function, @@ -55,10 +55,10 @@ type Driver interface { SetDefaultConfiguration(string) error // Finds the MAC address of the NIC nic0 - Mac(string) (string, error) + MAC(string) (string, error) // Finds the IP address of a VM connected that uses DHCP by its MAC address - IpAddress(string) (string, error) + IPAddress(string) (string, error) } func NewDriver() (Driver, error) { @@ -66,7 +66,7 @@ func NewDriver() (Driver, error) { var prlctlPath string var prlsrvctlPath string var supportedVersions []string - dhcp_lease_file := "/Library/Preferences/Parallels/parallels_dhcp_leases" + DHCPLeaseFile := "/Library/Preferences/Parallels/parallels_dhcp_leases" if runtime.GOOS != "darwin" { return nil, fmt.Errorf( @@ -96,22 +96,22 @@ func NewDriver() (Driver, error) { drivers = map[string]Driver{ "11": &Parallels11Driver{ Parallels9Driver: Parallels9Driver{ - PrlctlPath: prlctlPath, - PrlsrvctlPath: prlsrvctlPath, - dhcp_lease_file: dhcp_lease_file, + PrlctlPath: prlctlPath, + PrlsrvctlPath: prlsrvctlPath, + dhcpLeaseFile: DHCPLeaseFile, }, }, "10": &Parallels10Driver{ Parallels9Driver: Parallels9Driver{ - PrlctlPath: prlctlPath, - PrlsrvctlPath: prlsrvctlPath, - dhcp_lease_file: dhcp_lease_file, + PrlctlPath: prlctlPath, + PrlsrvctlPath: prlsrvctlPath, + dhcpLeaseFile: DHCPLeaseFile, }, }, "9": &Parallels9Driver{ - PrlctlPath: prlctlPath, - PrlsrvctlPath: prlsrvctlPath, - dhcp_lease_file: dhcp_lease_file, + PrlctlPath: prlctlPath, + PrlsrvctlPath: prlsrvctlPath, + dhcpLeaseFile: DHCPLeaseFile, }, } diff --git a/builder/parallels/common/driver_9.go b/builder/parallels/common/driver_9.go index aa11d1c0e..edd6c16ab 100644 --- a/builder/parallels/common/driver_9.go +++ b/builder/parallels/common/driver_9.go @@ -24,48 +24,51 @@ type Parallels9Driver struct { PrlsrvctlPath string // The path to the parallels_dhcp_leases file - dhcp_lease_file string + dhcpLeaseFile string } -func (d *Parallels9Driver) Import(name, srcPath, dstDir string, reassignMac bool) error { +func (d *Parallels9Driver) Import(name, srcPath, dstDir string, reassignMAC bool) error { err := d.Prlctl("register", srcPath, "--preserve-uuid") if err != nil { return err } - srcId, err := getVmId(srcPath) + srcID, err := getVMID(srcPath) if err != nil { return err } - srcMac := "auto" - if !reassignMac { - 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) + err = d.Prlctl("clone", srcID, "--name", name, "--dst", dstDir) if err != nil { return err } - err = d.Prlctl("unregister", srcId) + err = d.Prlctl("unregister", srcID) if err != nil { return err } - err = d.Prlctl("set", name, "--device-set", "net0", "--mac", srcMac) + err = d.Prlctl("set", name, "--device-set", "net0", "--mac", srcMAC) + if err != nil { + return err + } return nil } -func getVmId(path string) (string, error) { +func getVMID(path string) (string, error) { return getConfigValueFromXpath(path, "/ParallelsVirtualMachine/Identification/VmUuid") } -func getFirtsMacAddress(path string) (string, error) { +func getFirtsMACAddress(path string) (string, error) { return getConfigValueFromXpath(path, "/ParallelsVirtualMachine/Hardware/NetworkAdapter[@id='0']/MAC") } @@ -84,10 +87,10 @@ func getConfigValueFromXpath(path, xpath string) (string, error) { } // Finds an application bundle by identifier (for "darwin" platform only) -func getAppPath(bundleId string) (string, error) { +func getAppPath(bundleID string) (string, error) { var stdout bytes.Buffer - cmd := exec.Command("mdfind", "kMDItemCFBundleIdentifier ==", bundleId) + cmd := exec.Command("mdfind", "kMDItemCFBundleIdentifier ==", bundleID) cmd.Stdout = &stdout if err := cmd.Run(); err != nil { return "", err @@ -135,7 +138,7 @@ func (d *Parallels9Driver) CompactDisk(diskPath string) error { return nil } -func (d *Parallels9Driver) DeviceAddCdRom(name string, image string) (string, error) { +func (d *Parallels9Driver) DeviceAddCDROM(name string, image string) (string, error) { command := []string{ "set", name, "--device-add", "cdrom", @@ -154,8 +157,8 @@ func (d *Parallels9Driver) DeviceAddCdRom(name string, image string) (string, er "Could not determine cdrom device name in the output:\n%s", string(out)) } - device_name := matches[1] - return device_name, nil + deviceName := matches[1] + return deviceName, nil } func (d *Parallels9Driver) DiskPath(name string) (string, error) { @@ -164,15 +167,15 @@ func (d *Parallels9Driver) DiskPath(name string) (string, error) { return "", err } - hddRe := regexp.MustCompile("hdd0.* image='(.*)' type=*") - matches := hddRe.FindStringSubmatch(string(out)) + HDDRe := regexp.MustCompile("hdd0.* image='(.*)' type=*") + matches := HDDRe.FindStringSubmatch(string(out)) if matches == nil { return "", fmt.Errorf( "Could not determine hdd image path in the output:\n%s", string(out)) } - hdd_path := matches[1] - return hdd_path, nil + HDDPath := matches[1] + return HDDPath, nil } func (d *Parallels9Driver) IsRunning(name string) (bool, error) { @@ -328,7 +331,7 @@ func (d *Parallels9Driver) SetDefaultConfiguration(vmName string) error { return nil } -func (d *Parallels9Driver) Mac(vmName string) (string, error) { +func (d *Parallels9Driver) MAC(vmName string) (string, error) { var stdout bytes.Buffer cmd := exec.Command(d.PrlctlPath, "list", "-i", vmName) @@ -351,26 +354,26 @@ func (d *Parallels9Driver) Mac(vmName string) (string, error) { return mac, nil } -// Finds the IP address of a VM connected that uses DHCP by its MAC address +// IPAddress finds the IP address of a VM connected that uses DHCP by its MAC address // // Parses the file /Library/Preferences/Parallels/parallels_dhcp_leases // file contain a list of DHCP leases given by Parallels Desktop // Example line: // 10.211.55.181="1418921112,1800,001c42f593fb,ff42f593fb000100011c25b9ff001c42f593fb" // IP Address ="Lease expiry, Lease time, MAC, MAC or DUID" -func (d *Parallels9Driver) IpAddress(mac string) (string, error) { +func (d *Parallels9Driver) IPAddress(mac string) (string, error) { if len(mac) != 12 { return "", fmt.Errorf("Not a valid MAC address: %s. It should be exactly 12 digits.", mac) } - leases, err := ioutil.ReadFile(d.dhcp_lease_file) + leases, err := ioutil.ReadFile(d.dhcpLeaseFile) if err != nil { return "", err } re := regexp.MustCompile("(.*)=\"(.*),(.*)," + strings.ToLower(mac) + ",.*\"") - mostRecentIp := "" + mostRecentIP := "" mostRecentLease := uint64(0) for _, l := range re.FindAllStringSubmatch(string(leases), -1) { ip := l[1] @@ -378,20 +381,20 @@ func (d *Parallels9Driver) IpAddress(mac string) (string, error) { leaseTime, _ := strconv.ParseUint(l[3], 10, 32) log.Printf("Found lease: %s for MAC: %s, expiring at %d, leased for %d s.\n", ip, mac, expiry, leaseTime) if mostRecentLease <= expiry-leaseTime { - mostRecentIp = ip + mostRecentIP = ip mostRecentLease = expiry - leaseTime } } - if len(mostRecentIp) == 0 { - return "", fmt.Errorf("IP lease not found for MAC address %s in: %s\n", mac, d.dhcp_lease_file) + if len(mostRecentIP) == 0 { + return "", fmt.Errorf("IP lease not found for MAC address %s in: %s\n", mac, d.dhcpLeaseFile) } - log.Printf("Found IP lease: %s for MAC address %s\n", mostRecentIp, mac) - return mostRecentIp, nil + log.Printf("Found IP lease: %s for MAC address %s\n", mostRecentIP, mac) + return mostRecentIP, nil } -func (d *Parallels9Driver) ToolsIsoPath(k string) (string, error) { +func (d *Parallels9Driver) ToolsISOPath(k string) (string, error) { appPath, err := getAppPath("com.parallels.desktop.console") if err != nil { return "", err diff --git a/builder/parallels/common/driver_9_test.go b/builder/parallels/common/driver_9_test.go index 02fb4faf8..f57ef663a 100644 --- a/builder/parallels/common/driver_9_test.go +++ b/builder/parallels/common/driver_9_test.go @@ -10,7 +10,7 @@ func TestParallels9Driver_impl(t *testing.T) { var _ Driver = new(Parallels9Driver) } -func TestIpAddress(t *testing.T) { +func TestIPAddress(t *testing.T) { tf, err := ioutil.TempFile("", "packer") if err != nil { t.Fatalf("err: %s", err) @@ -18,11 +18,11 @@ func TestIpAddress(t *testing.T) { defer os.Remove(tf.Name()) d := Parallels9Driver{ - dhcp_lease_file: tf.Name(), + dhcpLeaseFile: tf.Name(), } // No lease should be found in an empty file - ip, err := d.IpAddress("123456789012") + ip, err := d.IPAddress("123456789012") if err == nil { t.Fatalf("Found IP: \"%v\". No IP should be found!\n", ip) } @@ -35,7 +35,7 @@ func TestIpAddress(t *testing.T) { 10.211.55.254="1411712008,1800,001c42a51419,01001c42a51419" `) ioutil.WriteFile(tf.Name(), c, 0666) - ip, err = d.IpAddress("001C4235240c") + ip, err = d.IPAddress("001C4235240c") if err != nil { t.Fatalf("Error: %v\n", err) } @@ -50,7 +50,7 @@ func TestIpAddress(t *testing.T) { 10.211.55.254="1411712008,1800,001c42a51419,01001c42a51419" `) ioutil.WriteFile(tf.Name(), c, 0666) - ip, err = d.IpAddress("001c4235240c") + ip, err = d.IPAddress("001c4235240c") if err != nil { t.Fatalf("Error: %v\n", err) } diff --git a/builder/parallels/common/driver_mock.go b/builder/parallels/common/driver_mock.go index fcd6b4b88..301ca8b9c 100644 --- a/builder/parallels/common/driver_mock.go +++ b/builder/parallels/common/driver_mock.go @@ -9,11 +9,11 @@ type DriverMock struct { CompactDiskPath string CompactDiskErr error - DeviceAddCdRomCalled bool - DeviceAddCdRomName string - DeviceAddCdRomImage string - DeviceAddCdRomResult string - DeviceAddCdRomErr error + DeviceAddCDROMCalled bool + DeviceAddCDROMName string + DeviceAddCDROMImage string + DeviceAddCDROMResult string + DeviceAddCDROMErr error DiskPathCalled bool DiskPathName string @@ -49,18 +49,18 @@ type DriverMock struct { SetDefaultConfigurationCalled bool SetDefaultConfigurationError error - ToolsIsoPathCalled bool - ToolsIsoPathFlavor string - ToolsIsoPathResult string - ToolsIsoPathErr error + ToolsISOPathCalled bool + ToolsISOPathFlavor string + ToolsISOPathResult string + ToolsISOPathErr error - MacName string - MacReturn string - MacError error + MACName string + MACReturn string + MACError error - IpAddressMac string - IpAddressReturn string - IpAddressError error + IPAddressMAC string + IPAddressReturn string + IPAddressError error } func (d *DriverMock) CompactDisk(path string) error { @@ -69,11 +69,11 @@ func (d *DriverMock) CompactDisk(path string) error { return d.CompactDiskErr } -func (d *DriverMock) DeviceAddCdRom(name string, image string) (string, error) { - d.DeviceAddCdRomCalled = true - d.DeviceAddCdRomName = name - d.DeviceAddCdRomImage = image - return d.DeviceAddCdRomResult, d.DeviceAddCdRomErr +func (d *DriverMock) DeviceAddCDROM(name string, image string) (string, error) { + d.DeviceAddCDROMCalled = true + d.DeviceAddCDROMName = name + d.DeviceAddCDROMImage = image + return d.DeviceAddCDROMResult, d.DeviceAddCDROMErr } func (d *DriverMock) DiskPath(name string) (string, error) { @@ -82,7 +82,7 @@ func (d *DriverMock) DiskPath(name string) (string, error) { return d.DiskPathResult, d.DiskPathErr } -func (d *DriverMock) Import(name, srcPath, dstPath string, reassignMac bool) error { +func (d *DriverMock) Import(name, srcPath, dstPath string, reassignMAC bool) error { d.ImportCalled = true d.ImportName = name d.ImportSrcPath = srcPath @@ -136,18 +136,18 @@ func (d *DriverMock) SetDefaultConfiguration(name string) error { return d.SetDefaultConfigurationError } -func (d *DriverMock) Mac(name string) (string, error) { - d.MacName = name - return d.MacReturn, d.MacError +func (d *DriverMock) MAC(name string) (string, error) { + d.MACName = name + return d.MACReturn, d.MACError } -func (d *DriverMock) IpAddress(mac string) (string, error) { - d.IpAddressMac = mac - return d.IpAddressReturn, d.IpAddressError +func (d *DriverMock) IPAddress(mac string) (string, error) { + d.IPAddressMAC = mac + return d.IPAddressReturn, d.IPAddressError } -func (d *DriverMock) ToolsIsoPath(flavor string) (string, error) { - d.ToolsIsoPathCalled = true - d.ToolsIsoPathFlavor = flavor - return d.ToolsIsoPathResult, d.ToolsIsoPathErr +func (d *DriverMock) ToolsISOPath(flavor string) (string, error) { + d.ToolsISOPathCalled = true + d.ToolsISOPathFlavor = flavor + return d.ToolsISOPathResult, d.ToolsISOPathErr } diff --git a/builder/parallels/common/ssh.go b/builder/parallels/common/ssh.go index 35b43311e..2c71c75a3 100644 --- a/builder/parallels/common/ssh.go +++ b/builder/parallels/common/ssh.go @@ -11,12 +11,12 @@ func CommHost(state multistep.StateBag) (string, error) { vmName := state.Get("vmName").(string) driver := state.Get("driver").(Driver) - mac, err := driver.Mac(vmName) + mac, err := driver.MAC(vmName) if err != nil { return "", err } - ip, err := driver.IpAddress(mac) + ip, err := driver.IPAddress(mac) if err != nil { return "", err } diff --git a/builder/parallels/common/step_attach_floppy.go b/builder/parallels/common/step_attach_floppy.go index 0e8fba021..782613d21 100644 --- a/builder/parallels/common/step_attach_floppy.go +++ b/builder/parallels/common/step_attach_floppy.go @@ -35,22 +35,22 @@ func (s *StepAttachFloppy) Run(state multistep.StateBag) multistep.StepAction { ui.Say("Deleting any current floppy disk...") // Delete the floppy disk controller - del_command := []string{ + delCommand := []string{ "set", vmName, "--device-del", "fdd0", } // This will almost certainly fail with 'The fdd0 device does not exist.' - driver.Prlctl(del_command...) + driver.Prlctl(delCommand...) ui.Say("Attaching floppy disk...") // Attaching the floppy disk - add_command := []string{ + addCommand := []string{ "set", vmName, "--device-add", "fdd", "--image", floppyPath, "--connect", } - if err := driver.Prlctl(add_command...); err != nil { + if err := driver.Prlctl(addCommand...); err != nil { state.Put("error", fmt.Errorf("Error adding floppy: %s", err)) return multistep.ActionHalt } diff --git a/builder/parallels/common/step_attach_parallels_tools.go b/builder/parallels/common/step_attach_parallels_tools.go index f681a83f1..aeadceb31 100644 --- a/builder/parallels/common/step_attach_parallels_tools.go +++ b/builder/parallels/common/step_attach_parallels_tools.go @@ -2,9 +2,10 @@ package common import ( "fmt" + "log" + "github.com/mitchellh/multistep" "github.com/mitchellh/packer/packer" - "log" ) // This step attaches the Parallels Tools as an inserted CD onto @@ -39,7 +40,7 @@ func (s *StepAttachParallelsTools) Run(state multistep.StateBag) multistep.StepA // Attach the guest additions to the computer ui.Say("Attaching Parallels Tools ISO to the new CD/DVD drive...") - cdrom, err := driver.DeviceAddCdRom(vmName, parallelsToolsPath) + cdrom, err := driver.DeviceAddCDROM(vmName, parallelsToolsPath) if err != nil { err := fmt.Errorf("Error attaching Parallels Tools ISO: %s", err) diff --git a/builder/parallels/common/step_prepare_parallels_tools.go b/builder/parallels/common/step_prepare_parallels_tools.go index 752268fd7..bf05796d2 100644 --- a/builder/parallels/common/step_prepare_parallels_tools.go +++ b/builder/parallels/common/step_prepare_parallels_tools.go @@ -25,7 +25,7 @@ func (s *StepPrepareParallelsTools) Run(state multistep.StateBag) multistep.Step return multistep.ActionContinue } - path, err := driver.ToolsIsoPath(s.ParallelsToolsFlavor) + path, err := driver.ToolsISOPath(s.ParallelsToolsFlavor) if err != nil { state.Put("error", err) diff --git a/builder/parallels/common/step_prepare_parallels_tools_test.go b/builder/parallels/common/step_prepare_parallels_tools_test.go index 931ecb972..0647149e5 100644 --- a/builder/parallels/common/step_prepare_parallels_tools_test.go +++ b/builder/parallels/common/step_prepare_parallels_tools_test.go @@ -29,7 +29,7 @@ func TestStepPrepareParallelsTools(t *testing.T) { driver := state.Get("driver").(*DriverMock) // Mock results - driver.ToolsIsoPathResult = tf.Name() + driver.ToolsISOPathResult = tf.Name() // Test the run if action := step.Run(state); action != multistep.ActionContinue { @@ -40,11 +40,11 @@ func TestStepPrepareParallelsTools(t *testing.T) { } // Test the driver - if !driver.ToolsIsoPathCalled { + if !driver.ToolsISOPathCalled { t.Fatal("tools iso path should be called") } - if driver.ToolsIsoPathFlavor != "foo" { - t.Fatalf("bad: %#v", driver.ToolsIsoPathFlavor) + if driver.ToolsISOPathFlavor != "foo" { + t.Fatalf("bad: %#v", driver.ToolsISOPathFlavor) } // Test the resulting state @@ -75,8 +75,8 @@ func TestStepPrepareParallelsTools_disabled(t *testing.T) { } // Test the driver - if driver.ToolsIsoPathCalled { - t.Fatal("tools iso path should NOT be called") + if driver.ToolsISOPathCalled { + t.Fatal("tools ISO path should NOT be called") } } @@ -90,7 +90,7 @@ func TestStepPrepareParallelsTools_nonExist(t *testing.T) { driver := state.Get("driver").(*DriverMock) // Mock results - driver.ToolsIsoPathResult = "foo" + driver.ToolsISOPathResult = "foo" // Test the run if action := step.Run(state); action != multistep.ActionHalt { @@ -101,11 +101,11 @@ func TestStepPrepareParallelsTools_nonExist(t *testing.T) { } // Test the driver - if !driver.ToolsIsoPathCalled { + if !driver.ToolsISOPathCalled { t.Fatal("tools iso path should be called") } - if driver.ToolsIsoPathFlavor != "foo" { - t.Fatalf("bad: %#v", driver.ToolsIsoPathFlavor) + if driver.ToolsISOPathFlavor != "foo" { + t.Fatalf("bad: %#v", driver.ToolsISOPathFlavor) } // Test the resulting state diff --git a/builder/parallels/iso/step_attach_iso.go b/builder/parallels/iso/step_attach_iso.go index 049f2edf3..628688976 100644 --- a/builder/parallels/iso/step_attach_iso.go +++ b/builder/parallels/iso/step_attach_iso.go @@ -12,7 +12,7 @@ import ( // // Uses: // driver Driver -// isoPath string +// iso_path string // ui packer.Ui // vmName string // diff --git a/builder/parallels/pvm/config.go b/builder/parallels/pvm/config.go index 47e90d7a6..ddcadcfee 100644 --- a/builder/parallels/pvm/config.go +++ b/builder/parallels/pvm/config.go @@ -27,7 +27,7 @@ type Config struct { BootCommand []string `mapstructure:"boot_command"` SourcePath string `mapstructure:"source_path"` VMName string `mapstructure:"vm_name"` - ReassignMac bool `mapstructure:"reassign_mac"` + ReassignMAC bool `mapstructure:"reassign_mac"` ctx interpolate.Context } diff --git a/builder/parallels/pvm/step_import.go b/builder/parallels/pvm/step_import.go index fdff75762..1a9b2de12 100644 --- a/builder/parallels/pvm/step_import.go +++ b/builder/parallels/pvm/step_import.go @@ -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, config.ReassignMac); 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())