Class BoxGrinder::AWSHelper
In: lib/boxgrinder-build/helpers/aws-helper.rb
lib/boxgrinder-build/helpers/aws-helper.rb
Parent: Object

Methods

Public Class methods

[Source]

    # File lib/boxgrinder-build/helpers/aws-helper.rb, line 47
47:     def self.block_device_mappings_validator(key, map, value)
48:       split_mappings = value.split('&') # /dev/xvdb=ephemeral0&/dev/xvdc=ephemeral1 
49: 
50:       split_mappings.each do |s_pair|
51:         name, blockdevice = s_pair.split('=') # /dev/xvdb=ephemeral0
52:         
53:         if name.nil? || blockdevice.nil? 
54:           raise PluginValidationError, 
55:           "Invalid device mapping: '#{s_pair}' in '#{split_mappings.join(', ')}'"
56:         else
57:           name.sub!(/xvd/, 'sd')
58:         end
59:         
60:         bd_keys = [:snapshot_id, :volume_size, :delete_on_termination]
61:         bd_values = blockdevice.split(':').map { |x| x.empty? ? nil : x }
62:         
63:         if bd_values.one? # '/dev/sdb' => 'ephemeral0'
64:           map.merge!(name => bd_values.first)
65:         else # '/dev/sdb' => { :snapshot_id => 'snap-123', ... }
66:           map.merge!(name => Hash[bd_keys.zip(bd_values)])
67:         end
68:       end
69:       map
70:     end

[Source]

    # File lib/boxgrinder-build/helpers/aws-helper.rb, line 47
47:     def self.block_device_mappings_validator(key, map, value)
48:       split_mappings = value.split('&') # /dev/xvdb=ephemeral0&/dev/xvdc=ephemeral1 
49: 
50:       split_mappings.each do |s_pair|
51:         name, blockdevice = s_pair.split('=') # /dev/xvdb=ephemeral0
52:         
53:         if name.nil? || blockdevice.nil? 
54:           raise PluginValidationError, 
55:           "Invalid device mapping: '#{s_pair}' in '#{split_mappings.join(', ')}'"
56:         else
57:           name.sub!(/xvd/, 'sd')
58:         end
59:         
60:         bd_keys = [:snapshot_id, :volume_size, :delete_on_termination]
61:         bd_values = blockdevice.split(':').map { |x| x.empty? ? nil : x }
62:         
63:         if bd_values.one? # '/dev/sdb' => 'ephemeral0'
64:           map.merge!(name => bd_values.first)
65:         else # '/dev/sdb' => { :snapshot_id => 'snap-123', ... }
66:           map.merge!(name => Hash[bd_keys.zip(bd_values)])
67:         end
68:       end
69:       map
70:     end

Public Instance methods

Setting value of a key to nil in opts_defaults forces non-nil value of key in opts_in

[Source]

    # 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

[Source]

    # 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

[Source]

    # 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

[Source]

    # 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

[Validate]