aws 2.3.9 → 2.3.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -97,7 +97,7 @@ module Aws
97
97
  # * <tt>:port</tt>: CloudFront service port, default: DEFAULT_PORT
98
98
  # * <tt>:protocol</tt>: 'http' or 'https', default: DEFAULT_PROTOCOL
99
99
  # * <tt>:multi_thread</tt>: true=HTTP connection per thread, false=per process
100
- # * <tt>:logger</tt>: for log messages, default: RAILS_DEFAULT_LOGGER else STDOUT
100
+ # * <tt>:logger</tt>: for log messages, default: Rails.logger else STDOUT
101
101
  # * <tt>:cache</tt>: true/false: caching for list_distributions method, default: false.
102
102
  #
103
103
  # acf = Aws::AcfInterface.new('1E3GDYEOGFJPIT7XXXXXX','hgTHt68JY07JKUY08ftHYtERkjgtfERn57XXXXXX',
@@ -343,6 +343,7 @@ module Aws
343
343
  @params[:connection_mode] ||= :default
344
344
  @params[:connection_mode] = :per_request if @params[:connection_mode] == :default
345
345
  @logger = @params[:logger]
346
+ @logger = Rails.logger if !@logger && defined?(Rails) && defined?(Rails.logger)
346
347
  @logger = RAILS_DEFAULT_LOGGER if !@logger && defined?(RAILS_DEFAULT_LOGGER)
347
348
  @logger = Logger.new(STDOUT) if !@logger
348
349
  @logger.info "New #{self.class.name} using #{@params[:connection_mode].to_s}-connection mode"
@@ -106,7 +106,7 @@ module Aws
106
106
  # * <tt>:port</tt>: EC2 service port, default: DEFAULT_PORT
107
107
  # * <tt>:protocol</tt>: 'http' or 'https', default: DEFAULT_PROTOCOL
108
108
  # * <tt>:multi_thread</tt>: true=HTTP connection per thread, false=per process
109
- # * <tt>:logger</tt>: for log messages, default: RAILS_DEFAULT_LOGGER else STDOUT
109
+ # * <tt>:logger</tt>: for log messages, default: Rails.logger else STDOUT
110
110
  # * <tt>:signature_version</tt>: The signature version : '0' or '1'(default)
111
111
  # * <tt>:cache</tt>: true/false: caching for: ec2_describe_images, describe_instances,
112
112
  # describe_images_by_owner, describe_images_by_executable_by, describe_availability_zones,
@@ -433,6 +433,8 @@ module Aws
433
433
  request_info(link, QEc2ConfirmProductInstanceParser.new(:logger => @logger))
434
434
  end
435
435
 
436
+ # DEPRECATED, USE launch_instances instead.
437
+ #
436
438
  # Launch new EC2 instances. Returns a list of launched instances or an exception.
437
439
  #
438
440
  # ec2.run_instances('ami-e444444d',1,1,['my_awesome_group'],'my_awesome_key', 'Woohoo!!!', 'public') #=>
@@ -514,30 +516,34 @@ module Aws
514
516
  # :aws_availability_zone => "us-east-1c"
515
517
  # }]
516
518
  #
517
- def launch_instances(image_id, lparams={})
519
+ def launch_instances(image_id, options={})
518
520
  @logger.info("Launching instance of image #{image_id} for #{@aws_access_key_id}, " +
519
- "key: #{lparams[:key_name]}, groups: #{(lparams[:group_ids]).to_a.join(',')}")
521
+ "key: #{options[:key_name]}, groups: #{(options[:group_ids]).to_a.join(',')}")
520
522
  # careful: keyName and securityGroups may be nil
521
- params = hash_params('SecurityGroup', lparams[:group_ids].to_a)
523
+ params = hash_params('SecurityGroup', options[:group_ids].to_a)
522
524
  params.update( {'ImageId' => image_id,
523
- 'MinCount' => (lparams[:min_count] || 1).to_s,
524
- 'MaxCount' => (lparams[:max_count] || 1).to_s,
525
- 'AddressingType' => lparams[:addressing_type] || DEFAULT_ADDRESSING_TYPE,
526
- 'InstanceType' => lparams[:instance_type] || DEFAULT_INSTANCE_TYPE })
525
+ 'MinCount' => (options[:min_count] || 1).to_s,
526
+ 'MaxCount' => (options[:max_count] || 1).to_s,
527
+ 'AddressingType' => options[:addressing_type] || DEFAULT_ADDRESSING_TYPE,
528
+ 'InstanceType' => options[:instance_type] || DEFAULT_INSTANCE_TYPE })
527
529
  # optional params
