1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-08 20:58:17 +03:00

feature #3782: Snapshots (create & revert operations) in running can be

performed either in a suspend/snap/restore cycle or in a detach/snap/attach one.
Allow to revert to the current snapshot
This commit is contained in:
Ruben S. Montero 2015-07-08 17:56:24 +02:00
parent f350ec8ee0
commit ae86849be6
3 changed files with 98 additions and 105 deletions

View File

@ -418,6 +418,10 @@ IM_MAD = [
# overridden for each action. # overridden for each action.
# Valid actions: deploy, shutdown, cancel, save, restore, migrate, poll # Valid actions: deploy, shutdown, cancel, save, restore, migrate, poll
# An example: "-l migrate=migrate_local,save" # An example: "-l migrate=migrate_local,save"
# -p more than one action per host in parallel, needs support from hypervisor
# -s <shell> to execute remote commands, bash by default
# -d detach disks on running VMs before creating/reverting snaps, by default
# the VM will be suspended
# #
# Note: You can use type = "qemu" to use qemu emulated guests, e.g. if your # Note: You can use type = "qemu" to use qemu emulated guests, e.g. if your
# CPU does not have virtualization extensions or use nested Qemu-KVM hosts # CPU does not have virtualization extensions or use nested Qemu-KVM hosts
@ -438,8 +442,12 @@ VM_MAD = [
# overridden for each action. # overridden for each action.
# Valid actions: deploy, shutdown, cancel, save, restore, migrate, poll # Valid actions: deploy, shutdown, cancel, save, restore, migrate, poll
# An example: "-l migrate,save" # An example: "-l migrate,save"
# -p more than one action per host in parallel, needs support from hypervisor
# -s <shell> to execute commands, bash by default
# -d detach disks on running VMs before creating/reverting snaps, by default
# the VM will be suspended
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
#
# Driver for Xen 3.x # Driver for Xen 3.x
#VM_MAD = [ #VM_MAD = [
# name = "xen", # name = "xen",
@ -447,7 +455,7 @@ VM_MAD = [
# arguments = "-t 15 -r 0 xen3", # arguments = "-t 15 -r 0 xen3",
# default = "vmm_exec/vmm_exec_xen3.conf", # default = "vmm_exec/vmm_exec_xen3.conf",
# type = "xen" ] # type = "xen" ]
#
# Driver for Xen 4.x # Driver for Xen 4.x
#VM_MAD = [ #VM_MAD = [
# name = "xen", # name = "xen",
@ -455,13 +463,17 @@ VM_MAD = [
# arguments = "-t 15 -r 0 xen4", # arguments = "-t 15 -r 0 xen4",
# default = "vmm_exec/vmm_exec_xen4.conf", # default = "vmm_exec/vmm_exec_xen4.conf",
# type = "xen" ] # type = "xen" ]
#
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# VMware Virtualization Driver Manager Configuration # VMware Virtualization Driver Manager Configuration
# -r number of retries when monitoring a host # -r number of retries when monitoring a host
# -t number of threads, i.e. number of hosts monitored at the same time # -t number of threads, i.e. number of hosts monitored at the same time
# -p more than one action per host in parallel, needs support from hypervisor
# -s <shell> to execute commands, bash by default
# -d detach disks on running VMs before creating/reverting snaps, by default
# the VM will be suspended
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
#VM_MAD = [ #VM_MAD = [
# name = "vmware", # name = "vmware",
@ -471,11 +483,14 @@ VM_MAD = [
# type = "vmware" ] # type = "vmware" ]
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# vCenter Virtualization Driver Manager Configuration # vCenter Virtualization Driver Manager Configuration
# -r number of retries when monitoring a host # -r number of retries when monitoring a host
# -t number of threads, i.e. number of hosts monitored at the same time # -t number of threads, i.e. number of hosts monitored at the same time
# -p more than one action per host in parallel, needs support from hypervisor
# -s <shell> to execute commands, bash by default
# -d detach disks on running VMs before creating/reverting snaps, by default
# the VM will be suspended
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
#VM_MAD = [ #VM_MAD = [
# name = "vcenter", # name = "vcenter",

View File

@ -1750,14 +1750,6 @@ int DispatchManager::disk_snapshot_revert(
return -1; return -1;
} }
if (snaps->get_active_id() == snap_id)
{
error_str = "Snapshot is already the active one";
vm->unlock();
return -1;
}
if (vm->set_snapshot_disk(did, snap_id) == -1) if (vm->set_snapshot_disk(did, snap_id) == -1)
{ {
vm->unlock(); vm->unlock();

View File

@ -669,7 +669,6 @@ class ExecDriver < VirtualMachineDriver
# SNAPSHOTCREATE action, creates a new system snapshot # SNAPSHOTCREATE action, creates a new system snapshot
# #
def snapshot_create(id, drv_message) def snapshot_create(id, drv_message)
action = ACTION[:snapshot_create]
xml_data = decode(drv_message) xml_data = decode(drv_message)
host = xml_data.elements['HOST'].text host = xml_data.elements['HOST'].text
@ -689,7 +688,6 @@ class ExecDriver < VirtualMachineDriver
# SNAPSHOTREVERT action, reverts to a system snapshot # SNAPSHOTREVERT action, reverts to a system snapshot
# #
def snapshot_revert(id, drv_message) def snapshot_revert(id, drv_message)
action = ACTION[:snapshot_revert]
xml_data = decode(drv_message) xml_data = decode(drv_message)
host = xml_data.elements['HOST'].text host = xml_data.elements['HOST'].text
@ -709,7 +707,6 @@ class ExecDriver < VirtualMachineDriver
# SNAPSHOTDELETE action, deletes a system snapshot # SNAPSHOTDELETE action, deletes a system snapshot
# #
def snapshot_delete(id, drv_message) def snapshot_delete(id, drv_message)
action = ACTION[:snapshot_delete]
xml_data = decode(drv_message) xml_data = decode(drv_message)
host = xml_data.elements['HOST'].text host = xml_data.elements['HOST'].text
@ -729,7 +726,6 @@ class ExecDriver < VirtualMachineDriver
# CLEANUP action, frees resources allocated in a host: VM and disk images # CLEANUP action, frees resources allocated in a host: VM and disk images
# #
def cleanup(id, drv_message) def cleanup(id, drv_message)
aname = ACTION[:cleanup]
xml_data = decode(drv_message) xml_data = decode(drv_message)
tm_command = xml_data.elements['TM_COMMAND'].text tm_command = xml_data.elements['TM_COMMAND'].text
@ -899,48 +895,56 @@ class ExecDriver < VirtualMachineDriver
tm_rollback= xml_data.elements['TM_COMMAND_ROLLBACK'].text.strip tm_rollback= xml_data.elements['TM_COMMAND_ROLLBACK'].text.strip
target_xpath = "VM/TEMPLATE/DISK[DISK_SNAPSHOT_ACTIVE='YES']/TARGET" target_xpath = "VM/TEMPLATE/DISK[DISK_SNAPSHOT_ACTIVE='YES']/TARGET"
target = ensure_xpath(xml_data, id, action, target_xpath) || return target = ensure_xpath(xml_data, id, action, target_xpath) ||return
target_index = target.downcase[-1..-1].unpack('c').first - 97 target_index = target.downcase[-1..-1].unpack('c').first - 97
disk = xml_data.elements[target_xpath] if @options[:detach_snap]
attach = REXML::Element.new('ATTACH') disk = xml_data.elements[target_xpath]
attach.add_text('YES') attach = REXML::Element.new('ATTACH')
disk.add(attach)
drv_message = Base64.encode64(xml_data.to_s) attach.add_text('YES')
disk.add(attach)
drv_message = Base64.encode64(xml_data.to_s)
end
action = VmmAction.new(self, id, :disk_snapshot_create, drv_message) action = VmmAction.new(self, id, :disk_snapshot_create, drv_message)
if @options[:detach_snap]
pre_action = :detach_disk
pre_params = [:deploy_id, :disk_target_path, target, target_index]
post_action = :attach_disk
post_params = [:deploy_id, :disk_target_path, target, target_index,
drv_message]
else
pre_action = :save
pre_params = [:deploy_id, :checkpoint_file, :host]
post_action = :restore
post_params = [:checkpoint_file, :host, :deploy_id]
end
steps = [ steps = [
# First detach the disk from the VM # Save VM state / detach the disk
#{
# :driver => :vmm,
# :action => :detach_disk,
# :parameters => [
# :deploy_id,
# :disk_target_path,
# target,
# target_index
# ]
#},
# Save the Virtual Machine state
{ {
:driver => :vmm, :driver => :vmm,
:action => :save, :action => pre_action,
:parameters => [:deploy_id, :checkpoint_file, :host] :parameters => pre_params
}, },
# Do the snapshot # Do the snapshot
{ {
:driver => :tm, :driver => :tm,
:action => :tm_snap_create, :action => :tm_snap_create,
:parameters => tm_command.split :parameters => tm_command.split,
:no_fail => true
}, },
# Restore the Virtual Machine from checkpoint # Restore VM / attach the disk
{ {
:driver => :vmm, :driver => :vmm,
:action => :restore, :action => post_action,
:parameters => [:checkpoint_file, :host, :deploy_id], :parameters => post_params,
:fail_actions => [ :fail_actions => [
{ {
:driver => :tm, :driver => :tm,
@ -948,26 +952,7 @@ class ExecDriver < VirtualMachineDriver
:parameters => tm_rollback.split :parameters => tm_rollback.split
} }
] ]
}, }
# Attach the disk again
#{
# :driver => :vmm,
# :action => :attach_disk,
# :parameters => [
# :deploy_id,
# :disk_target_path,
# target,
# target_index,
# drv_message
# ],
# :fail_actions => [
# {
# :driver => :tm,
# :action => :tm_snap_delete,
# :parameters => tm_rollback.split
# }
# ]
#}
] ]
action.run(steps) action.run(steps)
@ -983,61 +968,57 @@ class ExecDriver < VirtualMachineDriver
tm_command = ensure_xpath(xml_data, id, action, 'TM_COMMAND') || return tm_command = ensure_xpath(xml_data, id, action, 'TM_COMMAND') || return
target_xpath = "VM/TEMPLATE/DISK[DISK_SNAPSHOT_ACTIVE='YES']/TARGET" target_xpath = "VM/TEMPLATE/DISK[DISK_SNAPSHOT_ACTIVE='YES']/TARGET"
target = ensure_xpath(xml_data, id, action, target_xpath) || return target = ensure_xpath(xml_data, id, action, target_xpath) ||return
target_index = target.downcase[-1..-1].unpack('c').first - 97 target_index = target.downcase[-1..-1].unpack('c').first - 97
disk = xml_data.elements[target_xpath] if @options[:detach_snap]
attach = REXML::Element.new('ATTACH') disk = xml_data.elements[target_xpath]
attach.add_text('YES') attach = REXML::Element.new('ATTACH')
disk.add(attach)
drv_message = Base64.encode64(xml_data.to_s) attach.add_text('YES')
disk.add(attach)
drv_message = Base64.encode64(xml_data.to_s)
end
action = VmmAction.new(self, id, :disk_snapshot_revert, drv_message) action = VmmAction.new(self, id, :disk_snapshot_revert, drv_message)
if @options[:detach_snap]
pre_action = :detach_disk
pre_params = [:deploy_id, :disk_target_path, target, target_index]
post_action = :attach_disk
post_params = [:deploy_id, :disk_target_path, target, target_index,
drv_message]
else
pre_action = :save
pre_params = [:deploy_id, :checkpoint_file, :host]
post_action = :restore
post_params = [:checkpoint_file, :host, :deploy_id]
end
steps = [ steps = [
# First detach the disk from the VM # Save VM state / detach the disk
#{
# :driver => :vmm,
# :action => :detach_disk,
# :parameters => [
# :deploy_id,
# :disk_target_path,
# target,
# target_index
# ]
#},
# Save the Virtual Machine state
{ {
:driver => :vmm, :driver => :vmm,
:action => :save, :action => pre_action,
:parameters => [:deploy_id, :checkpoint_file, :host] :parameters => pre_params
}, },
# Do the snapshot # Do the snapshot
{ {
:driver => :tm, :driver => :tm,
:action => :tm_snap_revert, :action => :tm_snap_revert,
:parameters => tm_command.split :parameters => tm_command.split,
:no_fail => true,
}, },
# Restore the Virtual Machine from checkpoint # Restore VM / attach the disk
{ {
:driver => :vmm, :driver => :vmm,
:action => :restore, :action => post_action,
:parameters => [:checkpoint_file, :host, :deploy_id] :parameters => post_params
}, }
# Attach the disk again
#{
# :driver => :vmm,
# :action => :attach_disk,
# :parameters => [
# :deploy_id,
# :disk_target_path,
# target,
# target_index,
# drv_message
# ]
#}
] ]
action.run(steps) action.run(steps)
@ -1069,15 +1050,17 @@ opts = GetoptLong.new(
[ '--threads', '-t', GetoptLong::OPTIONAL_ARGUMENT ], [ '--threads', '-t', GetoptLong::OPTIONAL_ARGUMENT ],
[ '--local', '-l', GetoptLong::REQUIRED_ARGUMENT ], [ '--local', '-l', GetoptLong::REQUIRED_ARGUMENT ],
[ '--shell', '-s', GetoptLong::REQUIRED_ARGUMENT ], [ '--shell', '-s', GetoptLong::REQUIRED_ARGUMENT ],
[ '--parallel', '-p', GetoptLong::NO_ARGUMENT ] [ '--parallel', '-p', GetoptLong::NO_ARGUMENT ],
[ '--detach-snap','-d', GetoptLong::NO_ARGUMENT ]
) )
hypervisor = '' hypervisor = ''
retries = 0 retries = 0
threads = 15 threads = 15
shell = 'bash' shell = 'bash'
local_actions = {} local_actions = {}
single_host = true single_host = true
detach_snap = false
begin begin
opts.each do |opt, arg| opts.each do |opt, arg|
@ -1092,6 +1075,8 @@ begin
shell = arg shell = arg
when '--parallel' when '--parallel'
single_host = false single_host = false
when '--detach-snap'
detach_snap = true
end end
end end
rescue Exception => e rescue Exception => e
@ -1109,6 +1094,7 @@ exec_driver = ExecDriver.new(hypervisor,
:retries => retries, :retries => retries,
:local_actions => local_actions, :local_actions => local_actions,
:shell => shell, :shell => shell,
:single_host => single_host) :single_host => single_host,
:detach_snap => detach_snap)
exec_driver.start_driver exec_driver.start_driver