Class: OpenNebulaDriver
- Inherits:
-
ActionManager
- Object
- ActionManager
- OpenNebulaDriver
- Includes:
- DriverExecHelper
- Defined in:
- lib/OpenNebulaDriver.rb
Overview
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
Direct Known Subclasses
Constant Summary
Constants included from DriverExecHelper
Instance Attribute Summary collapse
-
#local_scripts_base_path ⇒ String
readonly
Base path for scripts.
-
#local_scripts_path ⇒ String
readonly
Path for scripts.
-
#remote_scripts_base_path ⇒ String
readonly
Base path for scripts.
-
#remote_scripts_path ⇒ String
readonly
Path for scripts.
Class Method Summary collapse
-
.parse_actions_list(str) ⇒ Hash
This function parses a string with this form:.
Instance Method Summary collapse
-
#do_action(parameters, id, host, aname, ops = {}) ⇒ Object
Calls remotes or local action checking the action name and.
-
#initialize(directory, options = {}) ⇒ OpenNebulaDriver
constructor
Initialize OpenNebulaDriver object.
-
#start_driver ⇒ Object
Start the driver.
Methods included from DriverExecHelper
#action_command_line, #action_is_local?, #action_script_name, failed?, #get_info_from_execution, #initialize_helper, #log, #log_method, #read_configuration, #send_message
Methods inherited from ActionManager
#cancel_action, #register_action, #start_listener, #trigger_action
Constructor Details
#initialize(directory, options = {}) ⇒ OpenNebulaDriver
Initialize OpenNebulaDriver object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/OpenNebulaDriver.rb', line 52 def initialize(directory, = {}) @options={ :concurrency => 10, :threaded => true, :retries => 0, :local_actions => {}, :timeout => nil }.merge!() super(@options[:concurrency], @options[:threaded]) @retries = @options[:retries] @timeout = @options[:timeout] # Set default values initialize_helper(directory, @options) register_action(:INIT, method('init')) end |
Instance Attribute Details
#local_scripts_base_path ⇒ String (readonly)
Returns Base path for scripts.
36 37 38 |
# File 'lib/OpenNebulaDriver.rb', line 36 def local_scripts_base_path @local_scripts_base_path end |
#local_scripts_path ⇒ String (readonly)
Returns Path for scripts.
38 39 40 |
# File 'lib/OpenNebulaDriver.rb', line 38 def local_scripts_path @local_scripts_path end |
#remote_scripts_base_path ⇒ String (readonly)
Returns Base path for scripts.
36 37 38 |
# File 'lib/OpenNebulaDriver.rb', line 36 def remote_scripts_base_path @remote_scripts_base_path end |
#remote_scripts_path ⇒ String (readonly)
Returns Path for scripts.
38 39 40 |
# File 'lib/OpenNebulaDriver.rb', line 38 def remote_scripts_path @remote_scripts_path end |
Class Method Details
.parse_actions_list(str) ⇒ Hash
This function parses a string with this form:
'deploy,shutdown,poll=poll_ganglia, cancel '
and returns a hash:
{"POLL"=>"poll_ganglia", "DEPLOY"=>nil, "SHUTDOWN"=>nil,
"CANCEL"=>nil}
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/OpenNebulaDriver.rb', line 162 def self.parse_actions_list(str) actions = {} str_splitted = str.split(/\s*,\s*/).map {|s| s.strip } str_splitted.each do |a| m=a.match(/([^=]+)(=(.*))?/) next unless m action=m[1].upcase if m[2] script=m[3] script.strip! if script else script=nil end actions[action]=script end actions end |
Instance Method Details
#do_action(parameters, id, host, aname, ops = {}) ⇒ Object
Calls remotes or local action checking the action name and
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/OpenNebulaDriver.rb', line 86 def do_action(parameters, id, host, aname, ops = {}) = { :stdin => nil, :script_name => nil, :respond => true, :ssh_stream => nil, :base64 => false, :zip => false, :no_extra_params => false }.merge(ops) params = parameters params = "#{params} #{id} #{host}" unless [:no_extra_params] command = action_command_line(aname, params, [:script_name]) # if options[:is_local] is not specified (nil) # we rely uniquely in actions_is_local? if action_is_local?(aname) or [:is_local] stdin = Base64.strict_encode64([:stdin].to_s) execution = LocalCommand.run(command, log_method(id), stdin, @timeout) elsif [:ssh_stream] if [:stdin] cmdin = "cat << 'EOT' | #{command}" stdin = "#{[:stdin]}\nEOT\n" else cmdin = command stdin = nil end execution = [:ssh_stream].run(cmdin, stdin, command, @timeout) else execution = RemotesCommand.run(command, host, @remote_scripts_base_path, log_method(id), [:stdin], @retries, @timeout) end result, info = get_info_from_execution(execution) if [:respond] info = Zlib::Deflate.deflate(info, Zlib::BEST_COMPRESSION) if [:zip] info = Base64.strict_encode64(info) if [:base64] (aname, result, id, info) end [result, info] end |
#start_driver ⇒ Object
Start the driver. Reads from STDIN and executes methods associated with the messages
146 147 148 149 |
# File 'lib/OpenNebulaDriver.rb', line 146 def start_driver Thread.new { loop } start_listener end |