class VirtualMachineDriver
This class provides basic messaging and logging functionality to implement OpenNebula
Drivers. A driver is a program that specialize the OpenNebula
behavior by interfacing with specific infrastructure functionalities.
A Driver inherits this class and only has to provide methods for each action it wants to receive. The method must be associated with the action name through the register_action function
Constants
- ACTION
Virtual Machine Driver Protocol constants
- HOST_ARG
- POLL_ATTRIBUTE
- VM_STATE
Public Class Methods
Register default actions for the protocol.
@param [String] directory path inside remotes path where the scripts
reside
@param [Hash] options options for OpenNebula
driver (check the available
options in {OpenNebulaDriver#initialize})
@option options [Boolean] :threaded (true) enables or disables threads
OpenNebulaDriver::new
# File lib/VirtualMachineDriver.rb, line 71 def initialize(directory, options={}) @options={ :threaded => true, :single_host => true }.merge!(options) super(directory, @options) @hosts = Array.new register_action(ACTION[:deploy].to_sym, method("deploy")) register_action(ACTION[:shutdown].to_sym, method("shutdown")) register_action(ACTION[:reboot].to_sym, method("reboot")) register_action(ACTION[:reset].to_sym, method("reset")) register_action(ACTION[:cancel].to_sym, method("cancel")) register_action(ACTION[:save].to_sym, method("save")) register_action(ACTION[:restore].to_sym, method("restore")) register_action(ACTION[:migrate].to_sym, method("migrate")) 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[:snapshot_create].to_sym, method("snapshot_create")) register_action(ACTION[:snapshot_revert].to_sym, method("snapshot_revert")) register_action(ACTION[:snapshot_delete].to_sym, method("snapshot_delete")) register_action(ACTION[:cleanup].to_sym, method("cleanup")) register_action(ACTION[:attach_nic].to_sym, method("attach_nic")) register_action(ACTION[:detach_nic].to_sym, method("detach_nic")) register_action(ACTION[:disk_snapshot_create].to_sym, method("disk_snapshot_create")) register_action(ACTION[:resize_disk].to_sym, method("resize_disk")) register_action(ACTION[:update_sg].to_sym, method("update_sg")) register_action(ACTION[:update_conf].to_sym, method("update_conf")) register_action(ACTION[:resize].to_sym, method("resize")) end
Public Instance Methods
# File lib/VirtualMachineDriver.rb, line 172 def attach_disk(id, drv_message) error = "Action not implemented by driver #{self.class}" send_message(ACTION[:attach_disk],RESULT[:failure],id,error) end
# File lib/VirtualMachineDriver.rb, line 182 def attach_nic(id, drv_message) error = "Action not implemented by driver #{self.class}" send_message(ACTION[:attach_nic],RESULT[:failure],id,error) end
# File lib/VirtualMachineDriver.rb, line 147 def cancel(id, drv_message) error = "Action not implemented by driver #{self.class}" send_message(ACTION[:cancel],RESULT[:failure],id,error) end
# File lib/VirtualMachineDriver.rb, line 222 def cleanup(id, drv_message) error = "Action not implemented by driver #{self.class}" send_message(ACTION[:cleanup],RESULT[:failure],id,error) end
Decodes the encoded XML driver message received from the core
@param [String] drv_message the driver message @return [REXML::Element] the root element of the decoded XML message
# File lib/VirtualMachineDriver.rb, line 109 def decode(drv_message) message = Base64.decode64(drv_message) xml_doc = REXML::Document.new(message) xml_doc.root end
Virtual Machine Manager Protocol Actions (generic implementation)
# File lib/VirtualMachineDriver.rb, line 127 def deploy(id, drv_message) error = "Action not implemented by driver #{self.class}" send_message(ACTION[:deploy],RESULT[:failure],id,error) end
# File lib/VirtualMachineDriver.rb, line 177 def detach_disk(id, drv_message) error = "Action not implemented by driver #{self.class}" send_message(ACTION[:detach_disk],RESULT[:failure],id,error) end
# File lib/VirtualMachineDriver.rb, line 187 def detach_nic(id, drv_message) error = "Action not implemented by driver #{self.class}" send_message(ACTION[:detach_nic],RESULT[:failure],id,error) end
# File lib/VirtualMachineDriver.rb, line 207 def disk_snapshot_create(id, drv_message) error = "Action not implemented by driver #{self.class}" send_message(ACTION[:disk_snapshot_create],RESULT[:failure],id,error) end
Execute a command associated to an action and id on localhost
# File lib/VirtualMachineDriver.rb, line 122 def local_action(command, id, action) super(command,id,ACTION[action]) end
# File lib/VirtualMachineDriver.rb, line 162 def migrate(id, drv_message) error = "Action not implemented by driver #{self.class}" send_message(ACTION[:migrate],RESULT[:failure],id,error) end
# File lib/VirtualMachineDriver.rb, line 167 def poll(id, drv_message) error = "Action not implemented by driver #{self.class}" send_message(ACTION[:poll],RESULT[:failure],id,error) end
# File lib/VirtualMachineDriver.rb, line 137 def reboot(id, drv_message) error = "Action not implemented by driver #{self.class}" send_message(ACTION[:reboot],RESULT[:failure],id,error) end
Execute a command associated to an action and id in a remote host.
# File lib/VirtualMachineDriver.rb, line 117 def remotes_action(command, id, host, action, remote_dir, std_in=nil) super(command,id,host,ACTION[action],remote_dir,std_in) end
# File lib/VirtualMachineDriver.rb, line 142 def reset(id, drv_message) error = "Action not implemented by driver #{self.class}" send_message(ACTION[:reset],RESULT[:failure],id,error) end
# File lib/VirtualMachineDriver.rb, line 232 def resize(id, drv_message) error = "Action not implemented by driver #{self.class}" send_message(ACTION[:resize],RESULT[:failure],id,error) end
# File lib/VirtualMachineDriver.rb, line 212 def resize_disk(id, drv_message) error = "Action not implemented by driver #{self.class}" send_message(ACTION[:resize_disk],RESULT[:failure],id,error) end
# File lib/VirtualMachineDriver.rb, line 157 def restore(id, drv_message) error = "Action not implemented by driver #{self.class}" send_message(ACTION[:restore],RESULT[:failure],id,error) end
# File lib/VirtualMachineDriver.rb, line 152 def save(id, drv_message) error = "Action not implemented by driver #{self.class}" send_message(ACTION[:save],RESULT[:failure],id,error) end
# File lib/VirtualMachineDriver.rb, line 132 def shutdown(id, drv_message) error = "Action not implemented by driver #{self.class}" send_message(ACTION[:shutdown],RESULT[:failure],id,error) end
# File lib/VirtualMachineDriver.rb, line 192 def snapshot_create(id, drv_message) error = "Action not implemented by driver #{self.class}" send_message(ACTION[:snapshot_create],RESULT[:failure],id,error) end
# File lib/VirtualMachineDriver.rb, line 202 def snapshot_delete(id, drv_message) error = "Action not implemented by driver #{self.class}" send_message(ACTION[:snapshot_delete],RESULT[:failure],id,error) end
# File lib/VirtualMachineDriver.rb, line 197 def snapshot_revert(id, drv_message) error = "Action not implemented by driver #{self.class}" send_message(ACTION[:snapshot_revert],RESULT[:failure],id,error) end
# File lib/VirtualMachineDriver.rb, line 227 def update_conf(id, drv_message) error = "Action not implemented by driver #{self.class}" send_message(ACTION[:update_conf],RESULT[:failure],id,error) end
# File lib/VirtualMachineDriver.rb, line 217 def update_sg(id, drv_message) error = "Action not implemented by driver #{self.class}" send_message(ACTION[:update_sg],RESULT[:failure],id,error) end
Private Instance Methods
Interface to handle the pending events from the ActionManager
Interface
ActionManager#delete_running_action
# File lib/VirtualMachineDriver.rb, line 240 def delete_running_action(action_id) if @options[:single_host] delete_running_action_single_host(action_id) else super(action_id) end end
# File lib/VirtualMachineDriver.rb, line 248 def delete_running_action_single_host(action_id) action=@action_running[action_id] if action @hosts.delete(action[:host]) @action_running.delete(action_id) end end
ActionManager#empty_queue
# File lib/VirtualMachineDriver.rb, line 320 def empty_queue if @options[:single_host] empty_queue_single_host else super end end
# File lib/VirtualMachineDriver.rb, line 328 def empty_queue_single_host get_first_runable==nil end
# File lib/VirtualMachineDriver.rb, line 256 def get_first_runable if @options[:single_host] get_first_runable_single_host else super end end
# File lib/VirtualMachineDriver.rb, line 264 def get_first_runable_single_host action_index=nil @action_queue.each_with_index do |action, index| if !action.keys.include?(:host) if action[:args].length == 2 begin xml=decode(action[:args].last) host=xml.elements['HOST'] action[:host]=host.text if host rescue action[:host]=nil end else action[:host]=nil end end if action.keys.include?(:host) && action[:host] if !@hosts.include?(action[:host]) action_index=index break end else action_index=index break end end return action_index end
ActionManager#get_runable_action
# File lib/VirtualMachineDriver.rb, line 295 def get_runable_action if @options[:single_host] get_runable_action_single_host else super end end
# File lib/VirtualMachineDriver.rb, line 303 def get_runable_action_single_host action_index=get_first_runable if action_index action=@action_queue[action_index] else action=nil end if action @hosts << action[:host] if action[:host] @action_queue.delete_at(action_index) end return action end