1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-25 02:50:08 +03:00

F #4913: Store snapshot name, not snapshot id as the name for vcenter snapshots F#4921

This commit is contained in:
mcabrerizo 2017-04-04 20:12:58 +02:00
parent 7fe325f8a8
commit 8e460d9bd3
3 changed files with 22 additions and 12 deletions

View File

@ -1715,8 +1715,8 @@ class VirtualMachine
# Create a snapshot for the VM
def create_snapshot(snap_id, snap_name)
snapshot_hash = {
:name => snap_id,
:description => snap_name,
:name => snap_name,
:description => "OpenNebula's snapshot at #{Time.now}",
:memory => true,
:quiesce => true
}
@ -1742,7 +1742,7 @@ class VirtualMachine
until snapshot_created || elapsed_minutes == 1440
if !!@item['snapshot']
current_snapshot = @item['snapshot.currentSnapshot'] rescue nil
snapshot_found = find_snapshot(@item['snapshot.rootSnapshotList'], snapshot_name)
snapshot_found = find_snapshot(@item['snapshot.rootSnapshotList'], snap_name)
snapshot_created = !!snapshot_found && !!current_snapshot && current_snapshot._ref == snapshot_found._ref
end
sleep(60)
@ -1754,10 +1754,10 @@ class VirtualMachine
end
# Revert to a VM snapshot
def revert_snapshot(snap_id)
def revert_snapshot(snap_id, snap_name)
snapshot_list = self["snapshot.rootSnapshotList"]
snapshot = find_snapshot_in_list(snapshot_list, snap_id)
snapshot = find_snapshot_in_list(snapshot_list, snap_id, snap_name)
return nil if !snapshot
@ -1770,10 +1770,10 @@ class VirtualMachine
end
# Delete VM snapshot
def delete_snapshot(snap_id)
def delete_snapshot(snap_id, snap_name)
snapshot_list = self["snapshot.rootSnapshotList"]
snapshot = find_snapshot_in_list(snapshot_list, snap_id)
snapshot = find_snapshot_in_list(snapshot_list, snap_id, snap_name)
return nil if !snapshot
@ -1788,12 +1788,12 @@ class VirtualMachine
end
end
def find_snapshot_in_list(list, snap_id)
def find_snapshot_in_list(list, snap_id, snap_name)
list.each do |i|
if i.name == snap_id.to_s
if i.name == snap_id.to_s || i.name == snap_name.to_s
return i.snapshot
elsif !i.childSnapshotList.empty?
snap = find_snapshot_in_list(i.childSnapshotList, snap_id)
snap = find_snapshot_in_list(i.childSnapshotList, snap_id, snap_name)
return snap if snap
end
end rescue nil

View File

@ -31,6 +31,7 @@ require 'vcenter_driver'
vm_ref = ARGV[0]
snap_id = ARGV[1]
vm_id = ARGV[2]
vc_cluster_name = ARGV[3]
host = VCenterDriver::VIHelper.find_by_name(OpenNebula::HostPool, vc_cluster_name)
@ -41,7 +42,11 @@ begin
vm = VCenterDriver::VirtualMachine.new_from_ref(vm_ref, vi_client)
vm.delete_snapshot(snap_id)
# Get snapshot name
one_vm = VCenterDriver::VIHelper.one_item(OpenNebula::VirtualMachine, vm_id)
snap_name = one_vm["TEMPLATE/SNAPSHOT[SNAPSHOT_ID=#{snap_id}]/NAME"]
vm.delete_snapshot(snap_id, snap_name)
rescue Exception => e
STDERR.puts "Snapshot of VM #{vm_ref} on vCenter cluster "\

View File

@ -31,6 +31,7 @@ require 'vcenter_driver'
vm_ref = ARGV[0]
snap_id = ARGV[1]
vm_id = ARGV[2]
vc_cluster_name = ARGV[3]
host = VCenterDriver::VIHelper.find_by_name(OpenNebula::HostPool, vc_cluster_name)
@ -41,7 +42,11 @@ begin
vm = VCenterDriver::VirtualMachine.new_from_ref(vm_ref, vi_client)
vm.revert_snapshot(snap_id)
# Get snapshot name
one_vm = VCenterDriver::VIHelper.one_item(OpenNebula::VirtualMachine, vm_id)
snap_name = one_vm["TEMPLATE/SNAPSHOT[SNAPSHOT_ID=#{snap_id}]/NAME"]
vm.revert_snapshot(snap_id, snap_name)
rescue Exception => e
STDERR.puts "Snapshot of VM #{vm_ref} on vCenter cluster "\