Class: Puppet::Node
- Extended by:
- Indirector
- Includes:
- Environment::Helper
- Defined in:
- lib/vendor/puppet/node.rb,
lib/vendor/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.
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
Methods included from Indirector
Methods included from Environment::Helper
Constructor Details
#initialize(name, options = {}) ⇒ Node
Returns a new instance of Node.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/vendor/puppet/node.rb', line 35 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/vendor/puppet/node.rb', line 20 def classes @classes end |
#ipaddress ⇒ Object
Returns the value of attribute ipaddress.
20 21 22 |
# File 'lib/vendor/puppet/node.rb', line 20 def ipaddress @ipaddress end |
#name ⇒ Object
Returns the value of attribute name.
20 21 22 |
# File 'lib/vendor/puppet/node.rb', line 20 def name @name end |
#parameters ⇒ Object
Returns the value of attribute parameters.
20 21 22 |
# File 'lib/vendor/puppet/node.rb', line 20 def parameters @parameters end |
#source ⇒ Object
Returns the value of attribute source.
20 21 22 |
# File 'lib/vendor/puppet/node.rb', line 20 def source @source end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
21 22 23 |
# File 'lib/vendor/puppet/node.rb', line 21 def time @time end |
Instance Method Details
#environment ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/vendor/puppet/node.rb', line 23 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.
59 60 61 62 63 64 65 66 67 |
# File 'lib/vendor/puppet/node.rb', line 59 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.
70 71 72 73 74 75 76 |
# File 'lib/vendor/puppet/node.rb', line 70 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.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/vendor/puppet/node.rb', line 80 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
112 113 114 115 116 117 118 119 |
# File 'lib/vendor/puppet/node.rb', line 112 def split_name(name) list = name.split(".") tmp = [] list.each_with_index do |short, i| tmp << list[0..i].join(".") end tmp.reverse end |