Class: Puppet::Resource::TypeCollection
Instance Attribute Summary collapse
Instance Method Summary
collapse
clear_warnings, debug_once, notice_once, warnonce
Constructor Details
Returns a new instance of TypeCollection.
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/puppet/resource/type_collection.rb', line 18
def initialize(env)
@environment = env
@hostclasses = {}
@definitions = {}
@nodes = {}
@notfound = {}
@node_list = []
end
|
Instance Attribute Details
#environment ⇒ Object
6
7
8
|
# File 'lib/puppet/resource/type_collection.rb', line 6
def environment
@environment
end
|
#parse_failed ⇒ Object
7
8
9
|
# File 'lib/puppet/resource/type_collection.rb', line 7
def parse_failed
@parse_failed
end
|
Instance Method Details
#<<(thing) ⇒ Object
39
40
41
42
|
# File 'lib/puppet/resource/type_collection.rb', line 39
def <<(thing)
add(thing)
self
end
|
#add(instance) ⇒ Object
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/puppet/resource/type_collection.rb', line 44
def add(instance)
if instance.type == :hostclass and other = @hostclasses[instance.name] and other.type == :hostclass
other.merge(instance)
return other
end
method = "add_#{instance.type}"
send(method, instance)
instance.resource_type_collection = self
instance
end
|
#add_definition(instance) ⇒ Object
101
102
103
104
105
|
# File 'lib/puppet/resource/type_collection.rb', line 101
def add_definition(instance)
dupe_check(instance, @hostclasses) { |dupe| "'#{instance.name}' is already defined#{dupe.error_context} as a class; cannot redefine as a definition" }
dupe_check(instance, @definitions) { |dupe| "Definition '#{instance.name}' is already defined#{dupe.error_context}; cannot be redefined" }
@definitions[instance.name] = instance
end
|
#add_hostclass(instance) ⇒ Object
55
56
57
58
59
60
61
|
# File 'lib/puppet/resource/type_collection.rb', line 55
def add_hostclass(instance)
dupe_check(instance, @hostclasses) { |dupe| "Class '#{instance.name}' is already defined#{dupe.error_context}; cannot redefine" }
dupe_check(instance, @definitions) { |dupe| "Definition '#{instance.name}' is already defined#{dupe.error_context}; cannot be redefined as a class" }
@hostclasses[instance.name] = instance
instance
end
|
#add_node(instance) ⇒ Object
67
68
69
70
71
72
73
|
# File 'lib/puppet/resource/type_collection.rb', line 67
def add_node(instance)
dupe_check(instance, @nodes) { |dupe| "Node '#{instance.name}' is already defined#{dupe.error_context}; cannot redefine" }
@node_list << instance
@nodes[instance.name] = instance
instance
end
|
11
12
13
14
15
16
|
# File 'lib/puppet/resource/type_collection.rb', line 11
def clear
@hostclasses.clear
@definitions.clear
@nodes.clear
@notfound.clear
end
|
#definition(name) ⇒ Object
107
108
109
|
# File 'lib/puppet/resource/type_collection.rb', line 107
def definition(name)
@definitions[munge_name(name)]
end
|
#find_definition(name) ⇒ Object
119
120
121
|
# File 'lib/puppet/resource/type_collection.rb', line 119
def find_definition(name)
find_or_load(name, :definition)
end
|
#find_hostclass(name) ⇒ Object
115
116
117
|
# File 'lib/puppet/resource/type_collection.rb', line 115
def find_hostclass(name)
find_or_load(name, :hostclass)
end
|
#find_node(name) ⇒ Object
111
112
113
|
# File 'lib/puppet/resource/type_collection.rb', line 111
def find_node(name)
@nodes[munge_name(name)]
end
|
#hostclass(name) ⇒ Object
63
64
65
|
# File 'lib/puppet/resource/type_collection.rb', line 63
def hostclass(name)
@hostclasses[munge_name(name)]
end
|
#import_ast(ast, modname) ⇒ Object
29
30
31
32
33
|
# File 'lib/puppet/resource/type_collection.rb', line 29
def import_ast(ast, modname)
ast.instantiate(modname).each do |instance|
add(instance)
end
end
|
35
36
37
|
# File 'lib/puppet/resource/type_collection.rb', line 35
def inspect
"TypeCollection" + { :hostclasses => @hostclasses.keys, :definitions => @definitions.keys, :nodes => @nodes.keys }.inspect
end
|
75
76
77
|
# File 'lib/puppet/resource/type_collection.rb', line 75
def loader
@loader ||= Puppet::Parser::TypeLoader.new(environment)
end
|
#node(name) ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/puppet/resource/type_collection.rb', line 79
def node(name)
name = munge_name(name)
if node = @nodes[name]
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
93
94
95
|
# File 'lib/puppet/resource/type_collection.rb', line 93
def node_exists?(name)
@nodes[munge_name(name)]
end
|
#nodes? ⇒ Boolean
97
98
99
|
# File 'lib/puppet/resource/type_collection.rb', line 97
def nodes?
@nodes.length > 0
end
|
#parse_failed? ⇒ Boolean
129
130
131
|
# File 'lib/puppet/resource/type_collection.rb', line 129
def parse_failed?
@parse_failed
end
|
133
134
135
136
137
138
139
140
141
142
143
144
145
|
# File 'lib/puppet/resource/type_collection.rb', line 133
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]).strip
end
end
@version
rescue Puppet::ExecutionFailure => e
raise Puppet::ParseError, "Execution of config_version command `#{environment.config_version}` failed: #{e.message}", e.backtrace
end
|