Class: Chef::Node

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
DSL::IncludeAttribute, DSL::PlatformIntrospection, Mixin::FromFile, Mixin::ParamsValidate
Defined in:
lib/chef/node.rb,
lib/chef/node/attribute.rb,
lib/chef/node/immutable_collections.rb,
lib/chef/node/attribute_collections.rb

Defined Under Namespace

Modules: Immutablize Classes: AttrArray, Attribute, ImmutableArray, ImmutableMash, MultiMash, VividMash

Constant Summary

NULL_ARG =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Mixin::ParamsValidate

#lazy, #set_or_return, #validate

Methods included from DSL::PlatformIntrospection

#platform?, #platform_family?, #value_for_platform, #value_for_platform_family

Methods included from DSL::IncludeAttribute

#include_attribute, #parse_attribute_file_spec

Methods included from Mixin::FromFile

#class_from_file, #from_file

Constructor Details

#initialize(chef_server_rest: nil) ⇒ Node

Create a new Chef::Node object.



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/chef/node.rb', line 69

def initialize(chef_server_rest: nil)
  @chef_server_rest = chef_server_rest
  @name = nil

  @chef_environment = '_default'
  @primary_runlist = Chef::RunList.new
  @override_runlist = Chef::RunList.new

  @policy_name = nil
  @policy_group = nil

  @attributes = Chef::Node::Attribute.new({}, {}, {}, {})

  @run_state = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, *args) ⇒ Object

Only works for attribute fetches, setting is no longer supported



294
295
296
# File 'lib/chef/node.rb', line 294

def method_missing(symbol, *args)
  attributes.send(symbol, *args)
end

Instance Attribute Details

#chef_server_restObject

Returns the value of attribute chef_server_rest



50
51
52
# File 'lib/chef/node.rb', line 50

def chef_server_rest
  @chef_server_rest
end

#override_runlist(*args) ⇒ Object

Returns the value of attribute override_runlist



48
49
50
# File 'lib/chef/node.rb', line 48

def override_runlist
  @override_runlist
end

#recipe_listObject

Returns the value of attribute recipe_list



48
49
50
# File 'lib/chef/node.rb', line 48

def recipe_list
  @recipe_list
end

#run_contextObject

