mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-01 20:58:18 +03:00
F #4913: Tweak the snapshot actions
Snapshot name is stored in the description field of vCenter The information is passed via STDIN and not as positional argument
This commit is contained in:
parent
36c66e5888
commit
469ff036a7
@ -739,7 +739,8 @@ class ExecDriver < VirtualMachineDriver
|
||||
id,
|
||||
host,
|
||||
ACTION[:snapshot_create],
|
||||
:script_name => "snapshot_create")
|
||||
:script_name => "snapshot_create",
|
||||
:stdin => xml_data)
|
||||
end
|
||||
|
||||
#
|
||||
|
@ -989,12 +989,12 @@ class VirtualMachine
|
||||
end
|
||||
|
||||
# Create a snapshot for the VM
|
||||
def create_snapshot(snapshot_name, vm_ref)
|
||||
def create_snapshot(snap_id, snap_name)
|
||||
snapshot_hash = {
|
||||
:name => snapshot_name,
|
||||
:description => "OpenNebula Snapshot of VM #{vm_ref}",
|
||||
:memory => true,
|
||||
:quiesce => true
|
||||
:name => snap_id,
|
||||
:description => snap_name,
|
||||
:memory => true,
|
||||
:quiesce => true
|
||||
}
|
||||
|
||||
begin
|
||||
@ -1003,14 +1003,14 @@ class VirtualMachine
|
||||
raise "Cannot create snapshot for VM: #{e.message}"
|
||||
end
|
||||
|
||||
return snapshot_name
|
||||
return snap_id
|
||||
end
|
||||
|
||||
# Revert to a VM snapshot
|
||||
def revert_snapshot(snapshot_name)
|
||||
def revert_snapshot(snap_id)
|
||||
|
||||
snapshot_list = self["snapshot.rootSnapshotList"]
|
||||
snapshot = find_snapshot_in_list(snapshot_list, snapshot_name)
|
||||
snapshot = find_snapshot_in_list(snapshot_list, snap_id)
|
||||
|
||||
return nil if !snapshot
|
||||
|
||||
@ -1023,10 +1023,10 @@ class VirtualMachine
|
||||
end
|
||||
|
||||
# Delete VM snapshot
|
||||
def delete_snapshot(snapshot_name)
|
||||
def delete_snapshot(snap_id)
|
||||
|
||||
snapshot_list = self["snapshot.rootSnapshotList"]
|
||||
snapshot = find_snapshot_in_list(snapshot_list, snapshot_name)
|
||||
snapshot = find_snapshot_in_list(snapshot_list, snap_id)
|
||||
|
||||
return nil if !snapshot
|
||||
|
||||
@ -1041,12 +1041,12 @@ class VirtualMachine
|
||||
end
|
||||
end
|
||||
|
||||
def find_snapshot_in_list(list, snapshot_name)
|
||||
def find_snapshot_in_list(list, snap_id)
|
||||
list.each do |i|
|
||||
if i.name == snapshot_name
|
||||
if i.name == snap_id.to_s
|
||||
return i.snapshot
|
||||
elsif !i.childSnapshotList.empty?
|
||||
snap = find_snapshot(i.childSnapshotList, snapshot_name)
|
||||
snap = find_snapshot(i.childSnapshotList, snap_id)
|
||||
return snap if snap
|
||||
end
|
||||
end rescue nil
|
||||
|
@ -30,18 +30,23 @@ $: << File.dirname(__FILE__)
|
||||
require 'vcenter_driver2'
|
||||
|
||||
vm_ref = ARGV[0]
|
||||
snapshot_name = ARGV[1]
|
||||
snap_id = ARGV[1]
|
||||
vc_cluster_name = ARGV[3]
|
||||
|
||||
drv_action = OpenNebula::XMLElement.new
|
||||
drv_action.initialize_xml(Base64.decode64(STDIN.read), 'VMM_DRIVER_ACTION_DATA')
|
||||
|
||||
host = VCenterDriver::VIHelper.find_by_name(OpenNebula::HostPool, vc_cluster_name)
|
||||
host_id = host['ID']
|
||||
|
||||
snap_name = drv_action["VM/TEMPLATE/SNAPSHOT[ACTIVE='YES']/NAME"]
|
||||
|
||||
begin
|
||||
vi_client = VCenterDriver::VIClient.new_from_host(host_id)
|
||||
|
||||
vm = VCenterDriver::VirtualMachine.new_from_ref(vm_ref, vi_client)
|
||||
|
||||
vm.create_snapshot(snapshot_name, vm_ref)
|
||||
vm.create_snapshot(snap_id, snap_name)
|
||||
|
||||
rescue Exception => e
|
||||
STDERR.puts "Snapshot of VM #{vm_ref} on vCenter cluster "\
|
||||
|
@ -30,7 +30,7 @@ $: << File.dirname(__FILE__)
|
||||
require 'vcenter_driver2'
|
||||
|
||||
vm_ref = ARGV[0]
|
||||
snapshot_name = ARGV[1]
|
||||
snap_id = ARGV[1]
|
||||
vc_cluster_name = ARGV[3]
|
||||
|
||||
host = VCenterDriver::VIHelper.find_by_name(OpenNebula::HostPool, vc_cluster_name)
|
||||
@ -41,7 +41,7 @@ begin
|
||||
|
||||
vm = VCenterDriver::VirtualMachine.new_from_ref(vm_ref, vi_client)
|
||||
|
||||
vm.delete_snapshot(snapshot_name)
|
||||
vm.delete_snapshot(snap_id)
|
||||
|
||||
rescue Exception => e
|
||||
STDERR.puts "Snapshot of VM #{vm_ref} on vCenter cluster "\
|
||||
|
@ -30,7 +30,7 @@ $: << File.dirname(__FILE__)
|
||||
require 'vcenter_driver2'
|
||||
|
||||
vm_ref = ARGV[0]
|
||||
snapshot_name = ARGV[1]
|
||||
snap_id = ARGV[1]
|
||||
vc_cluster_name = ARGV[3]
|
||||
|
||||
host = VCenterDriver::VIHelper.find_by_name(OpenNebula::HostPool, vc_cluster_name)
|
||||
@ -41,7 +41,7 @@ begin
|
||||
|
||||
vm = VCenterDriver::VirtualMachine.new_from_ref(vm_ref, vi_client)
|
||||
|
||||
vm.revert_snapshot(snapshot_name)
|
||||
vm.revert_snapshot(snap_id)
|
||||
|
||||
rescue Exception => e
|
||||
STDERR.puts "Snapshot of VM #{vm_ref} on vCenter cluster "\
|
||||
|
Loading…
x
Reference in New Issue
Block a user