2013-06-04 18:00:58 -04:00
|
|
|
package vmware
|
|
|
|
|
|
|
|
import (
|
2013-06-04 20:00:29 -04:00
|
|
|
"github.com/mitchellh/mapstructure"
|
2013-06-04 18:00:58 -04:00
|
|
|
"github.com/mitchellh/multistep"
|
|
|
|
"github.com/mitchellh/packer/packer"
|
|
|
|
)
|
|
|
|
|
|
|
|
const BuilderId = "mitchellh.vmware"
|
|
|
|
|
|
|
|
type Builder struct {
|
|
|
|
config config
|
|
|
|
runner multistep.Runner
|
|
|
|
}
|
|
|
|
|
|
|
|
type config struct {
|
2013-06-04 19:52:59 -04:00
|
|
|
DiskName string `mapstructure:"vmdk_name"`
|
2013-06-04 20:00:29 -04:00
|
|
|
ISOUrl string `mapstructure:"iso_url"`
|
2013-06-04 19:52:59 -04:00
|
|
|
VMName string `mapstructure:"vm_name"`
|
2013-06-04 18:00:58 -04:00
|
|
|
OutputDir string `mapstructure:"output_directory"`
|
2013-06-05 17:24:48 -04:00
|
|
|
HTTPDir string `mapstructure:"http_directory"`
|
2013-06-05 17:47:19 -04:00
|
|
|
BootCommand []string `mapstructure:"boot_command"`
|
2013-06-04 18:00:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (b *Builder) Prepare(raw interface{}) (err error) {
|
2013-06-04 20:00:29 -04:00
|
|
|
err = mapstructure.Decode(raw, &b.config)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2013-06-04 19:52:59 -04:00
|
|
|
if b.config.DiskName == "" {
|
|
|
|
b.config.DiskName = "disk"
|
|
|
|
}
|
|
|
|
|
|
|
|
if b.config.VMName == "" {
|
|
|
|
b.config.VMName = "packer"
|
|
|
|
}
|
|
|
|
|
2013-06-04 18:00:58 -04:00
|
|
|
if b.config.OutputDir == "" {
|
|
|
|
b.config.OutputDir = "vmware"
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *Builder) Run(ui packer.Ui, hook packer.Hook) packer.Artifact {
|
|
|
|
steps := []multistep.Step{
|
|
|
|
&stepPrepareOutputDir{},
|
|
|
|
&stepCreateDisk{},
|
2013-06-04 19:52:59 -04:00
|
|
|
&stepCreateVMX{},
|
2013-06-05 17:24:48 -04:00
|
|
|
&stepHTTPServer{},
|
2013-06-04 18:00:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Setup the state bag
|
|
|
|
state := make(map[string]interface{})
|
|
|
|
state["config"] = &b.config
|
|
|
|
state["hook"] = hook
|
|
|
|
state["ui"] = ui
|
|
|
|
|
|
|
|
// Run!
|
|
|
|
b.runner = &multistep.BasicRunner{Steps: steps}
|
|
|
|
b.runner.Run(state)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *Builder) Cancel() {
|
|
|
|
}
|