Merge pull request #4621 from hui-yang/disk-type

builder/parallels-iso: Configuration of disk type, plain or expanding
This commit is contained in:
Rickard von Essen 2017-03-10 19:32:41 +01:00 committed by GitHub
commit a047916944
4 changed files with 88 additions and 7 deletions

View File

@ -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,17 @@ 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.DiskType == "plain" && !b.config.SkipCompaction {
b.config.SkipCompaction = true
warnings = append(warnings,
"'skip_compaction' is enforced to be true for plain disks.")
}
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"))

View File

@ -130,6 +130,61 @@ func TestBuilderPrepare_DiskSize(t *testing.T) {
}
}
func TestBuilderPrepare_DiskType(t *testing.T) {
var b Builder
config := testConfig()
// Test a default disk_type
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 plain disk with wrong setting for compaction
config["disk_type"] = "plain"
config["skip_compaction"] = false
b = Builder{}
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)
}
// Test with plain disk with correct setting for compaction
config["disk_type"] = "plain"
config["skip_compaction"] = true
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()

View File

@ -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,
}

View File

@ -105,6 +105,14 @@ 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 full drive). Plain disks
perform faster than expanding disks. `skip_compaction` will be set to true
automatically for plain 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
@ -218,9 +226,10 @@ builder.
"5m", or five minutes.
- `skip_compaction` (boolean) - Virtual disk image is compacted at the end of
the build process using `prl_disk_tool` utility. In certain rare cases, this
might corrupt the resulting disk image. If you find this to be the case,
you can disable compaction using this configuration value.
the build process using `prl_disk_tool` utility (except for the case that
`disk_type` is set to `plain`). In certain rare cases, this might corrupt
the resulting disk image. If you find this to be the case, you can disable
compaction using this configuration value.
- `vm_name` (string) - This is the name of the PVM directory for the new
virtual machine, without the file extension. By default this is
@ -273,7 +282,7 @@ proper key:
- `<leftAltOn>` `<rightAltOn>` - Simulates pressing and holding the alt key.
- `<leftCtrlOn>` `<rightCtrlOn>` - Simulates pressing and holding the ctrl key.
- `<leftCtrlOn>` `<rightCtrlOn>` - Simulates pressing and holding the ctrl key.
- `<leftShiftOn>` `<rightShiftOn>` - Simulates pressing and holding the shift key.
@ -287,9 +296,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 `<leftCtrlOn>c<leftCtrlOff>`.