Merge pull request #4294 from legal90/iso-target-extension

Add "iso_target_extension" option for all local *-iso builders
This commit is contained in:
Rickard von Essen 2017-01-04 13:48:28 +01:00 committed by GitHub
commit 85cf00069f
11 changed files with 55 additions and 5 deletions

View File

@ -314,7 +314,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
Description: "ISO", Description: "ISO",
ResultKey: "iso_path", ResultKey: "iso_path",
Url: b.config.ISOUrls, Url: b.config.ISOUrls,
Extension: "iso", Extension: b.config.TargetExtension,
TargetPath: b.config.TargetPath, TargetPath: b.config.TargetPath,
}, },
&common.StepCreateFloppy{ &common.StepCreateFloppy{

View File

@ -139,7 +139,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
Checksum: b.config.ISOChecksum, Checksum: b.config.ISOChecksum,
ChecksumType: b.config.ISOChecksumType, ChecksumType: b.config.ISOChecksumType,
Description: "ISO", Description: "ISO",
Extension: "iso", Extension: b.config.TargetExtension,
ResultKey: "iso_path", ResultKey: "iso_path",
TargetPath: b.config.TargetPath, TargetPath: b.config.TargetPath,
Url: b.config.ISOUrls, Url: b.config.ISOUrls,

View File

@ -349,7 +349,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
Checksum: b.config.ISOChecksum, Checksum: b.config.ISOChecksum,
ChecksumType: b.config.ISOChecksumType, ChecksumType: b.config.ISOChecksumType,
Description: "ISO", Description: "ISO",
Extension: "iso", Extension: b.config.TargetExtension,
ResultKey: "iso_path", ResultKey: "iso_path",
TargetPath: b.config.TargetPath, TargetPath: b.config.TargetPath,
Url: b.config.ISOUrls, Url: b.config.ISOUrls,

View File

@ -187,7 +187,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
Checksum: b.config.ISOChecksum, Checksum: b.config.ISOChecksum,
ChecksumType: b.config.ISOChecksumType, ChecksumType: b.config.ISOChecksumType,
Description: "ISO", Description: "ISO",
Extension: "iso", Extension: b.config.TargetExtension,
ResultKey: "iso_path", ResultKey: "iso_path",
TargetPath: b.config.TargetPath, TargetPath: b.config.TargetPath,
Url: b.config.ISOUrls, Url: b.config.ISOUrls,

View File

@ -222,7 +222,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
Checksum: b.config.ISOChecksum, Checksum: b.config.ISOChecksum,
ChecksumType: b.config.ISOChecksumType, ChecksumType: b.config.ISOChecksumType,
Description: "ISO", Description: "ISO",
Extension: "iso", Extension: b.config.TargetExtension,
ResultKey: "iso_path", ResultKey: "iso_path",
TargetPath: b.config.TargetPath, TargetPath: b.config.TargetPath,
Url: b.config.ISOUrls, Url: b.config.ISOUrls,

View File

@ -21,6 +21,7 @@ type ISOConfig struct {
ISOChecksumType string `mapstructure:"iso_checksum_type"` ISOChecksumType string `mapstructure:"iso_checksum_type"`
ISOUrls []string `mapstructure:"iso_urls"` ISOUrls []string `mapstructure:"iso_urls"`
TargetPath string `mapstructure:"iso_target_path"` TargetPath string `mapstructure:"iso_target_path"`
TargetExtension string `mapstructure:"iso_target_extension"`
RawSingleISOUrl string `mapstructure:"iso_url"` RawSingleISOUrl string `mapstructure:"iso_url"`
} }
@ -119,6 +120,11 @@ func (c *ISOConfig) Prepare(ctx *interpolate.Context) (warnings []string, errs [
} }
} }
if c.TargetExtension == "" {
c.TargetExtension = "iso"
}
c.TargetExtension = strings.ToLower(c.TargetExtension)
// Warnings // Warnings
if c.ISOChecksumType == "none" { if c.ISOChecksumType == "none" {
warnings = append(warnings, warnings = append(warnings,

View File

@ -284,3 +284,35 @@ func TestISOConfigPrepare_ISOUrl(t *testing.T) {
t.Fatalf("bad: %#v", i.ISOUrls) t.Fatalf("bad: %#v", i.ISOUrls)
} }
} }
func TestISOConfigPrepare_TargetExtension(t *testing.T) {
i := testISOConfig()
// Test the default value
warns, err := i.Prepare(nil)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil {
t.Fatalf("should not have error: %s", err)
}
if i.TargetExtension != "iso" {
t.Fatalf("should've found \"iso\" got: %s", i.TargetExtension)
}
// Test the lowercased value
i = testISOConfig()
i.TargetExtension = "DMG"
warns, err = i.Prepare(nil)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil {
t.Fatalf("should not have error: %s", err)
}
if i.TargetExtension != "dmg" {
t.Fatalf("should've lowercased: %s", i.TargetExtension)
}
}

View File

@ -152,6 +152,9 @@ builder.
to force the HTTP server to be on one port, make this minimum and maximum to force the HTTP server to be on one port, make this minimum and maximum
port the same. By default the values are 8000 and 9000, respectively. port the same. By default the values are 8000 and 9000, respectively.
- `iso_target_extension` (string) - The extension of the iso file after
download. This defaults to "iso".
- `iso_target_path` (string) - The path where the iso should be saved after - `iso_target_path` (string) - The path where the iso should be saved after
download. By default will go in the packer cache, with a hash of the download. By default will go in the packer cache, with a hash of the
original filename as its name. original filename as its name.

View File

@ -197,6 +197,9 @@ Linux server and have not enabled X11 forwarding (`ssh -X`).
- `iso_skip_cache` (boolean) - Use iso from provided url. Qemu must support - `iso_skip_cache` (boolean) - Use iso from provided url. Qemu must support
curl block device. This defaults to `false`. curl block device. This defaults to `false`.
- `iso_target_extension` (string) - The extension of the iso file after
download. This defaults to "iso".
- `iso_target_path` (string) - The path where the iso should be saved after - `iso_target_path` (string) - The path where the iso should be saved after
download. By default will go in the packer cache, with a hash of the download. By default will go in the packer cache, with a hash of the
original filename as its name. original filename as its name.

View File

@ -230,6 +230,9 @@ builder.
to, defaults to "ide". When set to "sata", the drive is attached to an AHCI to, defaults to "ide". When set to "sata", the drive is attached to an AHCI
SATA controller. SATA controller.
- `iso_target_extension` (string) - The extension of the iso file after
download. This defaults to "iso".
- `iso_target_path` (string) - The path where the iso should be saved - `iso_target_path` (string) - The path where the iso should be saved
after download. By default will go in the packer cache, with a hash of the after download. By default will go in the packer cache, with a hash of the
original filename as its name. original filename as its name.

View File

@ -161,6 +161,9 @@ builder.
to force the HTTP server to be on one port, make this minimum and maximum to force the HTTP server to be on one port, make this minimum and maximum
port the same. By default the values are 8000 and 9000, respectively. port the same. By default the values are 8000 and 9000, respectively.
- `iso_target_extension` (string) - The extension of the iso file after
download. This defaults to "iso".
- `iso_target_path` (string) - The path where the iso should be saved after - `iso_target_path` (string) - The path where the iso should be saved after
download. By default will go in the packer cache, with a hash of the download. By default will go in the packer cache, with a hash of the
original filename as its name. original filename as its name.