@ -6,6 +6,7 @@ package clone
import (
"context"
"fmt"
"path"
"github.com/hashicorp/packer/builder/vsphere/common"
"github.com/hashicorp/packer/builder/vsphere/driver"
@ -49,19 +50,12 @@ type StepCloneVM struct {
func ( s * StepCloneVM ) Run ( ctx context . Context , state multistep . StateBag ) multistep . StepAction {
ui := state . Get ( "ui" ) . ( packer . Ui )
d := state . Get ( "driver" ) . ( * driver . Driver )
vmPath := fmt. Sprintf ( "%s/%s" , s . Location . Folder , s . Location . VMName )
vmPath := path. Join ( s . Location . Folder , s . Location . VMName )
vm , err := d . FindVM ( vmPath )
if s . Force == false && err == nil {
state . Put ( "error" , fmt . Errorf ( "%s already exists, you can use -force flag to destroy it" , vmPath ) )
err := d . PreCleanVM ( ui , vmPath , s . Force )
if err != nil {
state . Put ( "error" , err )
return multistep . ActionHalt
} else if s . Force == true && err == nil {
ui . Say ( fmt . Sprintf ( "the vm/template %s already exists, but deleting it due to -force flag" , vmPath ) )
err := vm . Destroy ( )
if err != nil {
state . Put ( "error" , fmt . Errorf ( "error destroying %s: %v" , vmPath , err ) )
}
}
ui . Say ( "Cloning VM..." )
@ -71,7 +65,7 @@ func (s *StepCloneVM) Run(ctx context.Context, state multistep.StateBag) multist
return multistep . ActionHalt
}
vm , err = template . Clone ( ctx , & driver . CloneConfig {
vm , err : = template . Clone ( ctx , & driver . CloneConfig {
Name : s . Location . VMName ,
Folder : s . Location . Folder ,
Cluster : s . Location . Cluster ,