Class: Shell::DoppelGangerClient

Inherits:
Chef::Client show all
Defined in:
lib/chef/shell/shell_session.rb

Constant Summary

Constants inherited from Chef::Client

Chef::Client::CERT_SYSTEM_STORE_CURRENT_USER, Chef::Client::CERT_SYSTEM_STORE_LOCAL_MACHINE, Chef::Client::CERT_SYSTEM_STORE_SERVICES, Chef::Client::CERT_SYSTEM_STORE_USERS, Chef::Client::CRYPT_EXPORTABLE, Chef::Client::STDERR_FD, Chef::Client::STDOUT_FD

Instance Attribute Summary collapse

Attributes inherited from Chef::Client

#events, #json_attribs, #local_context, #logger, #ohai, #run_context, #run_status, #runner

Instance Method Summary collapse

Methods inherited from Chef::Client

#check_certstore_for_key, clear_notifications, #configure_event_loggers, #configure_formatters, #converge, #converge_and_save, #create_new_key_and_register, #do_windows_admin_check, #expanded_run_list, #formatters_for_run, generate_pfx_package, #generate_pfx_package, import_pfx_to_store, #import_pfx_to_store, #load_node, #load_required_recipe, #node, #node=, #policy_builder, #rest, #rest_clean, #run, #run_completed_successfully, run_completed_successfully_notifications, #run_failed, run_failed_notifications, run_start_notifications, #run_started, #save_updated_node, #setup_run_context, #sync_cookbooks, update_key_and_register, #update_key_and_register, when_run_completes_successfully, when_run_fails, when_run_starts

Methods included from Chef::Mixin::Deprecation

#deprecated_attr, #deprecated_attr_reader, #deprecated_attr_writer, #deprecated_ivar

Constructor Details

#initialize(node_name) ⇒ DoppelGangerClient

Returns a new instance of DoppelGangerClient.



244
245
246
247
# File 'lib/chef/shell/shell_session.rb', line 244

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.



242
243
244
# File 'lib/chef/shell/shell_session.rb', line 242

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



257
258
259
260
261
262
263
264
265
266
267
# File 'lib/chef/shell/shell_session.rb', line 257

def build_node
  Chef::Log.trace("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)
  @run_list_expansion = @node.expand!("server")
  @expanded_run_list_with_versions = @run_list_expansion.recipes.with_version_constraints_strings
  Chef::Log.info("Run List is [#{@node.run_list}]")
  Chef::Log.info("Run List expands to [#{@expanded_run_list_with_versions.join(", ")}]")
  @node
end

#registerObject



269
270
271
272
# File 'lib/chef/shell/shell_session.rb', line 269

def register
  @rest = Chef::ServerAPI.new(Chef::Config[:chef_server_url], client_name: Chef::Config[:node_name],
                                                              signing_key_filename: 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



251
252
253
# File 'lib/chef/shell/shell_session.rb', line 251

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