Shell is Chef in an IRB session. Shell can interact with a Chef server via the REST API, and run and debug recipes interactively.
# File lib/chef/shell.rb, line 101 def self.configure_irb irb_conf[:HISTORY_FILE] = "~/.chef/chef_shell_history" irb_conf[:SAVE_HISTORY] = 1000 irb_conf[:IRB_RC] = lambda do |conf| m = conf.main conf.prompt_c = "chef#{leader(m)} > " conf.return_format = " => %s \n" conf.prompt_i = "chef#{leader(m)} > " conf.prompt_n = "chef#{leader(m)} ?> " conf.prompt_s = "chef#{leader(m)}%l> " end end
# File lib/chef/shell.rb, line 195 def self.editor @editor || Chef::Config[:editor] || ENV['EDITOR'] end
# File lib/chef/shell.rb, line 177 def self.fatal!(message, exit_status) Chef::Log.fatal(message) exit exit_status end
# File lib/chef/shell.rb, line 147 def self.greeting " #{Etc.getlogin}@#{Shell.session.node.fqdn}" rescue NameError, ArgumentError "" end
# File lib/chef/shell.rb, line 129 def self.init(main) parse_json configure_irb session # trigger ohai run + session load session.node.consume_attributes(@json_attribs) Extensions.extend_context_object(main) main.version puts puts "run `help' for help, `exit' or ^D to quit." puts puts "Ohai2u#{greeting}!" end
# File lib/chef/shell.rb, line 97 def self.irb_conf @irb_conf || IRB.conf end
Set the irb_conf object to something other than IRB.conf usful for testing.
# File lib/chef/shell.rb, line 93 def self.irb_conf=(conf_hash) @irb_conf = conf_hash end
# File lib/chef/shell.rb, line 116 def self.leader(main_object) env_string = Shell.env ? " (#{Shell.env})" : "" LEADERS[main_object.class] + env_string end
# File lib/chef/shell.rb, line 153 def self.parse_json # HACK: copied verbatim from chef/application/client, because it's not # reusable as written there :( if Chef::Config[:json_attribs] begin json_io = open(Chef::Config[:json_attribs]) rescue SocketError => error fatal!("I cannot connect to #{Chef::Config[:json_attribs]}", 2) rescue Errno::ENOENT => error fatal!("I cannot find #{Chef::Config[:json_attribs]}", 2) rescue Errno::EACCES => error fatal!("Permissions are incorrect on #{Chef::Config[:json_attribs]}. Please chmod a+r #{Chef::Config[:json_attribs]}", 2) rescue Exception => error fatal!("Got an unexpected error reading #{Chef::Config[:json_attribs]}: #{error.message}", 2) end begin @json_attribs = Chef::JSONCompat.from_json(json_io.read) rescue JSON::ParserError => error fatal!("Could not parse the provided JSON file (#{Chef::Config[:json_attribs]})!: " + error.message, 2) end end end
# File lib/chef/shell.rb, line 190 def self.parse_opts @options = Options.new @options.parse_opts end
Shell assumes it's running whenever it is defined
# File lib/chef/shell.rb, line 87 def self.running? true end
# File lib/chef/shell.rb, line 121 def self.session unless client_type.instance.node_built? puts "Session type: #{client_type.session_type}" client_type.instance.reset! end client_type.instance end
# File lib/chef/shell.rb, line 77 def self.setup_logger Chef::Config[:log_level] ||= :warn # If log_level is auto, change it to warn Chef::Config[:log_level] = :warn if Chef::Config[:log_level] == :auto Chef::Log.init(STDERR) Mixlib::Authentication::Log.logger = Ohai::Log.logger = Chef::Log.logger Chef::Log.level = Chef::Config[:log_level] || :warn end
Start the irb REPL with chef-shell's customizations
# File lib/chef/shell.rb, line 48 def self.start setup_logger # FUGLY HACK: irb gives us no other choice. irb_help = [:help, :irb_help, IRB::ExtendCommandBundle::NO_OVERRIDE] IRB::ExtendCommandBundle.instance_variable_get(:@ALIASES).delete(irb_help) parse_opts # HACK: this duplicates the functions of IRB.start, but we have to do it # to get access to the main object before irb starts. ::IRB.setup(nil) irb = IRB::Irb.new init(irb.context.main) irb_conf[:IRB_RC].call(irb.context) if irb_conf[:IRB_RC] irb_conf[:MAIN_CONTEXT] = irb.context trap("SIGINT") do irb.signal_handle end catch(:IRB_EXIT) do irb.eval_input end end
Generated with the Darkfish Rdoc Generator 2.