class Deltacloud::EC2::ActionHandler

Constants

MAPPINGS

Attributes

action[R]

Public Class Methods

mappings() click to toggle source
# File lib/ec2/query_parser.rb, line 34
def self.mappings
  MAPPINGS
end
new(action) click to toggle source
# File lib/ec2/query_parser.rb, line 40
def initialize(action)
  @action = action
end

Public Instance Methods

deltacloud_method() click to toggle source
# File lib/ec2/query_parser.rb, line 44
def deltacloud_method
  self.class.mappings[action.action][:method]
end
deltacloud_method_params() click to toggle source
# File lib/ec2/query_parser.rb, line 48
def deltacloud_method_params
  parameters = action.parameters.dup
  self.class.mappings[action.action][:params].inject({}) do |result, p|
    result[p.last] = parameters.delete(p.first)
    result.delete_if { |k,v| v.nil? }
  end
end
perform!(credentials, driver) click to toggle source
# File lib/ec2/query_parser.rb, line 56
def perform!(credentials, driver)
  @result = case deltacloud_method
    when :create_instance then driver.send(deltacloud_method, credentials, deltacloud_method_params.delete(:image_id), deltacloud_method_params)
    when :stop_instance then driver.send(deltacloud_method, credentials, deltacloud_method_params.delete(:id))
    when :start_instance then driver.send(deltacloud_method, credentials, deltacloud_method_params.delete(:id))
    when :destroy_instance then driver.send(deltacloud_method, credentials, deltacloud_method_params.delete(:id))
    when :reboot_instance then driver.send(deltacloud_method, credentials, deltacloud_method_params.delete(:id))
    else driver.send(deltacloud_method, credentials, deltacloud_method_params)
  end
end
to_xml(context) click to toggle source
# File lib/ec2/query_parser.rb, line 67
def to_xml(context)
  ResultParser.parse(action, @result, context)
end