class Shell::ShellSession

Attributes

client[R]
compile[RW]
json_configuration[RW]
node[RW]
node_attributes[R]
recipe[RW]
run_context[W]

Public Class Methods

new() click to toggle source
# File lib/chef/shell/shell_session.rb, line 43
def initialize
  @node_built = false
  formatter = Chef::Formatters.new(Chef::Config.formatter, STDOUT, STDERR)
  @events = Chef::EventDispatch::Dispatcher.new(formatter)
end
session_type(type = nil) click to toggle source
# File lib/chef/shell/shell_session.rb, line 36
def self.session_type(type = nil)
  @session_type = type if type
  @session_type
end

Public Instance Methods

cookbook_loader() click to toggle source
# File lib/chef/shell/shell_session.rb, line 85
def cookbook_loader
  nil
end
definitions() click to toggle source
# File lib/chef/shell/shell_session.rb, line 81
def definitions
  nil
end
node_attributes=(attrs) click to toggle source
# File lib/chef/shell/shell_session.rb, line 67
def node_attributes=(attrs)
  @node_attributes = attrs
  @node.consume_attributes(@node_attributes)
end
node_built?() click to toggle source
# File lib/chef/shell/shell_session.rb, line 49
def node_built?
  !!@node_built
end
rebuild_context() click to toggle source
# File lib/chef/shell/shell_session.rb, line 93
def rebuild_context
  raise "Not Implemented! :rebuild_collection should be implemented by subclasses"
end
reset!() click to toggle source
# File lib/chef/shell/shell_session.rb, line 53
def reset!
  loading do
    rebuild_node
    @node = client.node
    shorten_node_inspect
    Shell::Extensions.extend_context_node(@node)
    rebuild_context
    node.consume_attributes(node_attributes) if node_attributes
    @recipe = Chef::Recipe.new(nil, nil, run_context)
    Shell::Extensions.extend_context_recipe(@recipe)
    @node_built = true
  end
end
resource_collection() click to toggle source
# File lib/chef/shell/shell_session.rb, line 72
def resource_collection
  run_context.resource_collection
end
run_context() click to toggle source
# File lib/chef/shell/shell_session.rb, line 77
def run_context
  @run_context ||= rebuild_context
end
save_node() click to toggle source
# File lib/chef/shell/shell_session.rb, line 89
def save_node
  raise "Not Supported! #{self.class.name} doesn't support #save_node, maybe you need to run chef-shell in client mode?"
end

Private Instance Methods

loading() { || ... } click to toggle source
# File lib/chef/shell/shell_session.rb, line 99
def loading
  show_loading_progress
  begin
    yield
  rescue => e
    loading_complete(false)
    raise e
  else
    loading_complete(true)
  end
end
loading_complete(success) click to toggle source
# File lib/chef/shell/shell_session.rb, line 122
def loading_complete(success)
  @loading = false
  @dot_printer.join
  msg = success ? "done.\n\n" : "epic fail!\n\n"
  print msg
end
rebuild_node() click to toggle source
# File lib/chef/shell/shell_session.rb, line 135
def rebuild_node
  raise "Not Implemented! :rebuild_node should be implemented by subclasses"
end
shorten_node_inspect() click to toggle source
# File lib/chef/shell/shell_session.rb, line 129
def shorten_node_inspect
  def @node.inspect # rubocop:disable Lint/NestedMethodDefinition
    "<Chef::Node:0x#{object_id.to_s(16)} @name=\"#{name}\">"
  end
end
show_loading_progress() click to toggle source
# File lib/chef/shell/shell_session.rb, line 111
def show_loading_progress
  print "Loading"
  @loading = true
  @dot_printer = Thread.new do
    while @loading
      print "."
      sleep 0.5
    end
  end
end