# File lib/base_object.rb, line 322 def action_objects @objects.select { |o| o[:type] == :action_link } end
# File lib/base_object.rb, line 270 def action_trigger(action) # Refresh object state after action unless the object was destroyed return if action.to_s == "destroy" @new_state_object = @client.send(self.base_name, self.id) @state = @new_state_object.state self.update_actions! end
# File lib/base_object.rb, line 247 def add_default_states! @objects << { :method_name => 'stopped?', :type => :state, :state => 'STOPPED' } @objects << { :method_name => 'running?', :type => :state, :state => 'RUNNING' } @objects << { :method_name => 'pending?', :type => :state, :state => 'PENDING' } @objects << { :method_name => 'shutting_down?', :type => :state, :state => 'SHUTTING_DOWN' } end
# File lib/base_object.rb, line 278 def add_run_action!(id, link) @objects << { :method_name => 'run', :type => :run, :url => link, } end
# File lib/base_object.rb, line 318 def evaluate_state(method_state, current_state) method_state.eql?(current_state) end
# File lib/base_object.rb, line 288 def method_handler(m, args=[]) begin action_method_handler(m, args) rescue NoHandlerForMethod case m[:type] when :state then evaluate_state(m[:state], @state) when :run then run_command(m[:url][:href], args) else raise NoHandlerForMethod end end end
private
# File lib/base_object.rb, line 302 def run_command(instance_url, args) credentials = args[1] params = { :cmd => args[0], :private_key => credentials[:pem] ? File.read(credentials[:pem]) : nil, } params.merge!({ :username => credentials[:username], :password => credentials[:password] }) if credentials[:username] and credentials[:password] @client.request(:post, instance_url, {}, params) do |response| output = Nokogiri::XML(response) (output/'/instance/output').first.text end end
Generated with the Darkfish Rdoc Generator 2.