Class: Puppet::Node
- Extended by:
- Indirector
- Includes:
- Environment::Helper
- Defined in:
- lib/puppet/node.rb,
lib/puppet/node/environment.rb
Overview
Just define it, so this class has fewer load dependencies.
Defined Under Namespace
Classes: ActiveRecord, Environment, Exec, Facts, Inventory, Ldap, Memory, Plain, Rest, StoreConfigs, Yaml
Constant Summary
Constants included from Indirector
Instance Attribute Summary collapse
-
#classes ⇒ Object
Returns the value of attribute classes.
-
#ipaddress ⇒ Object
Returns the value of attribute ipaddress.
-
#name ⇒ Object
Returns the value of attribute name.
-
#parameters ⇒ Object
Returns the value of attribute parameters.
-
#source ⇒ Object
Returns the value of attribute source.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Class Method Summary collapse
Instance Method Summary collapse
- #environment ⇒ Object
-
#fact_merge ⇒ Object
Merge the node facts with parameters from the node source.
-
#initialize(name, options = {}) ⇒ Node
constructor
A new instance of Node.
-
#merge(params) ⇒ Object
Merge any random parameters into our parameter list.
-
#names ⇒ Object
Calculate the list of names we might use for looking up our node.
- #split_name(name) ⇒ Object
- #to_pson(*args) ⇒ Object
Methods included from Indirector
Methods included from Environment::Helper
Constructor Details
#initialize(name, options = {}) ⇒ Node
Returns a new instance of Node.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/puppet/node.rb', line 60 def initialize(name, = {}) raise ArgumentError, "Node names cannot be nil" unless name @name = name if classes = [:classes] if classes.is_a?(String) @classes = [classes] else @classes = classes end else @classes = [] end @parameters = [:parameters] || {} if env = [:environment] self.environment = env end @time = Time.now end |
Instance Attribute Details
#classes ⇒ Object
Returns the value of attribute classes.
20 21 22 |
# File 'lib/puppet/node.rb', line 20 def classes @classes end |
#ipaddress ⇒ Object
Returns the value of attribute ipaddress.
20 21 22 |
# File 'lib/puppet/node.rb', line 20 def ipaddress @ipaddress end |
#name ⇒ Object
Returns the value of attribute name.
20 21 22 |
# File 'lib/puppet/node.rb', line 20 def name @name end |
#parameters ⇒ Object
Returns the value of attribute parameters.
20 21 22 |
# File 'lib/puppet/node.rb', line 20 def parameters @parameters end |
#source ⇒ Object
Returns the value of attribute source.
20 21 22 |
# File 'lib/puppet/node.rb', line 20 def source @source end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
21 22 23 |
# File 'lib/puppet/node.rb', line 21 def time @time end |
Class Method Details
.from_pson(pson) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/puppet/node.rb', line 25 def self.from_pson(pson) raise ArgumentError, "No name provided in serialized data" unless name = pson['name'] node = new(name) node.classes = pson['classes'] node.parameters = pson['parameters'] node.environment = pson['environment'] node end |
Instance Method Details
#environment ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/puppet/node.rb', line 48 def environment return super if @environment if env = parameters["environment"] self.environment = env return super end # Else, return the default Puppet::Node::Environment.new end |
#fact_merge ⇒ Object
Merge the node facts with parameters from the node source.
84 85 86 87 88 89 90 91 92 |
# File 'lib/puppet/node.rb', line 84 def fact_merge if facts = Puppet::Node::Facts.indirection.find(name) merge(facts.values) end rescue => detail error = Puppet::Error.new("Could not retrieve facts for #{name}: #{detail}") error.set_backtrace(detail.backtrace) raise error end |
#merge(params) ⇒ Object
Merge any random parameters into our parameter list.
95 96 97 98 99 100 101 |
# File 'lib/puppet/node.rb', line 95 def merge(params) params.each do |name, value| @parameters[name] = value unless @parameters.include?(name) end @parameters["environment"] ||= self.environment.name.to_s if self.environment end |
#names ⇒ Object
Calculate the list of names we might use for looking up our node. This is only used for AST nodes.
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/puppet/node.rb', line 105 def names return [name] if Puppet.settings[:strict_hostname_checking] names = [] names += split_name(name) if name.include?(".") # First, get the fqdn unless fqdn = parameters["fqdn"] if parameters["hostname"] and parameters["domain"] fqdn = parameters["hostname"] + "." + parameters["domain"] else Puppet.warning "Host is missing hostname and/or domain: #{name}" end end # Now that we (might) have the fqdn, add each piece to the name # list to search, in order of longest to shortest. names += split_name(fqdn) if fqdn # And make sure the node name is first, since that's the most # likely usage. # The name is usually the Certificate CN, but it can be # set to the 'facter' hostname instead. if Puppet[:node_name] == 'cert' names.unshift name else names.unshift parameters["hostname"] end names.uniq end |
#split_name(name) ⇒ Object
137 138 139 140 141 142 143 144 |
# File 'lib/puppet/node.rb', line 137 def split_name(name) list = name.split(".") tmp = [] list.each_with_index do |short, i| tmp << list[0..i].join(".") end tmp.reverse end |
#to_pson(*args) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/puppet/node.rb', line 35 def to_pson(*args) result = { 'document_type' => "Node", 'data' => {} } result['data']['name'] = name result['data']['classes'] = classes unless classes.empty? result['data']['parameters'] = parameters unless parameters.empty? result['data']['environment'] = environment.name result.to_pson(*args) end |