diff --git a/debian/changelog b/debian/changelog index 38b9f30..5738a3e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -vn-vmware (1.0.37) stable; urgency=low +vn-vmware (1.0.38) stable; urgency=low * Initial Release. diff --git a/vn-vmware.pl b/vn-vmware.pl index 595294d..3fd86a7 100755 --- a/vn-vmware.pl +++ b/vn-vmware.pl @@ -729,6 +729,18 @@ sub clone_machine { # Gathering specifications and cloning + if ($original_vm) { + my $tmp_vm = Vim::find_entity_view( + view_type => 'VirtualMachine', + filter => {'name' => $dst_tmp_name} + ); + + if ($tmp_vm) { + power_off($tmp_vm); + $tmp_vm->Destroy(); + } + } + log_message "Cloning machine."; my $clone_spec = VirtualMachineCloneSpec->new( powerOn => false, @@ -753,6 +765,7 @@ sub clone_machine { if ($original_vm && $overwrite) { log_message "Deleting machine '$dst_name'."; + power_off($original_vm); $original_vm->Destroy(); log_message "Renaming '$dst_tmp_name' to '$dst_name'."; @@ -844,3 +857,11 @@ sub open_machine() { log_message "Found machine '$vm_name'."; } + +sub power_off { + my ($vm_power) = @_; + + if ($vm_power->runtime->powerState->val eq 'poweredOn') { + $vm_power->PowerOffVM(); + } +}