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
instance_action(driver, action, credentials, id) click to toggle source

Some drivers, like RHEV-M does not return the instance object but just notify client that the action was executed successfully.

If we not received an Instance object, then we need to do additional query.

# File lib/ec2/query_parser.rb, line 73
def instance_action(driver, action, credentials, id)
  instance = driver.send(action, credentials, id)
  if instance.kind_of? Instance
    instance
  else
    driver.instance(credentials, :id => id)
  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 instance_action(driver, deltacloud_method, credentials, deltacloud_method_params.delete(:id))
    when :start_instance then instance_action(driver, 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 82
def to_xml(context)
  ResultParser.parse(action, @result, context)
end