github.com/sneal/packer@v0.5.2/builder/vmware/vmx/step_clone_vmx.go (about) 1 package vmx 2 3 import ( 4 "fmt" 5 "log" 6 "path/filepath" 7 8 "github.com/mitchellh/multistep" 9 vmwcommon "github.com/mitchellh/packer/builder/vmware/common" 10 "github.com/mitchellh/packer/packer" 11 ) 12 13 // StepCloneVMX takes a VMX file and clones the VM into the output directory. 14 type StepCloneVMX struct { 15 OutputDir string 16 Path string 17 VMName string 18 } 19 20 func (s *StepCloneVMX) Run(state multistep.StateBag) multistep.StepAction { 21 driver := state.Get("driver").(vmwcommon.Driver) 22 ui := state.Get("ui").(packer.Ui) 23 24 vmxPath := filepath.Join(s.OutputDir, s.VMName+".vmx") 25 26 ui.Say("Cloning source VM...") 27 log.Printf("Cloning from: %s", s.Path) 28 log.Printf("Cloning to: %s", vmxPath) 29 if err := driver.Clone(vmxPath, s.Path); err != nil { 30 state.Put("error", err) 31 return multistep.ActionHalt 32 } 33 34 vmxData, err := vmwcommon.ReadVMX(vmxPath) 35 if err != nil { 36 state.Put("error", err) 37 return multistep.ActionHalt 38 } 39 40 diskName, ok := vmxData["scsi0:0.filename"] 41 if !ok { 42 err := fmt.Errorf("Root disk filename could not be found!") 43 state.Put("error", err) 44 return multistep.ActionHalt 45 } 46 47 state.Put("full_disk_path", filepath.Join(s.OutputDir, diskName)) 48 state.Put("vmx_path", vmxPath) 49 return multistep.ActionContinue 50 } 51 52 func (s *StepCloneVMX) Cleanup(state multistep.StateBag) { 53 }