builder/vmware: configurable disk size (default 40 GB)
This commit is contained in:
parent
adf150247e
commit
24f852f699
|
@ -26,6 +26,7 @@ type Builder struct {
|
||||||
|
|
||||||
type config struct {
|
type config struct {
|
||||||
DiskName string `mapstructure:"vmdk_name"`
|
DiskName string `mapstructure:"vmdk_name"`
|
||||||
|
DiskSize uint `mapstructure:"disk_size"`
|
||||||
GuestOSType string `mapstructure:"guest_os_type"`
|
GuestOSType string `mapstructure:"guest_os_type"`
|
||||||
ISOMD5 string `mapstructure:"iso_md5"`
|
ISOMD5 string `mapstructure:"iso_md5"`
|
||||||
ISOUrl string `mapstructure:"iso_url"`
|
ISOUrl string `mapstructure:"iso_url"`
|
||||||
|
@ -65,6 +66,10 @@ func (b *Builder) Prepare(raws ...interface{}) error {
|
||||||
b.config.DiskName = "disk"
|
b.config.DiskName = "disk"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if b.config.DiskSize == 0 {
|
||||||
|
b.config.DiskSize = 40000
|
||||||
|
}
|
||||||
|
|
||||||
if b.config.GuestOSType == "" {
|
if b.config.GuestOSType == "" {
|
||||||
b.config.GuestOSType = "other"
|
b.config.GuestOSType = "other"
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
func TestBuilderPrepare_HTTPPort(t *testing.T) {
|
||||||
var b Builder
|
var b Builder
|
||||||
config := testConfig()
|
config := testConfig()
|
||||||
|
|
|
@ -19,16 +19,13 @@ import (
|
||||||
type stepCreateDisk struct{}
|
type stepCreateDisk struct{}
|
||||||
|
|
||||||
func (stepCreateDisk) Run(state map[string]interface{}) multistep.StepAction {
|
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)
|
config := state["config"].(*config)
|
||||||
driver := state["driver"].(Driver)
|
driver := state["driver"].(Driver)
|
||||||
ui := state["ui"].(packer.Ui)
|
ui := state["ui"].(packer.Ui)
|
||||||
|
|
||||||
ui.Say("Creating virtual machine disk")
|
ui.Say("Creating virtual machine disk")
|
||||||
output := filepath.Join(config.OutputDir, config.DiskName+".vmdk")
|
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)
|
err := fmt.Errorf("Error creating disk: %s", err)
|
||||||
state["error"] = err
|
state["error"] = err
|
||||||
ui.Error(err.Error())
|
ui.Error(err.Error())
|
||||||
|
|
Loading…
Reference in New Issue