528
- params['KeyName'] = lparams[:key_name] unless lparams[:key_name].blank?
529
- params['KernelId'] = lparams[:kernel_id] unless lparams[:kernel_id].blank?
530
- params['RamdiskId'] = lparams[:ramdisk_id] unless lparams[:ramdisk_id].blank?
531
- params['Placement.AvailabilityZone'] = lparams[:availability_zone] unless lparams[:availability_zone].blank?
532
- params['BlockDeviceMappings'] = lparams[:block_device_mappings] unless lparams[:block_device_mappings].blank?
533
- params['Monitoring.Enabled'] = lparams[:monitoring_enabled] unless lparams[:monitoring_enabled].blank?
534
- unless lparams[:user_data].blank?
535
- lparams[:user_data].strip!
530
+ params['KeyName'] = options[:key_name] unless options[:key_name].blank?
531
+ params['KernelId'] = options[:kernel_id] unless options[:kernel_id].blank?
532
+ params['RamdiskId'] = options[:ramdisk_id] unless options[:ramdisk_id].blank?
533
+ params['Placement.AvailabilityZone'] = options[:availability_zone] unless options[:availability_zone].blank?
534
+ params['BlockDeviceMappings'] = options[:block_device_mappings] unless options[:block_device_mappings].blank?
535
+ params['Monitoring.Enabled'] = options[:monitoring_enabled] unless options[:monitoring_enabled].blank?
536
+ params['SubnetId'] = options[:subnet_id] unless options[:subnet_id].blank?
537
+ params['AdditionalInfo'] = options[:additional_info] unless options[:additional_info].blank?
538
+ params['DisableApiTermination'] = options[:disable_api_termination].to_s unless options[:disable_api_termination].nil?
539
+ params['InstanceInitiatedShutdownBehavior'] = options[:instance_initiated_shutdown_behavior] unless options[:instance_initiated_shutdown_behavior].blank?
540
+ unless options[:user_data].blank?
541
+ options[:user_data].strip!
536
542
  # Do not use CGI::escape(encode64(...)) as it is done in Amazons EC2 library.
537
543
  # Amazon 169.254.169.254 does not like escaped symbols!
538
544
  # And it doesn't like "\n" inside of encoded string! Grrr....
539
545
  # Otherwise, some of UserData symbols will be lost...
540
- params['UserData'] = Base64.encode64(lparams[:user_data]).delete("\n").strip unless lparams[:user_data].blank?
546
+ params['UserData'] = Base64.encode64(options[:user_data]).delete("\n").strip unless options[:user_data].blank?
541
547
  end
542
548
  link = generate_request("RunInstances", params)
543
549
  #debugger
@@ -260,14 +260,35 @@ module Aws
260
260
  #
261
261
  def find(*args)
262
262
  options = args.last.is_a?(Hash) ? args.pop : {}
263
- # puts 'first=' + args.first.to_s
263
+ case args.first
264
+ when nil then
265
+ raise "Invalid parameters passed to find: nil."
266
+ when :all then
267
+ sql_select(options)[:items]
268
+ when :first then
269
+ sql_select(options.merge(:limit => 1))[:items].first
270
+ when :count then
271
+ res = sql_select(options.merge(:count => true))[:count]
272
+ res
273
+ else
274
+ res = select_from_ids(args, options)
275
+ return res[:single] if res[:single]
276
+ return res[:items]
277
+ end
278
+ end
279
+
280
+ #
281
+ # Same as find, but will return SimpleDB metadata like :request_id and :box_usage
282
+ #
283
+ def find_with_metadata(*args)
284
+ options = args.last.is_a?(Hash) ? args.pop : {}
264
285
  case args.first
265
286
  when nil then
266
287
  raise "Invalid parameters passed to find: nil."
267
288
  when :all then
268
289
  sql_select(options)
269
290
  when :first then
270
- sql_select(options.merge(:limit => 1)).first
291
+ sql_select(options.merge(:limit => 1))
271
292
  when :count then
272
293
  res = sql_select(options.merge(:count => true))
273
294
  res
@@ -349,24 +370,27 @@ module Aws
349
370
  options[:conditions] = build_conditions(options[:conditions])
350
371
  # join ids condition and user defined conditions
