Module: Collins::Asset::Update

Included in:
Collins::Asset
Defined in:
lib/collins/asset_update.rb

Overview

Params we know about for updates, others come in via attribute hash

Constant Summary collapse

NON_ATTRIBUTE_PARAMS =
[
  "CHASSIS_TAG", "RACK_POSITION", /^POWER_(.*)_(.*)/i
]
FILE_PARAMS =
[
  "lshw", "lldp"
]
ALL_PARAMS =
NON_ATTRIBUTE_PARAMS + FILE_PARAMS

Class Method Summary collapse

Class Method Details

.get_param(key) ⇒ Object

get_param_value



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/collins/asset_update.rb', line 38

def get_param key
  to_a.each do |k|
    if k.is_a?(Regexp) && !k.match(key).nil? then
      # Assume it's a power setting until we have >1 regexp
      return key.upcase
    elsif key.to_s.downcase == k.to_s.downcase then
      return k
    end
  end
  return key
end

.get_param_value(key, value) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/collins/asset_update.rb', line 20

def get_param_value key, value
  if is_file_param?(key) then
    if value.start_with?('@') then
      filename = File.expand_path(value[1..-1])
      if !File.readable?(filename) then
        msg = "Could not read file '#{filename}' for key '#{key}'"
        raise ::Collins::ExpectationFailedError.new msg
      else
        File.read(filename)
      end
    else
      value
    end
  else
    value
  end
end

.is_attribute?(key) ⇒ Boolean

is_file_param?

Returns:

  • (Boolean)


54
55
56
57
58
59
60
61
62
63
# File 'lib/collins/asset_update.rb', line 54

def is_attribute? key
  to_a.each do |k|
    if k.is_a?(Regexp) && !k.match(key).nil? then
      return false
    elsif key.to_s.downcase == k.to_s.downcase then
      return false
    end
  end
  return true
end

.is_file_param?(key) ⇒ Boolean

get_param

Returns:

  • (Boolean)


50
51
52
# File 'lib/collins/asset_update.rb', line 50

def is_file_param? key
  FILE_PARAMS.map{|k|k.to_s.downcase}.include?(key.to_s.downcase)
end

.to_aObject



16
17
18
# File 'lib/collins/asset_update.rb', line 16

def to_a
  Collins::Asset::Update::ALL_PARAMS
end