Commit 2e57496a authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

builder/vmware: Start it. Creates disks so far...

parent 87e7f17a
package vmware
import (
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
)
const BuilderId = "mitchellh.vmware"
type Builder struct {
config config
runner multistep.Runner
}
type config struct {
OutputDir string `mapstructure:"output_directory"`
}
func (b *Builder) Prepare(raw interface{}) (err error) {
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{},
}
// 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() {
}
package vmware
import (
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"os/exec"
"path/filepath"
)
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)
ui := state["ui"].(packer.Ui)
vdisk_manager := "/Applications/VMware Fusion.app/Contents/Library/vmware-vdiskmanager"
output := filepath.Join(config.OutputDir, "disk.vmdk")
ui.Say("Creating virtual machine disk")
cmd := exec.Command(vdisk_manager, "-c", "-s", "40000M", "-a", "lsilogic", "-t", "1", output)
if err := cmd.Run(); err != nil {
ui.Error(fmt.Sprintf("Error creating VMware disk: %s", err))
return multistep.ActionHalt
}
return multistep.ActionContinue
}
func (stepCreateDisk) Cleanup(map[string]interface{}) {}
package vmware
import (
"github.com/mitchellh/multistep"
"os"
)
type stepPrepareOutputDir struct{}
func (stepPrepareOutputDir) Run(state map[string]interface{}) multistep.StepAction {
config := state["config"].(*config)
if err := os.MkdirAll(config.OutputDir, 0755); err != nil {
return multistep.ActionHalt
}
return multistep.ActionContinue
}
func (stepPrepareOutputDir) Cleanup(map[string]interface{}) {}
...@@ -13,6 +13,7 @@ import ( ...@@ -13,6 +13,7 @@ import (
const defaultConfig = ` const defaultConfig = `
[builders] [builders]
amazon-ebs = "packer-builder-amazon-ebs" amazon-ebs = "packer-builder-amazon-ebs"
vmware = "packer-builder-vmware"
[commands] [commands]
build = "packer-command-build" build = "packer-command-build"
......
package main
import (
"github.com/mitchellh/packer/builder/vmware"
"github.com/mitchellh/packer/packer/plugin"
)
func main() {
plugin.ServeBuilder(new(vmware.Builder))
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment