Class | BoxGrinder::AWSHelper |
In: |
lib/boxgrinder-build/helpers/aws-helper.rb
lib/boxgrinder-build/helpers/aws-helper.rb |
Parent: | Object |
Currently there is no API call for discovering S3 endpoint addresses but the base is presently the same as the EC2 endpoints, so this somewhat better than manually maintaining the data. S3 = /hd0-.*i386/, EBS = /hd00-.*i386/
# File lib/boxgrinder-build/helpers/aws-helper.rb, line 62 62: def endpoints(service_name, aki_pattern) 63: endpoints = {} 64: AWS.memoize do 65: @ec2.regions.each do |region| 66: endpoints.merge!({ 67: region.name => { 68: :endpoint => "#{service_name}.#{region.name}.amazonaws.com", 69: :location => region.name, #or alias? 70: :kernel => { 71: :i386 => select_aki(region, aki_pattern), 72: :x86_64 => select_aki(region, aki_pattern) 73: } 74: } 75: }) 76: end 77: end 78: end
Currently there is no API call for discovering S3 endpoint addresses but the base is presently the same as the EC2 endpoints, so this somewhat better than manually maintaining the data. S3 = /hd0-.*i386/, EBS = /hd00-.*i386/
# File lib/boxgrinder-build/helpers/aws-helper.rb, line 62 62: def endpoints(service_name, aki_pattern) 63: endpoints = {} 64: AWS.memoize do 65: @ec2.regions.each do |region| 66: endpoints.merge!({ 67: region.name => { 68: :endpoint => "#{service_name}.#{region.name}.amazonaws.com", 69: :location => region.name, #or alias? 70: :kernel => { 71: :i386 => select_aki(region, aki_pattern), 72: :x86_64 => select_aki(region, aki_pattern) 73: } 74: } 75: }) 76: end 77: end 78: end
Setting value of a key to nil in opts_defaults forces non-nil value of key in opts_in
# File lib/boxgrinder-build/helpers/aws-helper.rb, line 24 24: def parse_opts(opts_in, opts_defaults) 25: diff_id = opts_in.keys - opts_defaults.keys 26: raise ArgumentError, "Unrecognised argument(s): #{diff_id.join(", ")}" if diff_id.any? 27: 28: (opts_in.keys & opts_defaults.keys).each do |k| 29: raise ArgumentError, "Argument #{k.to_s} must not be nil" if opts_defaults[k] == nil and opts_in[k] == nil 30: end 31: 32: (opts_defaults.keys - opts_in.keys).each do |k| 33: raise ArgumentError, "Argument #{k.to_s} must not be nil" if opts_defaults[k] == nil 34: opts_in.merge!(k => opts_defaults[k]) 35: end 36: opts_in 37: end
Setting value of a key to nil in opts_defaults forces non-nil value of key in opts_in
# File lib/boxgrinder-build/helpers/aws-helper.rb, line 24 24: def parse_opts(opts_in, opts_defaults) 25: diff_id = opts_in.keys - opts_defaults.keys 26: raise ArgumentError, "Unrecognised argument(s): #{diff_id.join(", ")}" if diff_id.any? 27: 28: (opts_in.keys & opts_defaults.keys).each do |k| 29: raise ArgumentError, "Argument #{k.to_s} must not be nil" if opts_defaults[k] == nil and opts_in[k] == nil 30: end 31: 32: (opts_defaults.keys - opts_in.keys).each do |k| 33: raise ArgumentError, "Argument #{k.to_s} must not be nil" if opts_defaults[k] == nil 34: opts_in.merge!(k => opts_defaults[k]) 35: end 36: opts_in 37: end
# File lib/boxgrinder-build/helpers/aws-helper.rb, line 47 47: def select_aki(region, pattern) 48: candidates = region.images.with_owner('amazon'). 49: filter('manifest-location','*pv-grub*'). 50: sort(). 51: reverse 52: 53: candidates.each do |image| 54: return image.id if image.location =~ pattern 55: end 56: end
# File lib/boxgrinder-build/helpers/aws-helper.rb, line 47 47: def select_aki(region, pattern) 48: candidates = region.images.with_owner('amazon'). 49: filter('manifest-location','*pv-grub*'). 50: sort(). 51: reverse 52: 53: candidates.each do |image| 54: return image.id if image.location =~ pattern 55: end 56: end
# File lib/boxgrinder-build/helpers/aws-helper.rb, line 39 39: def wait_with_timeout(cycle_seconds, timeout_seconds) 40: Timeout::timeout(timeout_seconds) do 41: while not yield 42: sleep cycle_seconds 43: end 44: end 45: end