Module: PuppetRepl::Support::InputResponders
- Included in:
- PuppetRepl::Support
- Defined in:
- lib/puppet-repl/support/input_responders.rb
Instance Method Summary collapse
- #classes(args = []) ⇒ Object
- #classification(args = []) ⇒ Object
- #environment(args = []) ⇒ Object
- #facterdb_filter(args = []) ⇒ Object
- #facts(args = []) ⇒ Object
- #functions(args = []) ⇒ Object
- #handle_set(input) ⇒ Object
- #help(args = []) ⇒ Object
- #krt(args = []) ⇒ Object
- #play(args = []) ⇒ Object
- #reset(args = []) ⇒ Object
- #resources(args = []) ⇒ Object
- #set_log_level(level) ⇒ Object
- #static_responder_list ⇒ Object
- #vars(args = []) ⇒ Object
Instance Method Details
#classes(args = []) ⇒ Object
111 112 113 |
# File 'lib/puppet-repl/support/input_responders.rb', line 111 def classes(args=[]) scope.compiler.catalog.classes.ai end |
#classification(args = []) ⇒ Object
95 96 97 |
# File 'lib/puppet-repl/support/input_responders.rb', line 95 def classification(args=[]) node.classes.ai end |
#environment(args = []) ⇒ Object
60 61 62 |
# File 'lib/puppet-repl/support/input_responders.rb', line 60 def environment(args=[]) "Puppet Environment: #{puppet_env_name}" end |
#facterdb_filter(args = []) ⇒ Object
11 12 13 |
# File 'lib/puppet-repl/support/input_responders.rb', line 11 def facterdb_filter(args=[]) dynamic_facterdb_filter.ai end |
#facts(args = []) ⇒ Object
42 43 44 45 |
# File 'lib/puppet-repl/support/input_responders.rb', line 42 def facts(args=[]) variables = node.facts.values variables.ai({:sort_keys => true, :indent => -1}) end |
#functions(args = []) ⇒ Object
47 48 49 50 |
# File 'lib/puppet-repl/support/input_responders.rb', line 47 def functions(args=[]) filter = args.first || '' function_map.keys.sort.grep(/^#{Regexp.escape(filter)}/) end |
#handle_set(input) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/puppet-repl/support/input_responders.rb', line 19 def handle_set(input) output = '' args = input.split(' ') args.shift # throw away the set case args.shift when /node/ if name = args.shift output = "Resetting to use node #{name}" reset set_remote_node_name(name) else out_buffer.puts "Must supply a valid node name" end when /loglevel/ if level = args.shift @log_level = level set_log_level(level) output = "loglevel #{Puppet::Util::Log.level} is set" end end output end |
#help(args = []) ⇒ Object
15 16 17 |
# File 'lib/puppet-repl/support/input_responders.rb', line 15 def help(args=[]) PuppetRepl::Cli.print_repl_desc end |
#krt(args = []) ⇒ Object
84 85 86 |
# File 'lib/puppet-repl/support/input_responders.rb', line 84 def krt(args=[]) known_resource_types.ai({:sort_keys => true, :indent => -1}) end |
#play(args = []) ⇒ Object
88 89 90 91 92 93 |
# File 'lib/puppet-repl/support/input_responders.rb', line 88 def play(args=[]) config = {} config[:play] = args.first play_back(config) return nil # we don't want to return anything end |
#reset(args = []) ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/puppet-repl/support/input_responders.rb', line 64 def reset(args=[]) set_scope(nil) set_remote_node_name(nil) set_node(nil) set_facts(nil) set_environment(nil) set_log_level(log_level) end |
#resources(args = []) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/puppet-repl/support/input_responders.rb', line 99 def resources(args=[]) res = scope.compiler.catalog.resources.map do |res| res.to_s.gsub(/\[/, "['").gsub(/\]/, "']") # ensure the title has quotes end if !args.first.nil? res[args.first.to_i].ai else output = "Resources not shown in any specific order\n".warning output += res.ai end end |
#set_log_level(level) ⇒ Object
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/puppet-repl/support/input_responders.rb', line 73 def set_log_level(level) Puppet::Util::Log.level = level.to_sym buffer_log = Puppet::Util::Log.newdestination(:buffer) if buffer_log # if this is already set the buffer_log is nil buffer_log.out_buffer = out_buffer buffer_log.err_buffer = out_buffer end nil end |
#static_responder_list ⇒ Object
5 6 7 8 9 |
# File 'lib/puppet-repl/support/input_responders.rb', line 5 def static_responder_list ["exit", "functions", "classification","vars", 'facterdb_filter', "krt", "facts", "resources", "classes", "play","reset", "help" ] end |
#vars(args = []) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/puppet-repl/support/input_responders.rb', line 52 def vars(args=[]) # remove duplicate variables that are also in the facts hash variables = scope.to_hash.delete_if {| key, value | node.facts.values.key?(key) } variables['facts'] = 'removed by the puppet-repl' if variables.key?('facts') output = "Facts were removed for easier viewing".ai + "\n" output += variables.ai({:sort_keys => true, :indent => -1}) end |