builder/vmware: configurable disk size (default 40 GB)

This commit is contained in:
Mitchell Hashimoto 2013-06-23 15:07:19 -07:00
parent adf150247e
commit 24f852f699
3 changed files with 32 additions and 4 deletions

View File

@ -26,6 +26,7 @@ type Builder struct {
type config struct {
DiskName string `mapstructure:"vmdk_name"`
DiskSize uint `mapstructure:"disk_size"`
GuestOSType string `mapstructure:"guest_os_type"`
ISOMD5 string `mapstructure:"iso_md5"`
ISOUrl string `mapstructure:"iso_url"`
@ -65,6 +66,10 @@ func (b *Builder) Prepare(raws ...interface{}) error {
b.config.DiskName = "disk"
}
if b.config.DiskSize == 0 {
b.config.DiskSize = 40000
}
if b.config.GuestOSType == "" {
b.config.GuestOSType = "other"
}

View File

@ -68,6 +68,32 @@ func TestBuilderPrepare_Defaults(t *testing.T) {
}
}
func TestBuilderPrepare_DiskSize(t *testing.T) {
var b Builder
config := testConfig()
delete(config, "disk_size")
err := b.Prepare(config)
if err != nil {
t.Fatalf("bad err: %s", err)
}
if b.config.DiskSize != 40000 {
t.Fatalf("bad size: %d", b.config.DiskSize)
}
config["disk_size"] = 60000
b = Builder{}
err = b.Prepare(config)
if err != nil {
t.Fatalf("should not have error: %s", err)
}
if b.config.DiskSize != 60000 {
t.Fatalf("bad size: %s", b.config.DiskSize)
}
}
func TestBuilderPrepare_HTTPPort(t *testing.T) {
var b Builder
config := testConfig()

View File

@ -19,16 +19,13 @@ import (
type stepCreateDisk struct{}
func (stepCreateDisk) Run(state map[string]interface{}) multistep.StepAction {
// TODO(mitchellh): Configurable disk size
// TODO(mitchellh): Capture error output in case things go wrong to report it
config := state["config"].(*config)
driver := state["driver"].(Driver)
ui := state["ui"].(packer.Ui)
ui.Say("Creating virtual machine disk")
output := filepath.Join(config.OutputDir, config.DiskName+".vmdk")
if err := driver.CreateDisk(output, "40000M"); err != nil {
if err := driver.CreateDisk(output, fmt.Sprintf("%dM", config.DiskSize)); err != nil {
err := fmt.Errorf("Error creating disk: %s", err)
state["error"] = err
ui.Error(err.Error())