mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-03 00: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,
|
id,
|
||||||
host,
|
host,
|
||||||
ACTION[:snapshot_create],
|
ACTION[:snapshot_create],
|
||||||
:script_name => "snapshot_create")
|
:script_name => "snapshot_create",
|
||||||
|
:stdin => xml_data)
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -989,12 +989,12 @@ class VirtualMachine
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Create a snapshot for the VM
|
# Create a snapshot for the VM
|
||||||
def create_snapshot(snapshot_name, vm_ref)
|
def create_snapshot(snap_id, snap_name)
|
||||||
snapshot_hash = {
|
snapshot_hash = {
|
||||||
:name => snapshot_name,
|
:name => snap_id,
|
||||||
:description => "OpenNebula Snapshot of VM #{vm_ref}",
|
:description => snap_name,
|
||||||
:memory => true,
|
:memory => true,
|
||||||
:quiesce => true
|
:quiesce => true
|
||||||
}
|
}
|
||||||
|
|
||||||
begin
|
begin
|
||||||
@ -1003,14 +1003,14 @@ class VirtualMachine
|
|||||||
raise "Cannot create snapshot for VM: #{e.message}"
|
raise "Cannot create snapshot for VM: #{e.message}"
|
||||||
end
|
end
|
||||||
|
|
||||||
return snapshot_name
|
return snap_id
|
||||||
end
|
end
|
||||||
|
|
||||||
# Revert to a VM snapshot
|
# Revert to a VM snapshot
|
||||||
def revert_snapshot(snapshot_name)
|
def revert_snapshot(snap_id)
|
||||||
|
|
||||||
snapshot_list = self["snapshot.rootSnapshotList"]
|
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
|
return nil if !snapshot
|
||||||
|
|
||||||
@ -1023,10 +1023,10 @@ class VirtualMachine
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Delete VM snapshot
|
# Delete VM snapshot
|
||||||
def delete_snapshot(snapshot_name)
|
def delete_snapshot(snap_id)
|
||||||
|
|
||||||
snapshot_list = self["snapshot.rootSnapshotList"]
|
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
|
return nil if !snapshot
|
||||||
|
|
||||||
@ -1041,12 +1041,12 @@ class VirtualMachine
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_snapshot_in_list(list, snapshot_name)
|
def find_snapshot_in_list(list, snap_id)
|
||||||
list.each do |i|
|
list.each do |i|
|
||||||
if i.name == snapshot_name
|
if i.name == snap_id.to_s
|
||||||
return i.snapshot
|
return i.snapshot
|
||||||
elsif !i.childSnapshotList.empty?
|
elsif !i.childSnapshotList.empty?
|
||||||
snap = find_snapshot(i.childSnapshotList, snapshot_name)
|
snap = find_snapshot(i.childSnapshotList, snap_id)
|
||||||
return snap if snap
|
return snap if snap
|
||||||
end
|
end
|
||||||
end rescue nil
|
end rescue nil
|
||||||
|
@ -30,18 +30,23 @@ $: << File.dirname(__FILE__)
|
|||||||
require 'vcenter_driver2'
|
require 'vcenter_driver2'
|
||||||
|
|
||||||
vm_ref = ARGV[0]
|
vm_ref = ARGV[0]
|
||||||
snapshot_name = ARGV[1]
|
snap_id = ARGV[1]
|
||||||
vc_cluster_name = ARGV[3]
|
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 = VCenterDriver::VIHelper.find_by_name(OpenNebula::HostPool, vc_cluster_name)
|
||||||
host_id = host['ID']
|
host_id = host['ID']
|
||||||
|
|
||||||
|
snap_name = drv_action["VM/TEMPLATE/SNAPSHOT[ACTIVE='YES']/NAME"]
|
||||||
|
|
||||||
begin
|
begin
|
||||||
vi_client = VCenterDriver::VIClient.new_from_host(host_id)
|
vi_client = VCenterDriver::VIClient.new_from_host(host_id)
|
||||||
|
|
||||||
vm = VCenterDriver::VirtualMachine.new_from_ref(vm_ref, vi_client)
|
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
|
rescue Exception => e
|
||||||
STDERR.puts "Snapshot of VM #{vm_ref} on vCenter cluster "\
|
STDERR.puts "Snapshot of VM #{vm_ref} on vCenter cluster "\
|
||||||
|
@ -30,7 +30,7 @@ $: << File.dirname(__FILE__)
|
|||||||
require 'vcenter_driver2'
|
require 'vcenter_driver2'
|
||||||
|
|
||||||
vm_ref = ARGV[0]
|
vm_ref = ARGV[0]
|
||||||
snapshot_name = ARGV[1]
|
snap_id = ARGV[1]
|
||||||
vc_cluster_name = ARGV[3]
|
vc_cluster_name = ARGV[3]
|
||||||
|
|
||||||
host = VCenterDriver::VIHelper.find_by_name(OpenNebula::HostPool, vc_cluster_name)
|
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 = VCenterDriver::VirtualMachine.new_from_ref(vm_ref, vi_client)
|
||||||
|
|
||||||
vm.delete_snapshot(snapshot_name)
|
vm.delete_snapshot(snap_id)
|
||||||
|
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
STDERR.puts "Snapshot of VM #{vm_ref} on vCenter cluster "\
|
STDERR.puts "Snapshot of VM #{vm_ref} on vCenter cluster "\
|
||||||
|
@ -30,7 +30,7 @@ $: << File.dirname(__FILE__)
|
|||||||
require 'vcenter_driver2'
|
require 'vcenter_driver2'
|
||||||
|
|
||||||
vm_ref = ARGV[0]
|
vm_ref = ARGV[0]
|
||||||
snapshot_name = ARGV[1]
|
snap_id = ARGV[1]
|
||||||
vc_cluster_name = ARGV[3]
|
vc_cluster_name = ARGV[3]
|
||||||
|
|
||||||
host = VCenterDriver::VIHelper.find_by_name(OpenNebula::HostPool, vc_cluster_name)
|
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 = VCenterDriver::VirtualMachine.new_from_ref(vm_ref, vi_client)
|
||||||
|
|
||||||
vm.revert_snapshot(snapshot_name)
|
vm.revert_snapshot(snap_id)
|
||||||
|
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
STDERR.puts "Snapshot of VM #{vm_ref} on vCenter cluster "\
|
STDERR.puts "Snapshot of VM #{vm_ref} on vCenter cluster "\
|
||||||
|
Loading…
x
Reference in New Issue
Block a user