RunContext will set itself as run_context via this setter when initialized. This is needed so DSL::IncludeAttribute (in particular, #include_recipe) can access the run_context to determine if an attributes file has been seen yet. – TODO: This is a pretty ugly way to solve that problem.



58
59
60
# File 'lib/chef/node.rb', line 58

def run_context
  @run_context
end

#run_stateObject

Returns the value of attribute run_state



48
49
50
# File 'lib/chef/node.rb', line 48

def run_state
  @run_state
end

Class Method Details

.build(node_name) ⇒ Object



589
590
591
592
593
594
# File 'lib/chef/node.rb', line 589

def self.build(node_name)
  node = new
  node.name(node_name)
  node.chef_environment(Chef::Config[:environment]) unless Chef::Config[:environment].nil? || Chef::Config[:environment].chomp.empty?
  node
end

.find_or_create(node_name) ⇒ Object



581
582
583
584
585
586
587
# File 'lib/chef/node.rb', line 581

def self.find_or_create(node_name)
  load(node_name)
rescue Net::HTTPServerException => e
  raise unless e.response.code == '404'
  node = build(node_name)
  node.create
end

.json_create(o) ⇒ Object

Create a Chef::Node from JSON



535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
# File 'lib/chef/node.rb', line 535

def self.json_create(o)
  node = new
  node.name(o["name"])
  node.chef_environment(o["chef_environment"])
  if o.has_key?("attributes")
    node.normal_attrs = o["attributes"]
  end
  node.automatic_attrs = Mash.new(o["automatic"]) if o.has_key?("automatic")
  node.normal_attrs = Mash.new(o["normal"]) if o.has_key?("normal")
  node.default_attrs = Mash.new(o["default"]) if o.has_key?("default")
  node.override_attrs = Mash.new(o["override"]) if o.has_key?("override")

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

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

  node
end

.list(inflate = false) ⇒ Object



569
570
571
572
573
574
575
576
577
578
579
# File 'lib/chef/node.rb', line 569

def self.list(inflate=false)
  if inflate
    response = Hash.new
    Chef::Search::Query.new.search(:node) do |n|
      response[n.name] = n unless n.nil?
    end
    response
  else
    Chef::REST.new(Chef::Config[:chef_server_url]).get_rest("nodes")
  end
end

.list_by_environment(environment, inflate = false) ⇒ Object



559
560
561
562
563
564
565
566
567
# File 'lib/chef/node.rb', line 559

def self.list_by_environment(environment, inflate=false)
  if inflate
    response = Hash.new
    Chef::Search::Query.new.search(:node, "chef_environment:#{environment}") {|n| response[n.name] = n unless n.nil?}
    response
  else
    Chef::REST.new(Chef::Config[:chef_server_url]).get_rest("environments/#{environment}/nodes")
  end
end

.load(name) ⇒ Object

Load a node by name



597
598
599
# File 'lib/chef/node.rb', line 597

def self.load(name)
  Chef::REST.new(Chef::Config[:chef_server_url]).get_rest("nodes/#{name}")
end

Instance Method Details

#<=>(other_node) ⇒ Object



658
659
660
# File 'lib/chef/node.rb', line 658

def <=>(other_node)
  self.name <=> other_node.name
end

#==(other) ⇒ Object



650
651
652
653
654
655
656
# File 'lib/chef/node.rb', line 650

def ==(other)
  if other.kind_of?(self.class)
     self.name == other.name
  else
    false
  end
end

#[](attrib) ⇒ Object

Return an attribute of this node. Returns nil if the attribute is not found.



192
193
194
# File 'lib/chef/node.rb', line 192

def [](attrib)
  attributes[attrib]
end

#apply_expansion_attributes(expansion) ⇒ Object

Apply the default and overrides attributes from the expansion passed in, which came from roles.



454
455
456
457
458
459
460
461
462
463
464
465
466
# File 'lib/chef/node.rb', line 454

def apply_expansion_attributes(expansion)
  loaded_environment = if chef_environment == "_default"
                         Chef::Environment.new.tap {|e| e.name("_default")}
                       else
                         Chef::Environment.load(chef_environment)
                       end

  attributes.env_default = loaded_environment.default_attributes
  attributes.env_override = loaded_environment.override_attributes

  attribute.role_default = expansion.default_attrs
  attributes.role_override = expansion.override_attrs
end

#attribute?(attrib) ⇒ Boolean

Return true if this Node has a given attribute, false if not. Takes either a symbol or a string.

Only works on the top level. Preferred way is to use the normal [] style lookup and call attribute?()

Returns:

  • (Boolean)


279
280
281
# File 'lib/chef/node.rb', line 279

def attribute?(attrib)
  attributes.attribute?(attrib)
end

#attributesObject Also known as: attribute, construct_attributes



184
185
186
# File 'lib/chef/node.rb', line 184

def attributes
  @attributes
end

#automatic_attrsObject



264
265
266
267
268
# File 'lib/chef/node.rb', line 264

def automatic_attrs
  attributes.top_level_breadcrumb = nil
  attributes.set_unless_value_present = false
  attributes.automatic
end

#automatic_attrs=(new_values) ⇒ Object



270
271
272
# File 'lib/chef/node.rb', line 270

def automatic_attrs=(new_values)
  attributes.automatic = new_values
end

#chef_environment(arg = nil) ⇒ Object Also known as: environment



126
127
128
129
130
131
132
# File 'lib/chef/node.rb', line 126

def chef_environment(arg=nil)
  set_or_return(
    :chef_environment,
    arg,
    { :regex => /^[\-[:alnum:]_]+$/, :kind_of => String }
  )
end

#chef_environment=(environment) ⇒ Object



134
135
136
# File 'lib/chef/node.rb', line 134

def chef_environment=(environment)
  chef_environment(environment)
end

#consume_attributes(attrs) ⇒ Object

Consumes the combined run_list and other attributes in attrs



365
366
367
368
369
370
371
# File 'lib/chef/node.rb', line 365

def consume_attributes(attrs)
  normal_attrs_to_merge = consume_run_list(attrs)
  normal_attrs_to_merge = consume_chef_environment(normal_attrs_to_merge)
  Chef::Log.debug("Applying attributes from json file")
  self.normal_attrs = Chef::Mixin::DeepMerge.merge(normal_attrs,normal_attrs_to_merge)
  self.tags # make sure they're defined
end

#consume_chef_environment(attrs) ⇒ Object

chef_environment when set in -j JSON will take precedence over -E ENVIRONMENT. Ideally, IMO, the order of precedence should be (lowest to

highest):
 config_file
 -j JSON
 -E ENVIRONMENT

so that users could reuse their JSON and override the chef_environment configured within it with -E ENVIRONMENT. Because command line options are merged with Chef::Config there is currently no way to distinguish between an environment set via config from an environment set via command line.



410
411
412
413
414
415
416
# File 'lib/chef/node.rb', line 410

def consume_chef_environment(attrs)
  attrs = attrs ? attrs.dup : {}
  if env = attrs.delete("chef_environment")
    chef_environment(env)
  end
  attrs
end

#consume_external_attrs(ohai_data, json_cli_attrs) ⇒ Object

Consume data from ohai and Attributes provided as JSON on the command line.



352
353
354
355
356
357
358
359
360
361
362
# File 'lib/chef/node.rb', line 352

def consume_external_attrs(ohai_data, json_cli_attrs)
  Chef::Log.debug("Extracting run list from JSON attributes provided on command line")
  consume_attributes(json_cli_attrs)

  self.automatic_attrs = ohai_data

  platform, version = Chef::Platform.find_platform_and_version(self)
  Chef::Log.debug("Platform is #{platform} version #{version}")
  self.automatic[:platform] = platform
  self.automatic[:platform_version] = version
end

#consume_run_list(attrs) ⇒ Object

Extracts the run list from attrs and applies it. Returns the remaining attributes



388
389
390
391
392
393
394
395
396
397
398
# File 'lib/chef/node.rb', line 388

def consume_run_list(attrs)
  attrs = attrs ? attrs.dup : {}
  if new_run_list = attrs.delete("recipes") || attrs.delete("run_list")
    if attrs.key?("recipes") || attrs.key?("run_list")
      raise Chef::Exceptions::AmbiguousRunlistSpecification, "please set the node's run list using the 'run_list' attribute only."
    end
    Chef::Log.info("Setting the run_list to #{new_run_list.to_s} from CLI options")
    run_list(new_run_list)
  end
  attrs
end

#createObject

Create the node via the REST API



632
633
634
635
636
637
638
639
640
641
642
643
644
# File 'lib/chef/node.rb', line 632

def create
  chef_server_rest.post_rest("nodes", data_for_save)
  self
rescue Net::HTTPServerException => e
  # Chef Server before 12.3 rejects node JSON with 'policy_name' or
  # 'policy_group' keys, but 'policy_name' will be detected first.
  # Backcompat can be removed in 13.0
  if e.response.code == "400" && e.response.body.include?("Invalid key policy_name")
    chef_server_rest.post_rest("nodes", data_for_save_without_policyfile_attrs)
  else
    raise
  end
end

#defaultObject Also known as: default_attrs

Set a default of this node, but auto-vivify any Mashes that might be missing



218
219
220
221
222
# File 'lib/chef/node.rb', line 218

def default
  attributes.top_level_breadcrumb = nil
  attributes.set_unless_value_present = false
  attributes.default
end

#default_attrs=(new_values) ⇒ Object



256
257
258
# File 'lib/chef/node.rb', line 256

def default_attrs=(new_values)
  attributes.default = new_values
end

#default_unlessObject

Set a default attribute of this node, auto-vivifying any mashes that are missing, but if the final value already exists, don't set it



226
227
228
229
230
# File 'lib/chef/node.rb', line 226

def default_unless
  attributes.top_level_breadcrumb = nil
  attributes.set_unless_value_present = true
  attributes.default
end

#destroyObject

Remove this node via the REST API



602
603
604
# File 'lib/chef/node.rb', line 602

def destroy
  chef_server_rest.delete_rest("nodes/#{name}")
end

#display_hashObject



483
484
485
486
487
488
489
490
491
492
493
# File 'lib/chef/node.rb', line 483

def display_hash
  display = {}
  display["name"]             = name
  display["chef_environment"] = chef_environment
  display["automatic"]        = automatic_attrs
  display["normal"]           = normal_attrs
  display["default"]          = attributes.combined_default
  display["override"]         = attributes.combined_override
  display["run_list"]         = run_list.run_list_items
  display
end

#each(&block) ⇒ Object

Yield each key of the top level to the block.



284
285
286
# File 'lib/chef/node.rb', line 284

def each(&block)
  attributes.each(&block)
end

#each_attribute(&block) ⇒ Object

Iterates over each attribute, passing the attribute and value to the block.



289
290
291
# File 'lib/chef/node.rb', line 289

def each_attribute(&block)
  attributes.each_attribute(&block)
end

#expand!(data_source = 'server') ⇒ Object

Expands the node's run list and sets the default and override attributes. Also applies stored attributes (from json provided on the command line)

Returns the fully-expanded list of recipes, a RunListExpansion.

– TODO: timh/cw, 5-14-2010: Should this method exist? Should we instead modify default_attrs and override_attrs whenever our run_list is mutated? Or perhaps do something smarter like on-demand generation of default_attrs and override_attrs, invalidated only when run_list is mutated?



437
438
439
440
441
442
443
444
445
446
447
448
449
450
# File 'lib/chef/node.rb', line 437

def expand!(data_source = 'server')
  expansion = run_list.expand(chef_environment, data_source)
  raise Chef::Exceptions::MissingRole, expansion if expansion.errors?

  self.tags # make sure they're defined

  automatic_attrs[:recipes] = expansion.recipes.with_duplicate_names
  automatic_attrs[:expanded_run_list] = expansion.recipes.with_fully_qualified_names_and_version_constraints
  automatic_attrs[:roles] = expansion.roles

  apply_expansion_attributes(expansion)

  expansion
end

#for_jsonObject



500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
# File 'lib/chef/node.rb', line 500

def for_json
  result = {
    "name" => name,
    "chef_environment" => chef_environment,
    'json_class' => self.class.name,
    "automatic" => attributes.automatic,
    "normal" => attributes.normal,
    "chef_type" => "node",
    "default" => attributes.combined_default,
    "override" => attributes.combined_override,
    #Render correctly for run_list items so malformed json does not result
    "run_list" => @primary_runlist.run_list.map { |item| item.to_s }
  }
  # Chef Server rejects node JSON with extra keys; prior to 12.3,
  # "policy_name" and "policy_group" are unknown; after 12.3 they are
  # optional, therefore only including them in the JSON if present
  # maximizes compatibility for most people.
  unless policy_group.nil? && policy_name.nil?
    result["policy_name"] = policy_name
    result["policy_group"] = policy_group
  end
  result
end

#loaded_recipe(cookbook, recipe) ⇒ Object

used by include_recipe to add recipes to the expanded run_list to be saved back to the node and be searchable



311
312
313
314
315
# File 'lib/chef/node.rb', line 311

def loaded_recipe(cookbook, recipe)
  fully_qualified_recipe = "#{cookbook}::#{recipe}"

  automatic_attrs[:recipes] << fully_qualified_recipe unless Array(self[:recipes]).include?(fully_qualified_recipe)
end

#name(arg = nil) ⇒ Object

Set the name of this Node, or return the current name.



112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/chef/node.rb', line 112

def name(arg=nil)
  if arg != nil
    validate(
             {:name => arg },
             {:name => { :kind_of => String,
                 :cannot_be => :blank,
                 :regex => /^[\-[:alnum:]_:.]+$/}
             })
    @name = arg
  else
    @name
  end
end

#nodeObject

Used by DSL



95
96
97
# File 'lib/chef/node.rb', line 95

def node
  self
end

#normalObject Also known as: set, normal_attrs

Set a normal attribute of this node, but auto-vivify any Mashes that might be missing



198
199
200
201
202
# File 'lib/chef/node.rb', line 198

def normal
  attributes.top_level_breadcrumb = nil
  attributes.set_unless_value_present = false
  attributes.normal
end

#normal_attrs=(new_values) ⇒ Object



260
261
262
# File 'lib/chef/node.rb', line 260

def normal_attrs=(new_values)
  attributes.normal = new_values
end

#normal_unlessObject Also known as: set_unless

Set a normal attribute of this node, auto-vivifying any mashes that are missing, but if the final value already exists, don't set it



208
209
210
211
212
# File 'lib/chef/node.rb', line 208

def normal_unless
  attributes.top_level_breadcrumb = nil
  attributes.set_unless_value_present = true
  attributes.normal
end

#overrideObject Also known as: override_attrs

Set an override attribute of this node, but auto-vivify any Mashes that might be missing



234
235
236
237
238
# File 'lib/chef/node.rb', line 234

def override
  attributes.top_level_breadcrumb = nil
  attributes.set_unless_value_present = false
  attributes.override
end

#override_attrs=(new_values) ⇒ Object



252
253
254
# File 'lib/chef/node.rb', line 252

def override_attrs=(new_values)
  attributes.override = new_values
end

#override_unlessObject

Set an override attribute of this node, auto-vivifying any mashes that are missing, but if the final value already exists, don't set it



242
243
244
245
246
# File 'lib/chef/node.rb', line 242

def override_unless
  attributes.top_level_breadcrumb = nil
  attributes.set_unless_value_present = true
  attributes.override
end

#policy_group(arg = NULL_ARG) ⇒ String

The `policy_group` for this node. Setting this to a non-nil value will enable policyfile mode when `chef-client` is run. If set in the config file or in node json, running `chef-client` will update this value.

Parameters:

  • arg (String) (defaults to: NULL_ARG)

    the new policy_group value

Returns:

  • (String)

    the current policy_group, or the one you just set

See Also:



171
172
173
174
175
# File 'lib/chef/node.rb', line 171

def policy_group(arg=NULL_ARG)
  return @policy_group if arg.equal?(NULL_ARG)
  validate({policy_group: arg}, { policy_group: { kind_of: [ String, NilClass ], regex: /^[\-:.[:alnum:]_]+$/ } })
  @policy_group = arg
end

#policy_group=(policy_group) ⇒ Object

A “non-DSL-style” setter for `policy_group`

See Also:



180
181
182
# File 'lib/chef/node.rb', line 180

def policy_group=(policy_group)
  policy_group(policy_group)
end

#policy_name(arg = NULL_ARG) ⇒ String

The `policy_name` for this node. Setting this to a non-nil value will enable policyfile mode when `chef-client` is run. If set in the config file or in node json, running `chef-client` will update this value.

Parameters:

  • arg (String) (defaults to: NULL_ARG)

    the new policy_name value

Returns:

  • (String)

    the current policy_name, or the one you just set

See Also:



149
150
151
152
153
# File 'lib/chef/node.rb', line 149

def policy_name(arg=NULL_ARG)
  return @policy_name if arg.equal?(NULL_ARG)
  validate({policy_name: arg}, { policy_name: { kind_of: [ String, NilClass ], regex: /^[\-:.[:alnum:]_]+$/ } })
  @policy_name = arg
end

#policy_name=(policy_name) ⇒ Object

A “non-DSL-style” setter for `policy_name`

See Also:



158
159
160
# File 'lib/chef/node.rb', line 158

def policy_name=(policy_name)
  policy_name(policy_name)
end

#primary_runlistObject



322
323
324
# File 'lib/chef/node.rb', line 322

def primary_runlist
  @primary_runlist
end

#recipe?(recipe_name) ⇒ Boolean

Returns true if this Node expects a given recipe, false if not.

First, the run list is consulted to see whether the recipe is explicitly included. If it's not there, it looks in `node`, which is populated when the run_list is expanded

NOTE: It's used by cookbook authors

Returns:

  • (Boolean)


305
306
307
# File 'lib/chef/node.rb', line 305

def recipe?(recipe_name)
  run_list.include?(recipe_name) || Array(self[:recipes]).include?(recipe_name)
end

#reset_defaults_and_overridesObject

Clear defaults and overrides, so that any deleted attributes between runs are still gone.



420
421
422
423
# File 'lib/chef/node.rb', line 420

def reset_defaults_and_overrides
  self.default.clear
  self.override.clear
end

#role?(role_name) ⇒ Boolean

Returns true if this Node expects a given role, false if not.

Returns:

  • (Boolean)


318
319
320
# File 'lib/chef/node.rb', line 318

def role?(role_name)
  run_list.include?("role[#{role_name}]")
end

#run_list(*args) ⇒ Object

Returns an Array of roles and recipes, in the order they will be applied. If you call it with arguments, they will become the new list of roles and recipes.



336
337
338
339
# File 'lib/chef/node.rb', line 336

def run_list(*args)
  rl = select_run_list
  args.length > 0 ? rl.reset!(args) : rl
end

#run_list=(list) ⇒ Object



341
342
343
344
# File 'lib/chef/node.rb', line 341

def run_list=(list)
  rl = select_run_list
  rl = list
end

#run_list?(item) ⇒ Boolean

Returns true if this Node expects a given role, false if not.

Returns:

  • (Boolean)


347
348
349
# File 'lib/chef/node.rb', line 347

def run_list?(item)
  run_list.detect { |r| r == item } ? true : false
end

#saveObject

Save this node via the REST API



607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
# File 'lib/chef/node.rb', line 607

def save
  # Try PUT. If the node doesn't yet exist, PUT will return 404,
  # so then POST to create.
  begin
    if Chef::Config[:why_run]
      Chef::Log.warn("In why-run mode, so NOT performing node save.")
    else
      chef_server_rest.put_rest("nodes/#{name}", data_for_save)
    end
  rescue Net::HTTPServerException => e
    if e.response.code == "404"
      chef_server_rest.post_rest("nodes", data_for_save)
    # Chef Server before 12.3 rejects node JSON with 'policy_name' or
    # 'policy_group' keys, but 'policy_name' will be detected first.
    # Backcompat can be removed in 13.0
    elsif e.response.code == "400" && e.response.body.include?("Invalid key policy_name")
      save_without_policyfile_attrs
    else
      raise
    end
  end
  self
end

#select_run_listObject



330
331
332
# File 'lib/chef/node.rb', line 330

def select_run_list
  @override_runlist.empty? ? @primary_runlist : @override_runlist
end

#set_cookbook_attributeObject

after the run_context has been set on the node, go through the cookbook_collection and setup the node attribute so that it is published in the node object



87
88
89
90
91
92
# File 'lib/chef/node.rb', line 87

def set_cookbook_attribute
  return unless run_context.cookbook_collection
  run_context.cookbook_collection.each do |cookbook_name, cookbook|
    automatic_attrs[:cookbooks][cookbook_name][:version] = cookbook.version
  end
end

#tag(*args) ⇒ Object



379
380
381
382
383
384
385
# File 'lib/chef/node.rb', line 379

def tag(*args)
  args.each do |tag|
    tags.push(tag.to_s) unless tags.include? tag.to_s
  end

  tags
end

#tagsObject

Lazy initializer for tags attribute



374
375
376
377
# File 'lib/chef/node.rb', line 374

def tags
  normal[:tags] = [] unless attribute?(:tags)
  normal[:tags]
end

#to_hashObject

Transform the node to a Hash



469
470
471
472
473
474
475
476
477
478
479
480
481
# File 'lib/chef/node.rb', line 469

def to_hash
  index_hash = Hash.new
  index_hash["chef_type"] = "node"
  index_hash["name"] = name
  index_hash["chef_environment"] = chef_environment
  attribute.each do |key, value|
    index_hash[key] = value
  end
  index_hash["recipe"] = run_list.recipe_names if run_list.recipe_names.length > 0
  index_hash["role"] = run_list.role_names if run_list.role_names.length > 0
  index_hash["run_list"] = run_list.run_list_items
  index_hash
end

#to_json(*a) ⇒ Object

Serialize this object as a hash



496
497
498
# File 'lib/chef/node.rb', line 496

def to_json(*a)
  Chef::JSONCompat.to_json(for_json, *a)
end

#to_sObject



646
647
648
# File 'lib/chef/node.rb', line 646

def to_s
  "node[#{name}]"
end

#update_from!(o) ⇒ Object



524
525
526
527
528
529
530
531
532
# File 'lib/chef/node.rb', line 524

def update_from!(o)
  run_list.reset!(o.run_list)
  self.automatic_attrs = o.automatic_attrs
  self.normal_attrs = o.normal_attrs
  self.override_attrs = o.override_attrs
  self.default_attrs = o.default_attrs
  chef_environment(o.chef_environment)
  self
end