Method: Fog::Compute::IBM::Mock#create_instance

Defined in:
lib/fog/ibm/requests/compute/create_instance.rb

#create_instance(name, image_id, instance_type, location, options = {}) ⇒ Object

[View source]

60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/fog/ibm/requests/compute/create_instance.rb', line 60

def create_instance(name, image_id, instance_type, location, options={})
  response = Excon::Response.new
  # Since we want to test error conditions, we have a little regex that traps specially formed
  # instance type strings.
  case name
  when /FAIL:\ (\d{3})/
    response.status = $1.to_i
    raise Excon::Errors.status_error({:expects => 200}, response)
  else
    instance = Fog::IBM::Mock.create_instance(name, image_id, instance_type, location, options)
    self.data[:instances][instance['id']] = instance
    response.status = 200
    response.body = {"instances" => [ instance ]}
    response
  end
end