From 52d4514d6a40350cf079561d45353c7577ff23fc Mon Sep 17 00:00:00 2001 From: huiyang Date: Fri, 3 Mar 2017 15:32:51 -0800 Subject: [PATCH] builder/parallels-iso: Configuration of disk type, plain or expanding --- builder/parallels/iso/builder.go | 10 +++++ builder/parallels/iso/builder_test.go | 41 +++++++++++++++++++ builder/parallels/iso/step_create_disk.go | 1 + command/plugin.go | 2 +- .../docs/builders/parallels-iso.html.md | 15 +++++-- 5 files changed, 64 insertions(+), 5 deletions(-) diff --git a/builder/parallels/iso/builder.go b/builder/parallels/iso/builder.go index 8aefdf762..cfe6241a8 100644 --- a/builder/parallels/iso/builder.go +++ b/builder/parallels/iso/builder.go @@ -37,6 +37,7 @@ type Config struct { BootCommand []string `mapstructure:"boot_command"` DiskSize uint `mapstructure:"disk_size"` + DiskType string `mapstructure:"disk_type"` GuestOSType string `mapstructure:"guest_os_type"` HardDriveInterface string `mapstructure:"hard_drive_interface"` HostInterfaces []string `mapstructure:"host_interfaces"` @@ -87,6 +88,10 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { b.config.DiskSize = 40000 } + if b.config.DiskType == "" { + b.config.DiskType = "expand" + } + if b.config.HardDriveInterface == "" { b.config.HardDriveInterface = "sata" } @@ -104,6 +109,11 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { b.config.VMName = fmt.Sprintf("packer-%s", b.config.PackerBuildName) } + if b.config.DiskType != "expand" && b.config.DiskType != "plain" { + errs = packer.MultiErrorAppend( + errs, errors.New("disk_type can only be expand, or plain")) + } + if b.config.HardDriveInterface != "ide" && b.config.HardDriveInterface != "sata" && b.config.HardDriveInterface != "scsi" { errs = packer.MultiErrorAppend( errs, errors.New("hard_drive_interface can only be ide, sata, or scsi")) diff --git a/builder/parallels/iso/builder_test.go b/builder/parallels/iso/builder_test.go index 7be21bd59..668ec1c07 100644 --- a/builder/parallels/iso/builder_test.go +++ b/builder/parallels/iso/builder_test.go @@ -130,6 +130,47 @@ func TestBuilderPrepare_DiskSize(t *testing.T) { } } +func TestBuilderPrepare_DiskType(t *testing.T) { + var b Builder + config := testConfig() + + // Test a default boot_wait + delete(config, "disk_type") + warns, err := b.Prepare(config) + if len(warns) > 0 { + t.Fatalf("bad: %#v", warns) + } + if err != nil { + t.Fatalf("err: %s", err) + } + + if b.config.DiskType != "expand" { + t.Fatalf("bad: %s", b.config.DiskType) + } + + // Test with a bad + config["disk_type"] = "fake" + b = Builder{} + warns, err = b.Prepare(config) + if len(warns) > 0 { + t.Fatalf("bad: %#v", warns) + } + if err == nil { + t.Fatal("should have error") + } + + // Test with a good + config["disk_type"] = "plain" + b = Builder{} + warns, err = b.Prepare(config) + if len(warns) > 0 { + t.Fatalf("bad: %#v", warns) + } + if err != nil { + t.Fatalf("should not have error: %s", err) + } +} + func TestBuilderPrepare_HardDriveInterface(t *testing.T) { var b Builder config := testConfig() diff --git a/builder/parallels/iso/step_create_disk.go b/builder/parallels/iso/step_create_disk.go index e8f458f82..1737dcf6a 100644 --- a/builder/parallels/iso/step_create_disk.go +++ b/builder/parallels/iso/step_create_disk.go @@ -22,6 +22,7 @@ func (s *stepCreateDisk) Run(state multistep.StateBag) multistep.StepAction { command := []string{ "set", vmName, "--device-add", "hdd", + "--type", config.DiskType, "--size", strconv.FormatUint(uint64(config.DiskSize), 10), "--iface", config.HardDriveInterface, } diff --git a/command/plugin.go b/command/plugin.go index 8f09f0a74..bb76efbfe 100644 --- a/command/plugin.go +++ b/command/plugin.go @@ -75,8 +75,8 @@ type PluginCommand struct { var Builders = map[string]packer.Builder{ "amazon-chroot": new(amazonchrootbuilder.Builder), "amazon-ebs": new(amazonebsbuilder.Builder), - "amazon-ebsvolume": new(amazonebsvolumebuilder.Builder), "amazon-ebssurrogate": new(amazonebssurrogatebuilder.Builder), + "amazon-ebsvolume": new(amazonebsvolumebuilder.Builder), "amazon-instance": new(amazoninstancebuilder.Builder), "azure-arm": new(azurearmbuilder.Builder), "cloudstack": new(cloudstackbuilder.Builder), diff --git a/website/source/docs/builders/parallels-iso.html.md b/website/source/docs/builders/parallels-iso.html.md index 09bf750d7..4f3d73c4f 100644 --- a/website/source/docs/builders/parallels-iso.html.md +++ b/website/source/docs/builders/parallels-iso.html.md @@ -105,6 +105,13 @@ builder. - `disk_size` (integer) - The size, in megabytes, of the hard disk to create for the VM. By default, this is 40000 (about 40 GB). +- `disk_type` (string) - The type for image file based virtual disk drives, + defaults to `expand`. Valid options are `expand` (expanding disk) that the + image file is small initially and grows in size as you add data to it, and + `plain` (plain disk) that the image file has a fixed size from the moment it + is created (i.e the space is allocated for the drive fully). Plain disks + perform faster than expanding disks. + - `floppy_files` (array of strings) - A list of files to place onto a floppy disk that is attached when the VM is booted. This is most useful for unattended Windows installs, which look for an `Autounattend.xml` file on @@ -273,7 +280,7 @@ proper key: - `` `` - Simulates pressing and holding the alt key. -- `` `` - Simulates pressing and holding the ctrl key. +- `` `` - Simulates pressing and holding the ctrl key. - `` `` - Simulates pressing and holding the shift key. @@ -287,9 +294,9 @@ proper key: sending any additional keys. This is useful if you have to generally wait for the UI to update before typing more. -When using modifier keys `ctrl`, `alt`, `shift` ensure that you release them, -otherwise they will be held down until the machine reboots. Use lowercase -characters as well inside modifiers. +When using modifier keys `ctrl`, `alt`, `shift` ensure that you release them, +otherwise they will be held down until the machine reboots. Use lowercase +characters as well inside modifiers. For example: to simulate ctrl+c use `c`.