Module: PuppetRepl::Support
- Includes:
- Compilier, Environment, Facts, Functions, InputResponders, Node, Play, Scope
- Included in:
- Cli
- Defined in:
- lib/puppet-repl/support.rb,
lib/puppet-repl/support/node.rb,
lib/puppet-repl/support/play.rb,
lib/puppet-repl/support/facts.rb,
lib/puppet-repl/support/scope.rb,
lib/puppet-repl/support/compiler.rb,
lib/puppet-repl/support/functions.rb,
lib/puppet-repl/support/environment.rb,
lib/puppet-repl/support/input_responders.rb
Defined Under Namespace
Modules: Compilier, Environment, Facts, Functions, InputResponders, Node, Play, Scope
Instance Method Summary collapse
- #default_manifests_dir ⇒ Object
-
#default_modules_paths ⇒ Object
returns an array of module directories, generally this is the only place to look for puppet code by default.
- #default_site_manifest ⇒ Object
-
#do_initialize ⇒ Object
this is required in order to load things only when we need them.
- #initialize_from_scope(value) ⇒ Object
- #keyword_expression ⇒ Object
- #known_resource_types ⇒ Object
-
#modules_paths ⇒ Object
returns all the modules paths defined in the environment.
-
#parse_error(error) ⇒ Object
parses the error type into a more useful error message defined in errors.rb returns new error object or the original if error cannot be parsed.
-
#parser ⇒ Object
returns a future parser for evaluating code.
- #puppet_lib_dir ⇒ Object
-
#puppet_repl_lib_dir ⇒ Object
this is the lib directory of this gem in order to load any puppet functions from this gem we need to add the lib path of this gem.
Methods included from Play
#convert_to_text, #fetch_url_data, #play_back, #play_back_string, #play_back_url
Methods included from InputResponders
#classes, #classification, #environment, #facts, #functions, #handle_set, #help, #krt, #play, #reset, #resources, #set_log_level, #static_responder_list, #vars
Methods included from Node
#convert_remote_node, #create_node, #get_remote_node, #node, #remote_node_name, #remote_node_name=, #set_node, #set_node_from_name, #set_remote_node_name
Methods included from Functions
#function_files, #function_map, #lib_dirs, #load_lib_dirs, #mod_finder, #resolve_paths
Methods included from Scope
#create_scope, #scope, #scope_vars, #set_scope
Methods included from Facts
#default_facts, #facterdb_filter, #server_facts, #set_facts
Methods included from Environment
#create_environment, #default_puppet_env_name, #environment_loaders, #puppet_env_name, #puppet_environment, #set_environment
Methods included from Compilier
#compiler, #create_compiler, #set_compiler
Instance Method Details
#default_manifests_dir ⇒ Object
120 121 122 |
# File 'lib/puppet-repl/support.rb', line 120 def default_manifests_dir File.join(Puppet[:environmentpath],default_puppet_env_name,'manifests') end |
#default_modules_paths ⇒ Object
returns an array of module directories, generally this is the only place to look for puppet code by default. This is read from the puppet configuration
46 47 48 49 50 51 52 53 |
# File 'lib/puppet-repl/support.rb', line 46 def default_modules_paths dirs = [] do_initialize if Puppet[:codedir].nil? # add the puppet-repl directory so we can load any defined functions dirs << File.join(Puppet[:environmentpath],default_puppet_env_name,'modules') unless Puppet[:environmentpath].empty? dirs << Puppet.settings[:basemodulepath].split(':') dirs.flatten end |
#default_site_manifest ⇒ Object
124 125 126 |
# File 'lib/puppet-repl/support.rb', line 124 def default_site_manifest File.join(default_manifests_dir, 'site.pp') end |
#do_initialize ⇒ Object
this is required in order to load things only when we need them
100 101 102 103 104 105 106 107 |
# File 'lib/puppet-repl/support.rb', line 100 def do_initialize begin Puppet.initialize_settings Puppet[:trusted_node_data] = true rescue # do nothing otherwise calling init twice raises an error end end |
#initialize_from_scope(value) ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/puppet-repl/support.rb', line 67 def initialize_from_scope(value) set_scope(value) unless value.nil? set_environment(value.environment) set_node(value.compiler.node) set_compiler(value.compiler) end end |
#keyword_expression ⇒ Object
76 77 78 |
# File 'lib/puppet-repl/support.rb', line 76 def keyword_expression @keyword_expression ||= Regexp.new(/^exit|^:set|^play|^classification|^facts|^vars|^functions|^classes|^resources|^krt|^environment|^reset|^help/) end |
#known_resource_types ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/puppet-repl/support.rb', line 80 def known_resource_types res = { :hostclasses => scope.known_resource_types.hostclasses.keys, :definitions => scope.known_resource_types.definitions.keys, :nodes => scope.known_resource_types.nodes.keys, } if sites = scope.known_resource_types.instance_variable_get(:@sites) res.merge!(:sites => scope.known_resource_types.instance_variable_get(:@sites).first) end if scope.known_resource_types.respond_to?(:applications) res.merge!(:applications => scope.known_resource_types.applications.keys) end # some versions of puppet do not support capabilities if scope.known_resource_types.respond_to?(:capability_mappings) res.merge!(:capability_mappings => scope.known_resource_types.capability_mappings.keys) end res end |
#modules_paths ⇒ Object
returns all the modules paths defined in the environment
63 64 65 |
# File 'lib/puppet-repl/support.rb', line 63 def modules_paths puppet_environment.full_modulepath end |
#parse_error(error) ⇒ Object
parses the error type into a more useful error message defined in errors.rb returns new error object or the original if error cannot be parsed
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/puppet-repl/support.rb', line 21 def parse_error(error) case error when SocketError PuppetRepl::Exception::ConnectError.new(:message => "Unknown host: #{Puppet[:server]}") when Net::HTTPError PuppetRepl::Exception::AuthError.new(:message => error.) when Errno::ECONNREFUSED PuppetRepl::Exception::ConnectError.new(:message => error.) when Puppet::Error if error. =~ /could\ not\ find\ class/i PuppetRepl::Exception::NoClassError.new(:default_modules_paths => default_modules_paths, :message => error.) elsif error. =~ /default\ node/i PuppetRepl::Exception::NodeDefinitionError.new(:default_site_manifest => default_site_manifest, :message => error.) else error end else error end end |
#parser ⇒ Object
returns a future parser for evaluating code
116 117 118 |
# File 'lib/puppet-repl/support.rb', line 116 def parser @parser || ::Puppet::Pops::Parser::EvaluatingParser.new end |
#puppet_lib_dir ⇒ Object
109 110 111 112 113 |
# File 'lib/puppet-repl/support.rb', line 109 def puppet_lib_dir # returns something like "/Library/Ruby/Gems/2.0.0/gems/puppet-4.2.2/lib/puppet.rb" # this is only useful when returning a namespace with the functions @puppet_lib_dir ||= File.dirname(Puppet.method(:[]).source_location.first) end |
#puppet_repl_lib_dir ⇒ Object
this is the lib directory of this gem in order to load any puppet functions from this gem we need to add the lib path of this gem
58 59 60 |
# File 'lib/puppet-repl/support.rb', line 58 def puppet_repl_lib_dir File.(File.join(File.dirname(File.dirname(File.dirname(__FILE__))), 'lib')) end |