github.com/rothwerx/packer@v0.9.0/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 var diskName string 41 if _, ok := vmxData["scsi0:0.filename"]; ok { 42 diskName = vmxData["scsi0:0.filename"] 43 } 44 if _, ok := vmxData["sata0:0.filename"]; ok { 45 diskName = vmxData["sata0:0.filename"] 46 } 47 if _, ok := vmxData["ide0:0.filename"]; ok { 48 diskName = vmxData["ide0:0.filename"] 49 } 50 if diskName == "" { 51 err := fmt.Errorf("Root disk filename could not be found!") 52 state.Put("error", err) 53 return multistep.ActionHalt 54 } 55 56 state.Put("full_disk_path", filepath.Join(s.OutputDir, diskName)) 57 state.Put("vmx_path", vmxPath) 58 return multistep.ActionContinue 59 } 60 61 func (s *StepCloneVMX) Cleanup(state multistep.StateBag) { 62 }