function domain_snapshot_revert($domain, $name) { $name = $this->domain_snapshot_lookup_by_name($domain, $name); $tmp = libvirt_domain_snapshot_revert($name); return ($tmp) ? $tmp : $this->_set_last_error(); }
/** * revert to a snapshot of a virtual machine on the virt host * * @todo TIDY UP to remove bugged code * * @global resource $host_conn libvirt connection * * @param string $vm_virt_id virt_id of the vm * @param int $vm_snapshot_instance_to_revert_to snapshot instance * * @return bool on success */ function ace_kvm_vm_snapshot_revert($vm_virt_id, $vm_snapshot_instance_to_revert_to) { global $host_conn; $vm_res = libvirt_domain_lookup_by_name($host_conn, $vm_virt_id); ace_kvm_log_last_error(); $vm_snapshot_list = ace_kvm_vm_get_snapshot_list($vm_virt_id); $num_vm_snapshots = count($vm_snapshot_list); $max_snapshot_instance = $num_vm_snapshots - 1; if ($num_vm_snapshots > 0 && $vm_snapshot_instance_to_revert_to >= 0 && $vm_snapshot_instance_to_revert_to <= $max_snapshot_instance) { $vm_snapshot_name_to_revert_to = $vm_snapshot_list[$vm_snapshot_instance_to_revert_to]; $vm_snapshot_res_to_revert_to = libvirt_domain_snapshot_lookup_by_name($vm_res, $vm_snapshot_name_to_revert_to); ace_kvm_log_last_error(); $revert_result = libvirt_domain_snapshot_revert($vm_snapshot_res_to_revert_to); ace_kvm_log_last_error(); # resume, since the vm was 'paused' when the snapshot was taken ace_kvm_vm_resume($vm_virt_id); # then stop, since we only work with snapshots when vm is inactive ace_kvm_vm_stop($vm_virt_id); # if $vm_snapshot_instance < $num_snaps then delete snap[instance+1]-with children # if (($num_vm_snapshots > 0) && ($vm_snapshot_instance < ($num_vm_snapshots - 1))) { if ($vm_snapshot_instance_to_revert_to < $max_snapshot_instance) { $all_delete_results = TRUE; for ($i = $max_snapshot_instance; $i > $vm_snapshot_instance_to_revert_to; $i--) { $vm_snapshot_name_to_delete = $vm_snapshot_list[$i]; $vm_snapshot_res_to_delete = libvirt_domain_snapshot_lookup_by_name($vm_res, $vm_snapshot_name_to_delete); ace_kvm_log_last_error(); $delete_result = libvirt_domain_snapshot_delete($vm_snapshot_res_to_delete); ace_kvm_log_last_error(); $all_delete_results = $all_delete_results && $delete_result; } # the following FAILS - it has to do with the children flag //$result = libvirt_domain_snapshot_delete($vm_snapshot_res_to_delete,VIR_SNAPSHOT_DELETE_CHILDREN); #$result = libvirt_domain_snapshot_delete($vm_snapshot_res_to_delete); //ace_kvm_log_error(); } else { $all_delete_results = TRUE; } } else { $revert_result = FALSE; } return $revert_result && $all_delete_results; }