Class: Toaster::ChefNodeInspector

Inherits:
Object
  • Object
show all
Defined in:
lib/toaster/chef/chef_node_inspector.rb

Constant Summary collapse

@@DEFAULT_PROCESSOR_CLASS =
Toaster::DefaultProcessorRecursive

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(chef_paths = [ChefUtil.DEFAULT_OPSCODE_TMP_DIR, ChefUtil.DEFAULT_COOKBOOKS_DIR], processor = nil, &error_reporting) ⇒ ChefNodeInspector

  • chef_paths - Chef dirs on local filesystem



113
114
115
116
117
118
119
120
# File 'lib/toaster/chef/chef_node_inspector.rb', line 113

def initialize(chef_paths = [ChefUtil.DEFAULT_OPSCODE_TMP_DIR,
  ChefUtil.DEFAULT_COOKBOOKS_DIR], processor = nil, &error_reporting)
  @chef_paths = chef_paths
  @processor = processor
  raise "Invalid 'error_reporting'" if error_reporting.nil?
  @error_reporting = error_reporting
  @keyfile = nil
end

Instance Attribute Details

#keyfile=(value) ⇒ Object (writeonly)

Sets the attribute keyfile



103
104
105
# File 'lib/toaster/chef/chef_node_inspector.rb', line 103

def keyfile=(value)
  @keyfile = value
end

Instance Method Details

#get_cookbooks(recipes) ⇒ Object



148
149
150
# File 'lib/toaster/chef/chef_node_inspector.rb', line 148

def get_cookbooks(recipes)
  return recipes.map { |qualified_recipe| qualified_recipe[RECIPE_REGEXP, 1] }.uniq
end

#get_defaults(cookbook_name, recipe_name = "default") ⇒ Object

scrape the default param files and return recipe -> param -> default



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/toaster/chef/chef_node_inspector.rb', line 123

def get_defaults(cookbook_name, recipe_name="default")
  if cookbook_name.nil?
    @error_reporting.call(Logger::WARN, "Unknown cookbook #{cookbook_name.inspect}")
    return {}
  end
  
  file_name = cookbook_name + "/attributes/#{recipe_name}.rb"
  default_file = get_filename(file_name)

  if default_file.nil?
    @error_reporting.call(Logger::INFO, "Unknown attribute file '#{file_name.inspect}'")
    return {}
  end
  
  default_processor = @processor.nil? ? DefaultProcessorRecursive.new() : @processor
  begin
    default_processor.instance_eval(File.new(default_file).read(), default_file)
  rescue NoMethodError => e
    @error_reporting.call(Logger::WARN, "#{e.to_s}\n#{e.backtrace.join("\n")}")
    return {}
  end
  
  return default_processor.default()
end