Class: Shef::DoppelGangerClient

Inherits:
Chef::Client show all
Defined in:
lib/chef/shef/shef_session.rb

Instance Attribute Summary collapse

Attributes inherited from Chef::Client

#json_attribs, #node, #ohai, #rest, #run_status, #runner

Instance Method Summary collapse

Methods inherited from Chef::Client

clear_notifications, #converge, #run, #run_completed_successfully, run_completed_successfully_notifications, #run_failed, run_failed_notifications, run_start_notifications, #run_started, #sync_cookbooks, when_run_completes_successfully, when_run_fails, when_run_starts

Constructor Details

#initialize(node_name) ⇒ DoppelGangerClient

Returns a new instance of DoppelGangerClient.



210
211
212
213
# File 'lib/chef/shef/shef_session.rb', line 210

def initialize(node_name)
  @node_name = node_name
  @ohai = Ohai::System.new
end

Instance Attribute Details

#node_nameObject (readonly)

Returns the value of attribute node_name.



208
209
210
# File 'lib/chef/shef/shef_session.rb', line 208

def node_name
  @node_name
end

Instance Method Details

#build_nodeObject

DoppelGanger implementation of build_node. preserves as many of the node’s attributes, and does not save updates to the server



223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/chef/shef/shef_session.rb', line 223

def build_node
  Chef::Log.debug("Building node object for #{@node_name}")

  @node = Chef::Node.find_or_create(node_name)

  ohai_data = @ohai.data.merge(@node.automatic_attrs)

  @node.consume_external_attrs(ohai_data,nil)
  @node.reset_defaults_and_overrides

  @node
end

#registerObject



236
237
238
# File 'lib/chef/shef/shef_session.rb', line 236

def register
  @rest = Chef::REST.new(Chef::Config[:chef_server_url], Chef::Config[:node_name], Chef::Config[:client_key])
end

#run_ohaiObject

Run the very smallest amount of ohai we can get away with and still hope to have things work. Otherwise we’re not very good doppelgangers



217
218
219
# File 'lib/chef/shef/shef_session.rb', line 217

def run_ohai
  @ohai.require_plugin('os')
end