Commit 16cb6f60 authored by Mikhail Zholobov's avatar Mikhail Zholobov

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.
parent bed62702
...@@ -29,23 +29,23 @@ type config struct { ...@@ -29,23 +29,23 @@ type config struct {
parallelscommon.SSHConfig `mapstructure:",squash"` parallelscommon.SSHConfig `mapstructure:",squash"`
parallelscommon.ToolsConfig `mapstructure:",squash"` parallelscommon.ToolsConfig `mapstructure:",squash"`
BootCommand []string `mapstructure:"boot_command"` BootCommand []string `mapstructure:"boot_command"`
DiskSize uint `mapstructure:"disk_size"` DiskSize uint `mapstructure:"disk_size"`
GuestOSDistribution string `mapstructure:"guest_os_distribution"` GuestOSType string `mapstructure:"guest_os_type"`
HardDriveInterface string `mapstructure:"hard_drive_interface"` HardDriveInterface string `mapstructure:"hard_drive_interface"`
HostInterfaces []string `mapstructure:"host_interfaces"` HostInterfaces []string `mapstructure:"host_interfaces"`
HTTPDir string `mapstructure:"http_directory"` HTTPDir string `mapstructure:"http_directory"`
HTTPPortMin uint `mapstructure:"http_port_min"` HTTPPortMin uint `mapstructure:"http_port_min"`
HTTPPortMax uint `mapstructure:"http_port_max"` HTTPPortMax uint `mapstructure:"http_port_max"`
ISOChecksum string `mapstructure:"iso_checksum"` ISOChecksum string `mapstructure:"iso_checksum"`
ISOChecksumType string `mapstructure:"iso_checksum_type"` ISOChecksumType string `mapstructure:"iso_checksum_type"`
ISOUrls []string `mapstructure:"iso_urls"` ISOUrls []string `mapstructure:"iso_urls"`
VMName string `mapstructure:"vm_name"` VMName string `mapstructure:"vm_name"`
RawSingleISOUrl string `mapstructure:"iso_url"` RawSingleISOUrl string `mapstructure:"iso_url"`
// Deprecated parameters // Deprecated parameters
GuestOSType string `mapstructure:"guest_os_type"` GuestOSDistribution string `mapstructure:"guest_os_distribution"`
ParallelsToolsHostPath string `mapstructure:"parallels_tools_host_path"` ParallelsToolsHostPath string `mapstructure:"parallels_tools_host_path"`
tpl *packer.ConfigTemplate tpl *packer.ConfigTemplate
...@@ -85,8 +85,18 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { ...@@ -85,8 +85,18 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
b.config.HardDriveInterface = "sata" b.config.HardDriveInterface = "sata"
} }
if b.config.GuestOSDistribution == "" { if b.config.GuestOSType == "" {
b.config.GuestOSDistribution = "other" 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 { if b.config.HTTPPortMin == 0 {
...@@ -108,13 +118,13 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { ...@@ -108,13 +118,13 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
// Errors // Errors
templates := map[string]*string{ templates := map[string]*string{
"guest_os_distribution": &b.config.GuestOSDistribution, "guest_os_type": &b.config.GuestOSType,
"hard_drive_interface": &b.config.HardDriveInterface, "hard_drive_interface": &b.config.HardDriveInterface,
"http_directory": &b.config.HTTPDir, "http_directory": &b.config.HTTPDir,
"iso_checksum": &b.config.ISOChecksum, "iso_checksum": &b.config.ISOChecksum,
"iso_checksum_type": &b.config.ISOChecksumType, "iso_checksum_type": &b.config.ISOChecksumType,
"iso_url": &b.config.RawSingleISOUrl, "iso_url": &b.config.RawSingleISOUrl,
"vm_name": &b.config.VMName, "vm_name": &b.config.VMName,
} }
for n, ptr := range templates { for n, ptr := range templates {
......
...@@ -38,8 +38,8 @@ func TestBuilderPrepare_Defaults(t *testing.T) { ...@@ -38,8 +38,8 @@ func TestBuilderPrepare_Defaults(t *testing.T) {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
if b.config.GuestOSDistribution != "other" { if b.config.GuestOSType != "other" {
t.Errorf("bad guest OS distribution: %s", b.config.GuestOSDistribution) t.Errorf("bad guest OS type: %s", b.config.GuestOSType)
} }
if b.config.VMName != "packer-foo" { if b.config.VMName != "packer-foo" {
...@@ -79,6 +79,25 @@ func TestBuilderPrepare_DiskSize(t *testing.T) { ...@@ -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) { func TestBuilderPrepare_HardDriveInterface(t *testing.T) {
var b Builder var b Builder
config := testConfig() config := testConfig()
......
...@@ -28,7 +28,7 @@ func (s *stepCreateVM) Run(state multistep.StateBag) multistep.StepAction { ...@@ -28,7 +28,7 @@ func (s *stepCreateVM) Run(state multistep.StateBag) multistep.StepAction {
commands := make([][]string, 8) commands := make([][]string, 8)
commands[0] = []string{ commands[0] = []string{
"create", name, "create", name,
"--distribution", config.GuestOSDistribution, "--distribution", config.GuestOSType,
"--dst", path, "--dst", path,
"--vmtype", "vm", "--vmtype", "vm",
} }
......
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