351
372
  options[:conditions] = options[:conditions].blank? ? ids_cond : "(#{options[:conditions]}) AND #{ids_cond}"
373
+ puts 'options=' + options.inspect
352
374
  result = sql_select(options)
375
+ puts 'select_from_ids result=' + result.inspect
353
376
  # if one record was requested then return it
354
377
  unless bunch_of_records_requested
355
- record = result.first
378
+ record = result[:items].first
356
379
  # railse if nothing was found
357
380
  raise ActiveSdbError.new("Couldn't find #{name} with ID #{args}") unless record
358
- record
381
+ result[:single] = record
359
382
  else
360
383
  # if a bunch of records was requested then return check that we found all of them
361
384
  # and return as an array
362
- unless args.size == result.size
385
+ unless args.size == result[:items].size
363
386
  # todo: might make sense to return the array but with nil values in the slots where an item wasn't found?
364
387
  id_list = args.map{|i| "'#{i}'"}.join(',')
365
- raise ActiveSdbError.new("Couldn't find all #{name} with IDs (#{id_list}) (found #{result.size} results, but was looking for #{args.size})")
388
+ raise ActiveSdbError.new("Couldn't find all #{name} with IDs (#{id_list}) (found #{result[:items].size} results, but was looking for #{args.size})")
366
389
  else
367
390
  result
368
391
  end
369
392
  end
393
+ result
370
394
  end
371
395
 
372
396
  def sql_select(options) # :nodoc:
@@ -376,19 +400,24 @@ module Aws
376
400
  select_expression = build_select(options)
377
401
  # request items
378
402
  query_result = self.connection.select(select_expression, @next_token)
379
- #puts 'QR=' + query_result.inspect
403
+ # puts 'QR=' + query_result.inspect
404
+ ret = {}
380
405
  if count
381
- return query_result[:items][0]["Domain"]["Count"][0].to_i
406
+ ret[:count] = query_result.delete(:items)[0]["Domain"]["Count"][0].to_i
407
+ ret.merge!(query_result)
408
+ return ret
382
409
  end
383
410
  @next_token = query_result[:next_token]
384
- items = query_result[:items].map do |hash|
411
+ items = query_result.delete(:items).map do |hash|
385
412
  id, attributes = hash.shift
386
413
  new_item = self.new( )
387
414
  new_item.initialize_from_db(attributes.merge({ 'id' => id }))
388
415
  new_item.mark_as_old
389
416
  new_item
390
417
  end
391
- items
418
+ ret[:items] = items
419
+ ret.merge!(query_result)
420
+ ret
392
421
  end
393
422
 
394
423
  # select_by helpers
@@ -121,7 +121,7 @@ class TestSdb < Test::Unit::TestCase
121
121
 
122
122
  def test_04b_find_all_dashed
123
123
  # retrieve all the DB, make sure all are in place
124
- clients = DashedClient.find(:all)
124
+ clients = DashClient.find(:all)
125
125
  ids = clients.map{|client| client.id }[0..1]
126
126
  assert_equal @clients.size + 1, clients.size
127
127
  # retrieve all presidents (must find: Bush, Putin, Medvedev)
@@ -156,11 +156,11 @@ class TestSdb < Test::Unit::TestCase
156
156
  # find any record
157
157
  assert Client.find(:first)
158
158
  # find any president
159
- assert Client.find(:first, :conditions => ["[?=?]",'post','president'])
159
+ assert Client.find(:first, :conditions => ["post=? and country=?",'president','Russia'])
160
160
  # find any rissian president
161
- assert Client.find(:first, :conditions => ["['post'=?] intersection ['country'=?]",'president','Russia'])
161
+ assert_nil Client.find(:first, :conditions => ["post=? and country=?",'president','Rwanda'])
162
162
  # find any unexistent record
163
- assert_nil Client.find(:first, :conditions => ["['post'=?] intersection ['country'=?]",'president','Rwanda'])
163
+ assert Client.find(:first, :conditions => ["?=?",'post','president'])
164
164
  end
165
165
 
166
166
  def test_06_find_all_by_helpers
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 2
8
8
  - 3
9
- - 9
10
- version: 2.3.9
9
+ - 12
10
+ version: 2.3.12
11
11
  platform: ruby
12
12
  authors:
13
13
  - Travis Reeder
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2010-06-04 00:00:00 -07:00
20
+ date: 2010-06-18 00:00:00 -07:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency