mirror of
https://github.com/OpenNebula/one.git
synced 2025-02-01 05:47:01 +03:00
feature #1685: Adds a new cleanup operation to VMM driver. It cancels the VM and removes all associated files, the operations are synchronized
This commit is contained in:
parent
934f4b0271
commit
c46c0686f4
@ -42,6 +42,7 @@ class VirtualMachineDriver < OpenNebulaDriver
|
||||
:log => "LOG",
|
||||
:attach_disk => "ATTACHDISK",
|
||||
:detach_disk => "DETACHDISK",
|
||||
:cleanup => "CLEANUP"
|
||||
}
|
||||
|
||||
POLL_ATTRIBUTE = {
|
||||
@ -89,6 +90,7 @@ class VirtualMachineDriver < OpenNebulaDriver
|
||||
register_action(ACTION[:poll].to_sym, method("poll"))
|
||||
register_action(ACTION[:attach_disk].to_sym, method("attach_disk"))
|
||||
register_action(ACTION[:detach_disk].to_sym, method("detach_disk"))
|
||||
register_action(ACTION[:cleanup].to_sym, method("cleanup"))
|
||||
end
|
||||
|
||||
# Decodes the encoded XML driver message received from the core
|
||||
@ -168,6 +170,11 @@ class VirtualMachineDriver < OpenNebulaDriver
|
||||
send_message(ACTION[:detach_disk],RESULT[:failure],id,error)
|
||||
end
|
||||
|
||||
def cleanup(id, drv_message)
|
||||
error = "Action not implemented by driver #{self.class}"
|
||||
send_message(ACTION[:cleanup],RESULT[:failure],id,error)
|
||||
end
|
||||
|
||||
private
|
||||
# Interface to handle the pending events from the ActionManager Interface
|
||||
def delete_running_action(action_id)
|
||||
|
@ -128,6 +128,12 @@ class DummyDriver < VirtualMachineDriver
|
||||
send_message(ACTION[:detach_disk],result,id)
|
||||
end
|
||||
|
||||
def cleanup(id, drv_message)
|
||||
result = retrieve_result("cleanup")
|
||||
|
||||
send_message(ACTION[:cleanup],result,id)
|
||||
end
|
||||
|
||||
def poll(id, drv_message)
|
||||
result = retrieve_result("poll")
|
||||
|
||||
@ -159,7 +165,7 @@ class DummyDriver < VirtualMachineDriver
|
||||
"#{POLL_ATTRIBUTE[:nettx]}=#{prev_nettx+(50*rand(3))} " \
|
||||
"#{POLL_ATTRIBUTE[:netrx]}=#{prev_netrx+(100*rand(4))} " \
|
||||
"#{POLL_ATTRIBUTE[:usedmemory]}=#{max_memory * (rand(80)+20)/100} " \
|
||||
"#{POLL_ATTRIBUTE[:usedcpu]}=#{max_cpu * (rand(95)+5)/100}"
|
||||
"#{POLL_ATTRIBUTE[:usedcpu]}=#{max_cpu * (rand(95)+5)/100}"
|
||||
|
||||
send_message(ACTION[:poll],result,id,monitor_info)
|
||||
end
|
||||
@ -194,4 +200,4 @@ class DummyDriver < VirtualMachineDriver
|
||||
end
|
||||
|
||||
dd = DummyDriver.new
|
||||
dd.start_driver
|
||||
dd.start_driver
|
||||
|
@ -542,7 +542,7 @@ class ExecDriver < VirtualMachineDriver
|
||||
# Bug #1355, argument character limitation in ESX
|
||||
# Message not used in vmware anyway
|
||||
if @hypervisor == "vmware"
|
||||
drv_message = "drv_message"
|
||||
drv_message = "drv_message"
|
||||
end
|
||||
|
||||
steps = [
|
||||
@ -608,6 +608,54 @@ class ExecDriver < VirtualMachineDriver
|
||||
action.run(steps)
|
||||
end
|
||||
|
||||
#
|
||||
# CLEANUP action, frees resources allocated in a host: VM and disk images
|
||||
#
|
||||
def cleanup(id, drv_message)
|
||||
aname = ACTION[:cleanup]
|
||||
xml_data = decode(drv_message)
|
||||
|
||||
tm_command = xml_data.elements['TM_COMMAND'].text.strip
|
||||
mhost = xml_data.elements['MIGR_HOST'].text.strip
|
||||
|
||||
action = VmmAction.new(self, id, :cleanup, drv_message)
|
||||
|
||||
# Cancel the VM at host
|
||||
steps = [
|
||||
{
|
||||
:driver => :vmm,
|
||||
:action => :cancel,
|
||||
:parameters => [:deploy_id, :host],
|
||||
:no_fail => true
|
||||
}
|
||||
]
|
||||
|
||||
# Cancel the VM at the previous host (in case of migration)
|
||||
steps <<
|
||||
{
|
||||
:driver => :vmm,
|
||||
:action => :cancel,
|
||||
:parameters => [:deploy_id, :dest_host],
|
||||
:destination => true,
|
||||
:no_fail => true
|
||||
} if !mhost.empty?
|
||||
|
||||
# Cleans VM disk images and directory
|
||||
tm_command.each_line { |tc|
|
||||
tc.strip!
|
||||
|
||||
steps <<
|
||||
{
|
||||
:driver => :tm,
|
||||
:action => :tm_command,
|
||||
:parameters => tm_command.split
|
||||
:no_fail => true
|
||||
} if !tc.empty?
|
||||
}
|
||||
|
||||
action.run(steps)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def ensure_xpath(xml_data, id, action, xpath)
|
||||
|
Loading…
x
Reference in New Issue
Block a user