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"
|
2013-06-05 20:52:37 -04:00
|
|
|
"log"
|
2013-06-04 18:00:58 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
const BuilderId = "mitchellh.vmware"
|
|
|
|
|
|
|
|
type Builder struct {
|
|
|
|
config config
|
|
|
|
runner multistep.Runner
|
|
|
|
}
|
|
|
|
|
|
|
|
type config struct {
|
2013-06-05 18:48:13 -04:00
|
|
|
DiskName string `mapstructure:"vmdk_name"`
|
|
|
|
ISOUrl string `mapstructure:"iso_url"`
|
|
|
|
VMName string `mapstructure:"vm_name"`
|
|
|
|
OutputDir string `mapstructure:"output_directory"`
|
|
|
|
HTTPDir string `mapstructure:"http_directory"`
|
2013-06-05 17:47:19 -04:00
|
|
|
BootCommand []string `mapstructure:"boot_command"`
|
2013-06-05 18:48:13 -04:00
|
|
|
BootWait uint `mapstructure:"boot_wait"`
|
2013-06-05 23:04:55 -04:00
|
|
|
SSHUser string `mapstructure:"ssh_user"`
|
|
|
|
SSHPassword string `mapstructure:"ssh_password"`
|
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-05 18:12:43 -04:00
|
|
|
&stepRun{},
|
2013-06-05 20:15:16 -04:00
|
|
|
&stepTypeBootCommand{},
|
2013-06-05 23:53:34 -04:00
|
|
|
&stepWaitForSSH{},
|
2013-06-06 11:42:38 -04:00
|
|
|
&stepProvision{},
|
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() {
|
2013-06-05 20:52:37 -04:00
|
|
|
if b.runner != nil {
|
|
|
|
log.Println("Cancelling the step runner...")
|
|
|
|
b.runner.Cancel()
|
|
|
|
}
|
2013-06-04 18:00:58 -04:00
|
|
|
}
|