Class: Scalr::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/scalr/request.rb

Defined Under Namespace

Classes: InvalidInputError, ScalrError

Constant Summary collapse

ACTIONS =
{
  :bundle_task_get_status => {:name => 'BundleTaskGetStatus', :inputs => {:bundle_task_id => true}},
  :dns_zone_create => {:name => 'DNSZoneCreate', :inputs => {:domain_name => true, :farm_id => false, :farm_role_id => false}},
  :dns_zone_record_add => {:name => 'DNSZoneRecordAdd', :inputs => {:zone_name => true, :type => true, :ttl => true, :name => true, :value => true, :priority => false, :weight => false, :port => false}},
  :dns_zone_record_remove => {:name => 'DNSZoneRecordRemove', :inputs => {:zone_name => true, :record_id => true}},
  :dns_zone_records_list => {:name => 'DNSZoneRecordsList', :inputs => {:zone_name => true}},
  :dns_zones_list => {:name => 'DNSZonesList', :inputs => {}},
  :events_list => {:name => 'EventsList', :inputs => {:farm_id => true, :start_from => false, :records_limit => false}},
  :farm_get_details => {:name => 'FarmGetDetails', :inputs => {:farm_id => true}},
  :farm_get_stats => {:name => 'FarmGetStats', :inputs => {:farm_id => true, :date => false}},
  :farms_list => {:name => 'FarmsList', :inputs => {}},
  :farm_terminate => {:name => 'FarmTerminate', :inputs => {:farm_id => true, :keep_ebs => true, :keep_eip => false, :keep_dns_zone => false}},
  :farm_launch => {:name => 'FarmLaunch', :inputs => {:farm_id => true}},
  :logs_list => {:name => 'LogsList', :inputs => {:farm_id => true, :server_id => true, :start_from => false, :records_limit => false}},
  :roles_list => {:name => 'RolesList', :inputs => {:platform => false, :name => false, :prefix => false, :image_id => false}},
  :script_execute => {:name => 'ScriptExecute', :inputs => {:farm_role_id => false, :server_id => false, :farm_id => true, :script_id => true, :timeout => true, :async => true, :revision => false, :config_variables => false}},
  :script_get_details => {:name => 'ScriptGetDetails', :inputs => {:script_id => true}},
  :scripts_list => {:name => 'ScriptsList', :inputs => {}},
  :server_image_create => {:name => 'ServerImageCreate', :inputs => {:server_id => true, :role_name => true}},
  :server_launch => {:name => 'ServerLaunch', :inputs => {:farm_role_id => true}},
  :server_reboot => {:name => 'ServerReboot', :inputs => {:server_id => true}},
  :server_terminate => {:name => 'ServerTerminate', :inputs => {:server_id => true, :decrease_min_instances_setting => false}},
  :statistics_get_graph_url => {:name => 'StatisticsGetGraphURL', :inputs => {:object_type => true, :object_id => true, :watcher_name => true, :graph_type => true}}
}
INPUTS =
{
  :async => 'Async',
  :bundle_task_id => 'BundleTaskID',
  :config_variables => 'ConfigVariables',
  :date => 'Date',
  :decrease_min_instances_setting => 'DecreaseMinInstancesSetting',
  :domain_name => 'DomainName',
  :farm_id => 'FarmID',
  :farm_role_id => 'FarmRoleID',
  :graph_type => 'GraphType',
  :image_id => 'ImageID',
  :keep_dns_zone => 'KeepDNSZone',
  :keep_ebs => 'KeepEBS',
  :keep_eip => 'KeepEIP',
  :key => 'Key',
  :name => 'Name',
  :object_id => 'ObjectID',
  :object_type => 'ObjectType',
  :platform => 'Platform',
  :port => 'Port',
  :prefix => 'Prefix',
  :priority => 'Priority',
  :record_id => 'RecordID',
  :records_limit => 'RecordsLimit',
  :revision => 'Revision',
  :role_name => 'RoleName',
  :script_id => 'ScriptID',
  :server_id => 'ServerID',
  :start_from => 'StartFrom',
  :timeout => 'Timeout',
  :ttl => 'TTL',
  :type => 'Type',
  :value => 'Value',
  :watcher_name => 'WatcherName',
  :weight => 'Weight',
  :zone_name => 'ZoneName'      
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(action, endpoint, key_id, access_key, version, *arguments) ⇒ Request

Returns a new instance of Request.



78
79
80
81
82
83
# File 'lib/scalr/request.rb', line 78

def initialize(action, endpoint, key_id, access_key, version, *arguments)
  set_inputs(action, arguments.flatten.first)
  @inputs.merge!('Action' => ACTIONS[action.to_sym][:name], 'KeyID' => key_id, 'Version' => version, 'Timestamp' => Time.now.utc.iso8601)
  @endpoint = endpoint
  @access_key = access_key
end

Instance Attribute Details

#access_keyObject

Returns the value of attribute access_key.



76
77
78
# File 'lib/scalr/request.rb', line 76

def access_key
  @access_key
end

#endpointObject

Returns the value of attribute endpoint.



76
77
78
# File 'lib/scalr/request.rb', line 76

def endpoint
  @endpoint
end

#inputsObject

Returns the value of attribute inputs.



76
77
78
# File 'lib/scalr/request.rb', line 76

def inputs
  @inputs
end

#signatureObject

Returns the value of attribute signature.



76
77
78
# File 'lib/scalr/request.rb', line 76

def signature
  @signature
end

Instance Method Details

#process!Object



85
86
87
88
89
90
91
# File 'lib/scalr/request.rb', line 85

def process!
  set_signature!
  http = Net::HTTP.new(@endpoint, 443)
  http.use_ssl = true
  response, data = http.get("/?" + query_string + "&Signature=#{@signature}", nil)
  return Scalr::Response.new(response, data)
end