From 16cb6f60c8072f4f88b81fb19cc06cefa5c09b6d Mon Sep 17 00:00:00 2001 From: Mikhail Zholobov Date: Tue, 2 Sep 2014 16:00:25 +0400 Subject: [PATCH] builder/parallels: "guest_os_distribution" renamed to "guest_os_type". "guest_os_distribution" become deprecated and is not required anymore. But if it is defined (in outdated templates),then the value will be copied to "guest_os_type" and warning will be displayed. --- builder/parallels/iso/builder.go | 54 +++++++++++++++---------- builder/parallels/iso/builder_test.go | 23 ++++++++++- builder/parallels/iso/step_create_vm.go | 2 +- 3 files changed, 54 insertions(+), 25 deletions(-) diff --git a/builder/parallels/iso/builder.go b/builder/parallels/iso/builder.go index 980f2b5d3..b177bb27d 100644 --- a/builder/parallels/iso/builder.go +++ b/builder/parallels/iso/builder.go @@ -29,23 +29,23 @@ type config struct { parallelscommon.SSHConfig `mapstructure:",squash"` parallelscommon.ToolsConfig `mapstructure:",squash"` - BootCommand []string `mapstructure:"boot_command"` - DiskSize uint `mapstructure:"disk_size"` - GuestOSDistribution string `mapstructure:"guest_os_distribution"` - HardDriveInterface string `mapstructure:"hard_drive_interface"` - HostInterfaces []string `mapstructure:"host_interfaces"` - HTTPDir string `mapstructure:"http_directory"` - HTTPPortMin uint `mapstructure:"http_port_min"` - HTTPPortMax uint `mapstructure:"http_port_max"` - ISOChecksum string `mapstructure:"iso_checksum"` - ISOChecksumType string `mapstructure:"iso_checksum_type"` - ISOUrls []string `mapstructure:"iso_urls"` - VMName string `mapstructure:"vm_name"` + BootCommand []string `mapstructure:"boot_command"` + DiskSize uint `mapstructure:"disk_size"` + GuestOSType string `mapstructure:"guest_os_type"` + HardDriveInterface string `mapstructure:"hard_drive_interface"` + HostInterfaces []string `mapstructure:"host_interfaces"` + HTTPDir string `mapstructure:"http_directory"` + HTTPPortMin uint `mapstructure:"http_port_min"` + HTTPPortMax uint `mapstructure:"http_port_max"` + ISOChecksum string `mapstructure:"iso_checksum"` + ISOChecksumType string `mapstructure:"iso_checksum_type"` + ISOUrls []string `mapstructure:"iso_urls"` + VMName string `mapstructure:"vm_name"` RawSingleISOUrl string `mapstructure:"iso_url"` // Deprecated parameters - GuestOSType string `mapstructure:"guest_os_type"` + GuestOSDistribution string `mapstructure:"guest_os_distribution"` ParallelsToolsHostPath string `mapstructure:"parallels_tools_host_path"` tpl *packer.ConfigTemplate @@ -85,8 +85,18 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { b.config.HardDriveInterface = "sata" } - if b.config.GuestOSDistribution == "" { - b.config.GuestOSDistribution = "other" + if b.config.GuestOSType == "" { + b.config.GuestOSType = "other" + } + + if b.config.GuestOSDistribution != "" { + // Compatibility with older templates: + // Use value of 'guest_os_distribution' if it is defined. + b.config.GuestOSType = b.config.GuestOSDistribution + warnings = append(warnings, + "A 'guest_os_distribution' has been completely replaced with 'guest_os_type'\n"+ + "It is recommended to remove it and assign the previous value to 'guest_os_type'.\n"+ + "Run it to see all available values: `prlctl create x -d list` ") } if b.config.HTTPPortMin == 0 { @@ -108,13 +118,13 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { // Errors templates := map[string]*string{ - "guest_os_distribution": &b.config.GuestOSDistribution, - "hard_drive_interface": &b.config.HardDriveInterface, - "http_directory": &b.config.HTTPDir, - "iso_checksum": &b.config.ISOChecksum, - "iso_checksum_type": &b.config.ISOChecksumType, - "iso_url": &b.config.RawSingleISOUrl, - "vm_name": &b.config.VMName, + "guest_os_type": &b.config.GuestOSType, + "hard_drive_interface": &b.config.HardDriveInterface, + "http_directory": &b.config.HTTPDir, + "iso_checksum": &b.config.ISOChecksum, + "iso_checksum_type": &b.config.ISOChecksumType, + "iso_url": &b.config.RawSingleISOUrl, + "vm_name": &b.config.VMName, } for n, ptr := range templates { diff --git a/builder/parallels/iso/builder_test.go b/builder/parallels/iso/builder_test.go index fce9e14a4..9c7f56f6b 100644 --- a/builder/parallels/iso/builder_test.go +++ b/builder/parallels/iso/builder_test.go @@ -38,8 +38,8 @@ func TestBuilderPrepare_Defaults(t *testing.T) { t.Fatalf("should not have error: %s", err) } - if b.config.GuestOSDistribution != "other" { - t.Errorf("bad guest OS distribution: %s", b.config.GuestOSDistribution) + if b.config.GuestOSType != "other" { + t.Errorf("bad guest OS type: %s", b.config.GuestOSType) } if b.config.VMName != "packer-foo" { @@ -79,6 +79,25 @@ func TestBuilderPrepare_DiskSize(t *testing.T) { } } +func TestBuilderPrepare_GuestOSType(t *testing.T) { + var b Builder + config := testConfig() + delete(config, "guest_os_distribution") + + // Test deprecated parameter + config["guest_os_distribution"] = "bolgenos" + warns, err := b.Prepare(config) + if len(warns) == 0 { + t.Fatalf("should have warning") + } + if err != nil { + t.Fatalf("should not have error: %s", err) + } + if b.config.GuestOSType != "bolgenos" { + t.Fatalf("bad: %s", b.config.GuestOSType) + } +} + func TestBuilderPrepare_HardDriveInterface(t *testing.T) { var b Builder config := testConfig() diff --git a/builder/parallels/iso/step_create_vm.go b/builder/parallels/iso/step_create_vm.go index 1b2468cfe..9da4b678c 100644 --- a/builder/parallels/iso/step_create_vm.go +++ b/builder/parallels/iso/step_create_vm.go @@ -28,7 +28,7 @@ func (s *stepCreateVM) Run(state multistep.StateBag) multistep.StepAction { commands := make([][]string, 8) commands[0] = []string{ "create", name, - "--distribution", config.GuestOSDistribution, + "--distribution", config.GuestOSType, "--dst", path, "--vmtype", "vm", }