Module: PuppetDebugger::Support::Node
- Included in:
- PuppetDebugger::Support
- Defined in:
- lib/puppet-debugger/support/node.rb
Instance Method Summary collapse
-
#convert_remote_node(remote_node) ⇒ Object
this is a hack to get around that the puppet node fact face does not return a proper node object with the facts hash populated returns a node object with a proper facts hash.
-
#create_node ⇒ Object
creates a node object using defaults or gets the remote node object if the remote_node_name is defined.
- #create_real_node(environment) ⇒ Object
- #get_remote_node(name) ⇒ Object
-
#node ⇒ node
Puppet node object.
- #remote_node_name ⇒ Object
- #remote_node_name=(name) ⇒ Object
- #set_node(value) ⇒ Object
-
#set_node_from_name(name) ⇒ Object
query the remote puppet server and retrieve the node object.
- #set_remote_node_name(name) ⇒ Object
Instance Method Details
#convert_remote_node(remote_node) ⇒ Object
this is a hack to get around that the puppet node fact face does not return a proper node object with the facts hash populated returns a node object with a proper facts hash
74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/puppet-debugger/support/node.rb', line 74 def convert_remote_node(remote_node) = {} # remove trusted data as it will later get populated during compilation parameters = remote_node.parameters.dup trusted_data = parameters.delete('trusted') [:parameters] = parameters || {} [:facts] = Puppet::Node::Facts.new(remote_node.name, remote_node.parameters) [:classes] = remote_node.classes [:environment] = puppet_environment node_object = Puppet::Node.new(remote_node.name, ) node_object.add_server_facts(server_facts) if node_object.respond_to?(:add_server_facts) node_object.trusted_data = trusted_data node_object end |
#create_node ⇒ Object
creates a node object using defaults or gets the remote node object if the remote_node_name is defined
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/puppet-debugger/support/node.rb', line 10 def create_node if remote_node_name # refetch node_obj = set_node_from_name(remote_node_name) end unless node_obj = {} [:parameters] = default_facts.values [:facts] = default_facts [:classes] = [] [:environment] = puppet_environment name = default_facts.values['fqdn'] node_obj = Puppet::Node.new(name, ) node_obj.add_server_facts(server_facts) if node_obj.respond_to?(:add_server_facts) node_obj end node_obj end |
#create_real_node(environment) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/puppet-debugger/support/node.rb', line 29 def create_real_node(environment) node = nil unless Puppet[:node_name_fact].empty? # Collect our facts. facts = Puppet::Node::Facts.indirection.find(Puppet[:node_name_value]) raise "Could not find facts for #{Puppet[:node_name_value]}" unless facts Puppet[:node_name_value] = facts.values[Puppet[:node_name_fact]] facts.name = Puppet[:node_name_value] end Puppet.override({ current_environment: environment }, 'For puppet debugger') do # Find our Node node = Puppet::Node.indirection.find(Puppet[:node_name_value]) raise "Could not find node #{Puppet[:node_name_value]}" unless node # Merge in the facts. node.merge(facts.values) if facts end node end |
#get_remote_node(name) ⇒ Object
65 66 67 68 69 |
# File 'lib/puppet-debugger/support/node.rb', line 65 def get_remote_node(name) indirection = Puppet::Indirector::Indirection.instance(:node) indirection.terminus_class = 'rest' indirection.find(name, environment: puppet_environment) end |
#node ⇒ node
Returns puppet node object.
61 62 63 |
# File 'lib/puppet-debugger/support/node.rb', line 61 def node @node ||= create_node end |
#remote_node_name ⇒ Object
56 57 58 |
# File 'lib/puppet-debugger/support/node.rb', line 56 def remote_node_name @remote_node_name end |
#remote_node_name=(name) ⇒ Object
52 53 54 |
# File 'lib/puppet-debugger/support/node.rb', line 52 def remote_node_name=(name) @remote_node_name = name end |
#set_node(value) ⇒ Object
103 104 105 |
# File 'lib/puppet-debugger/support/node.rb', line 103 def set_node(value) @node = value end |
#set_node_from_name(name) ⇒ Object
query the remote puppet server and retrieve the node object
91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/puppet-debugger/support/node.rb', line 91 def set_node_from_name(name) out_buffer.puts "Fetching node #{name}" remote_node = get_remote_node(name) if remote_node && remote_node.parameters.empty? remote_node_name = nil # clear out the remote name raise PuppetDebugger::Exception::UndefinedNode, name: remote_node.name end remote_node_name = remote_node.name node_object = convert_remote_node(remote_node) set_node(node_object) end |
#set_remote_node_name(name) ⇒ Object
48 49 50 |
# File 'lib/puppet-debugger/support/node.rb', line 48 def set_remote_node_name(name) @remote_node_name = name end |