Class: BoxGrinder::AWSHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/boxgrinder-build/helpers/aws-helper.rb

Direct Known Subclasses

EC2Helper, S3Helper

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.block_device_mappings_validator(key, map, value) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/boxgrinder-build/helpers/aws-helper.rb', line 47

def self.block_device_mappings_validator(key, map, value)
  split_mappings = value.split('&') # /dev/xvdb=ephemeral0&/dev/xvdc=ephemeral1 

  split_mappings.each do |s_pair|
    name, blockdevice = s_pair.split('=') # /dev/xvdb=ephemeral0
    
    if name.nil? || blockdevice.nil? 
      raise PluginValidationError, 
      "Invalid device mapping: '#{s_pair}' in '#{split_mappings.join(', ')}'"
    else
      name.sub!(/xvd/, 'sd')
    end
    
    bd_keys = [:snapshot_id, :volume_size, :delete_on_termination]
    bd_values = blockdevice.split(':').map { |x| x.empty? ? nil : x }
    
    if bd_values.one? # '/dev/sdb' => 'ephemeral0'
      map.merge!(name => bd_values.first)
    else # '/dev/sdb' => { :snapshot_id => 'snap-123', ... }
      map.merge!(name => Hash[bd_keys.zip(bd_values)])
    end
  end
  map
end

Instance Method Details

#parse_opts(opts_in, opts_defaults) ⇒ Object

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

Raises:

  • (ArgumentError)


24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/boxgrinder-build/helpers/aws-helper.rb', line 24

def parse_opts(opts_in, opts_defaults)
  diff_id = opts_in.keys - opts_defaults.keys
  raise ArgumentError, "Unrecognised argument(s): #{diff_id.join(", ")}" if diff_id.any?

  (opts_in.keys & opts_defaults.keys).each do |k|
    raise ArgumentError, "Argument #{k.to_s} must not be nil" if opts_defaults[k] == nil and opts_in[k] == nil
  end

  (opts_defaults.keys - opts_in.keys).each do |k|
    raise ArgumentError, "Argument #{k.to_s} must not be nil" if opts_defaults[k] == nil
    opts_in.merge!(k => opts_defaults[k])
  end
  opts_in
end

#wait_with_timeout(cycle_seconds, timeout_seconds) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/boxgrinder-build/helpers/aws-helper.rb', line 39

def wait_with_timeout(cycle_seconds, timeout_seconds)
  Timeout::timeout(timeout_seconds) do
    while not yield
      sleep cycle_seconds
    end
  end
end