Method: Chef::Node.from_hash

Defined in:
lib/chef/node.rb

.from_hash(o) ⇒ Object



580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
# File 'lib/chef/node.rb', line 580

def self.from_hash(o)
  return o if o.is_a? Chef::Node

  node = new
  node.name(o["name"])

  node.policy_name = o["policy_name"] if o.key?("policy_name")
  node.policy_group = o["policy_group"] if o.key?("policy_group")

  unless node.policy_group.nil?
    node.chef_environment(o["policy_group"])
  else
    node.chef_environment(o["chef_environment"])
  end

  if o.key?("attributes")
    node.normal_attrs = o["attributes"]
  end
  node.automatic_attrs = Mash.new(o["automatic"]) if o.key?("automatic")
  node.normal_attrs = Mash.new(o["normal"]) if o.key?("normal")
  node.default_attrs = Mash.new(o["default"]) if o.key?("default")
  node.override_attrs = Mash.new(o["override"]) if o.key?("override")

  if o.key?("run_list")
    node.run_list.reset!(o["run_list"])
  elsif o.key?("recipes")
    o["recipes"].each { |r| node.recipes << r }
  end

  node
end