Class: Puppet::Resource::TypeCollection Private
- Includes:
- Util::Warnings
- Defined in:
- lib/puppet/resource/type_collection.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Instance Attribute Summary collapse
- #environment ⇒ Object readonly private
- #parse_failed ⇒ Object private
Instance Method Summary collapse
- #<<(thing) ⇒ Object private
- #add(instance) ⇒ Object private
- #add_application(instance) ⇒ Object private
- #add_capability_mapping(instance) ⇒ Object private
- #add_definition(instance) ⇒ Object private
- #add_hostclass(instance) ⇒ Object private
- #add_node(instance) ⇒ Object private
- #add_site(instance) ⇒ Object private
- #application(name) ⇒ Object private
- #clear ⇒ Object private
- #definition(name) ⇒ Object private
- #find_application(name) ⇒ Object private
- #find_definition(name) ⇒ Object private
- #find_hostclass(name) ⇒ Object private
- #find_node(name) ⇒ Object private
- #find_site ⇒ Object private
- #handle_hostclass_merge(instance) ⇒ Object private
- #hostclass(name) ⇒ Object private
- #import_ast(ast, modname) ⇒ Object private
-
#initialize(env) ⇒ TypeCollection
constructor
private
A new instance of TypeCollection.
- #inspect ⇒ Object private
- #loader ⇒ Object private
- #node(name) ⇒ Object private
- #node_exists?(name) ⇒ Boolean private
- #nodes? ⇒ Boolean private
- #parse_failed? ⇒ Boolean private
-
#replace_settings(instance) ⇒ Object
private
Replaces the known settings with a new instance (that must be named ‘settings’).
- #site(_) ⇒ Object private
- #version ⇒ Object private
Methods included from Util::Warnings
clear_warnings, debug_once, maybe_log, notice_once, warnonce
Constructor Details
#initialize(env) ⇒ TypeCollection
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of TypeCollection.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/puppet/resource/type_collection.rb', line 24 def initialize(env) @environment = env @hostclasses = {} @definitions = {} @capability_mappings = {} @applications = {} @nodes = {} @notfound = {} @sites = [] @lock = Puppet::Concurrent::Lock.new # So we can keep a list and match the first-defined regex @node_list = [] end |
Instance Attribute Details
#environment ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
9 10 11 |
# File 'lib/puppet/resource/type_collection.rb', line 9 def environment @environment end |
#parse_failed ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
10 11 12 |
# File 'lib/puppet/resource/type_collection.rb', line 10 def parse_failed @parse_failed end |
Instance Method Details
#<<(thing) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
57 58 59 60 |
# File 'lib/puppet/resource/type_collection.rb', line 57 def <<(thing) add(thing) self end |
#add(instance) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
62 63 64 65 66 67 68 69 |
# File 'lib/puppet/resource/type_collection.rb', line 62 def add(instance) # return a merged instance, or the given catch(:merged) { send("add_#{instance.type}", instance) instance.resource_type_collection = self instance } end |
#add_application(instance) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
166 167 168 169 170 171 |
# File 'lib/puppet/resource/type_collection.rb', line 166 def add_application(instance) dupe_check(instance, @hostclasses) { |dupe| _("'%{name}' is already defined%{error} as a class; cannot redefine as an application") % { name: instance.name, error: dupe.error_context } } dupe_check(instance, @definitions) { |dupe| _("'%{name}' is already defined%{error} as a definition; cannot redefine as an application") % { name: instance.name, error: dupe.error_context } } dupe_check(instance, @applications) { |dupe| _("'%{name}' is already defined%{error} as an application; cannot be redefined") % { name: instance.name, error: dupe.error_context } } @applications[instance.name] = instance end |
#add_capability_mapping(instance) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
157 158 159 160 |
# File 'lib/puppet/resource/type_collection.rb', line 157 def add_capability_mapping(instance) dupe_check(instance, @capability_mappings) { |dupe| _("'%{name}' is already defined%{error} as a class; cannot redefine as a mapping") % { name: instance.name, error: dupe.error_context } } @capability_mappings[instance.name] = instance end |
#add_definition(instance) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
150 151 152 153 154 155 |
# File 'lib/puppet/resource/type_collection.rb', line 150 def add_definition(instance) dupe_check(instance, @hostclasses) { |dupe| _("'%{name}' is already defined%{error} as a class; cannot redefine as a definition") % { name: instance.name, error: dupe.error_context } } dupe_check(instance, @definitions) { |dupe| _("Definition '%{name}' is already defined%{error}; cannot be redefined") % { name: instance.name, error: dupe.error_context } } dupe_check(instance, @applications) { |dupe| _("'%{name}' is already defined%{error} as an application; cannot be redefined") % { name: instance.name, error: dupe.error_context } } @definitions[instance.name] = instance end |
#add_hostclass(instance) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
71 72 73 74 75 76 77 78 79 |
# File 'lib/puppet/resource/type_collection.rb', line 71 def add_hostclass(instance) handle_hostclass_merge(instance) dupe_check(instance, @hostclasses) { |dupe| _("Class '%{klass}' is already defined%{error}; cannot redefine") % { klass: instance.name, error: dupe.error_context } } dupe_check(instance, @definitions) { |dupe| _("Definition '%{klass}' is already defined%{error}; cannot be redefined as a class") % { klass: instance.name, error: dupe.error_context } } dupe_check(instance, @applications) { |dupe| _("Application '%{klass}' is already defined%{error}; cannot be redefined as a class") % { klass: instance.name, error: dupe.error_context } } @hostclasses[instance.name] = instance instance end |
#add_node(instance) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
105 106 107 108 109 110 111 |
# File 'lib/puppet/resource/type_collection.rb', line 105 def add_node(instance) dupe_check(instance, @nodes) { |dupe| _("Node '%{name}' is already defined%{error}; cannot redefine") % { name: instance.name, error: dupe.error_context } } @node_list << instance @nodes[instance.name] = instance instance end |
#add_site(instance) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
113 114 115 116 117 |
# File 'lib/puppet/resource/type_collection.rb', line 113 def add_site(instance) dupe_check_singleton(instance, @sites) { |dupe| _("Site is already defined%{error}; cannot redefine") % { error: dupe.error_context } } @sites << instance instance end |
#application(name) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
173 174 175 |
# File 'lib/puppet/resource/type_collection.rb', line 173 def application(name) @applications[munge_name(name)] end |
#clear ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
14 15 16 17 18 19 20 21 22 |
# File 'lib/puppet/resource/type_collection.rb', line 14 def clear @hostclasses.clear @definitions.clear @applications.clear @nodes.clear @notfound.clear @capability_mappings.clear @sites.clear end |
#definition(name) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
162 163 164 |
# File 'lib/puppet/resource/type_collection.rb', line 162 def definition(name) @definitions[munge_name(name)] end |
#find_application(name) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
193 194 195 |
# File 'lib/puppet/resource/type_collection.rb', line 193 def find_application(name) find_or_load(name, :application) end |
#find_definition(name) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
189 190 191 |
# File 'lib/puppet/resource/type_collection.rb', line 189 def find_definition(name) find_or_load(name, :definition) end |
#find_hostclass(name) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
185 186 187 |
# File 'lib/puppet/resource/type_collection.rb', line 185 def find_hostclass(name) find_or_load(name, :hostclass) end |
#find_node(name) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
177 178 179 |
# File 'lib/puppet/resource/type_collection.rb', line 177 def find_node(name) @nodes[munge_name(name)] end |
#find_site ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
181 182 183 |
# File 'lib/puppet/resource/type_collection.rb', line 181 def find_site() @sites[0] end |
#handle_hostclass_merge(instance) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
81 82 83 84 85 86 87 88 89 |
# File 'lib/puppet/resource/type_collection.rb', line 81 def handle_hostclass_merge(instance) # Only main class (named '') can be merged (for purpose of merging top-scopes). return instance unless instance.name == '' if instance.type == :hostclass && (other = @hostclasses[instance.name]) && other.type == :hostclass other.merge(instance) # throw is used to signal merge - avoids dupe checks and adding it to hostclasses throw :merged, other end end |
#hostclass(name) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
101 102 103 |
# File 'lib/puppet/resource/type_collection.rb', line 101 def hostclass(name) @hostclasses[munge_name(name)] end |
#import_ast(ast, modname) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
39 40 41 42 43 |
# File 'lib/puppet/resource/type_collection.rb', line 39 def import_ast(ast, modname) ast.instantiate(modname).each do |instance| add(instance) end end |
#inspect ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/puppet/resource/type_collection.rb', line 45 def inspect "TypeCollection" + { :hostclasses => @hostclasses.keys, :definitions => @definitions.keys, :nodes => @nodes.keys, :capability_mappings => @capability_mappings.keys, :applications => @applications.keys, :site => @sites[0] # todo, could be just a binary, this dumps the entire body (good while developing) }.inspect end |
#loader ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
123 124 125 |
# File 'lib/puppet/resource/type_collection.rb', line 123 def loader @loader ||= Puppet::Parser::TypeLoader.new(environment) end |
#node(name) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/puppet/resource/type_collection.rb', line 127 def node(name) name = munge_name(name) node = @nodes[name] if node return node end @node_list.each do |n| next unless n.name_is_regex? return n if n.match(name) end nil end |
#node_exists?(name) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
142 143 144 |
# File 'lib/puppet/resource/type_collection.rb', line 142 def node_exists?(name) @nodes[munge_name(name)] end |
#nodes? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
146 147 148 |
# File 'lib/puppet/resource/type_collection.rb', line 146 def nodes? @nodes.length > 0 end |
#parse_failed? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
206 207 208 |
# File 'lib/puppet/resource/type_collection.rb', line 206 def parse_failed? @parse_failed end |
#replace_settings(instance) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Replaces the known settings with a new instance (that must be named ‘settings’). This is primarily needed for testing purposes. Also see PUP-5954 as it makes it illegal to merge classes other than the ” (main) class. Prior to this change settings where always merged rather than being defined from scratch for many testing scenarios not having a complete side effect free setup for compilation.
97 98 99 |
# File 'lib/puppet/resource/type_collection.rb', line 97 def replace_settings(instance) @hostclasses['settings'] = instance end |
#site(_) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
119 120 121 |
# File 'lib/puppet/resource/type_collection.rb', line 119 def site(_) @sites[0] end |
#version ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/puppet/resource/type_collection.rb', line 210 def version if !defined?(@version) if environment.config_version.nil? || environment.config_version == "" @version = Time.now.to_i else @version = Puppet::Util::Execution.execute([environment.config_version]).to_s.strip end end @version rescue Puppet::ExecutionFailure => e raise Puppet::ParseError, _("Execution of config_version command `%{cmd}` failed: %{message}") % { cmd: environment.config_version, message: e. }, e.backtrace end |