puppet 3.1.0.rc1 → 3.1.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of puppet might be problematic. Click here for more details.
- data/COMMITTERS.md +185 -0
- data/ext/debian/changelog.erb +6 -0
- data/ext/debian/puppet-common.manpages +1 -0
- data/ext/debian/puppet.default +3 -1
- data/ext/debian/puppetmaster.default +6 -3
- data/ext/redhat/puppet.spec.erb +16 -5
- data/lib/puppet.rb +3 -5
- data/lib/puppet/defaults.rb +6 -5
- data/lib/puppet/dsl.rb +3 -7
- data/lib/puppet/dsl/resource_api.rb +120 -0
- data/lib/puppet/dsl/resource_type_api.rb +34 -0
- data/lib/puppet/module_tool.rb +23 -11
- data/lib/puppet/network/formats.rb +1 -1
- data/lib/puppet/node/environment.rb +1 -3
- data/lib/puppet/parser/ast/definition.rb +5 -2
- data/lib/puppet/parser/ast/hostclass.rb +3 -2
- data/lib/puppet/parser/ast/node.rb +5 -2
- data/lib/puppet/parser/ast/resourceparam.rb +1 -1
- data/lib/puppet/parser/compiler.rb +0 -10
- data/lib/puppet/parser/lexer.rb +50 -39
- data/lib/puppet/parser/parser_support.rb +29 -11
- data/lib/puppet/parser/scope.rb +2 -2
- data/lib/puppet/parser/type_loader.rb +7 -31
- data/lib/puppet/provider/package/openbsd.rb +16 -2
- data/lib/puppet/provider/package/pip.rb +11 -2
- data/lib/puppet/provider/package/portage.rb +29 -12
- data/lib/puppet/provider/service/launchd.rb +19 -14
- data/lib/puppet/provider/service/upstart.rb +1 -1
- data/lib/puppet/provider/user/hpux.rb +37 -2
- data/lib/puppet/resource.rb +25 -38
- data/lib/puppet/resource/type.rb +6 -14
- data/lib/puppet/settings.rb +1 -1
- data/lib/puppet/ssl/certificate_authority.rb +4 -1
- data/lib/puppet/ssl/certificate_request.rb +3 -1
- data/lib/puppet/ssl/certificate_signer.rb +22 -0
- data/lib/puppet/type.rb +4 -4
- data/lib/puppet/util/methodhelper.rb +0 -19
- data/lib/puppet/util/rubygems.rb +3 -1
- data/lib/puppet/util/selinux.rb +1 -6
- data/lib/puppet/version.rb +1 -1
- data/man/man5/puppet.conf.5 +81 -95
- data/man/man8/extlookup2hiera.8 +23 -0
- data/man/man8/puppet-agent.8 +3 -3
- data/man/man8/puppet-apply.8 +2 -6
- data/man/man8/puppet-ca.8 +6 -7
- data/man/man8/puppet-catalog.8 +6 -7
- data/man/man8/puppet-cert.8 +4 -4
- data/man/man8/puppet-certificate.8 +6 -7
- data/man/man8/puppet-certificate_request.8 +6 -7
- data/man/man8/puppet-certificate_revocation_list.8 +6 -7
- data/man/man8/puppet-config.8 +4 -8
- data/man/man8/puppet-describe.8 +1 -1
- data/man/man8/puppet-device.8 +1 -1
- data/man/man8/puppet-doc.8 +3 -3
- data/man/man8/puppet-facts.8 +4 -8
- data/man/man8/puppet-file.8 +6 -7
- data/man/man8/puppet-filebucket.8 +1 -1
- data/man/man8/puppet-help.8 +2 -6
- data/man/man8/puppet-inspect.8 +1 -1
- data/man/man8/puppet-instrumentation_data.8 +3 -7
- data/man/man8/puppet-instrumentation_listener.8 +3 -7
- data/man/man8/puppet-instrumentation_probe.8 +3 -7
- data/man/man8/puppet-key.8 +6 -7
- data/man/man8/puppet-kick.8 +5 -1
- data/man/man8/puppet-man.8 +2 -6
- data/man/man8/puppet-master.8 +2 -2
- data/man/man8/puppet-module.8 +11 -9
- data/man/man8/puppet-node.8 +38 -37
- data/man/man8/puppet-parser.8 +2 -6
- data/man/man8/puppet-plugin.8 +2 -6
- data/man/man8/puppet-queue.8 +1 -1
- data/man/man8/puppet-report.8 +3 -7
- data/man/man8/puppet-resource.8 +1 -1
- data/man/man8/puppet-resource_type.8 +3 -7
- data/man/man8/puppet-secret_agent.8 +2 -6
- data/man/man8/puppet-status.8 +3 -7
- data/man/man8/puppet.8 +1 -1
- data/spec/integration/parser/ruby_manifest_spec.rb +128 -0
- data/spec/lib/puppet_spec/compiler.rb +0 -11
- data/spec/spec_helper.rb +3 -4
- data/spec/unit/dsl/resource_api_spec.rb +180 -0
- data/spec/unit/dsl/resource_type_api_spec.rb +53 -0
- data/spec/unit/module_tool_spec.rb +79 -46
- data/spec/unit/network/formats_spec.rb +4 -0
- data/spec/unit/node/environment_spec.rb +0 -13
- data/spec/unit/parser/compiler_spec.rb +0 -26
- data/spec/unit/parser/parser_spec.rb +14 -0
- data/spec/unit/parser/type_loader_spec.rb +4 -15
- data/spec/unit/provider/package/openbsd_spec.rb +148 -35
- data/spec/unit/provider/package/pip_spec.rb +49 -25
- data/spec/unit/provider/package/portage_spec.rb +65 -0
- data/spec/unit/provider/service/launchd_spec.rb +6 -5
- data/spec/unit/provider/user/hpux_spec.rb +39 -11
- data/spec/unit/provider/user/useradd_spec.rb +14 -14
- data/spec/unit/resource/type_spec.rb +7 -49
- data/spec/unit/resource_spec.rb +0 -32
- data/spec/unit/ssl/certificate_request_spec.rb +18 -0
- data/spec/unit/util/rubygems_spec.rb +1 -1
- data/spec/unit/util/selinux_spec.rb +0 -2
- metadata +17 -50
- data/lib/puppet/dsl/actions.rb +0 -283
- data/lib/puppet/dsl/blank_slate.rb +0 -55
- data/lib/puppet/dsl/context.rb +0 -393
- data/lib/puppet/dsl/parser.rb +0 -57
- data/lib/puppet/dsl/resource_decorator.rb +0 -56
- data/lib/puppet/dsl/resource_reference.rb +0 -95
- data/lib/puppet/dsl/type_reference.rb +0 -102
- data/lib/puppet/util/manifest_filetype_helper.rb +0 -22
- data/spec/integration/dsl/classes_spec.rb +0 -191
- data/spec/integration/dsl/defaults_spec.rb +0 -38
- data/spec/integration/dsl/definitions_spec.rb +0 -73
- data/spec/integration/dsl/functions_spec.rb +0 -95
- data/spec/integration/dsl/nodes_spec.rb +0 -96
- data/spec/integration/dsl/params_spec.rb +0 -146
- data/spec/integration/dsl/relationships_spec.rb +0 -46
- data/spec/integration/dsl/resources_spec.rb +0 -202
- data/spec/integration/dsl/type_loading_spec.rb +0 -64
- data/spec/lib/matchers/catalog.rb +0 -50
- data/spec/lib/puppet_spec/dsl.rb +0 -29
- data/spec/unit/dsl/actions_spec.rb +0 -402
- data/spec/unit/dsl/blank_slate_spec.rb +0 -27
- data/spec/unit/dsl/context_spec.rb +0 -678
- data/spec/unit/dsl/parser_spec.rb +0 -56
- data/spec/unit/dsl/resource_decorator_spec.rb +0 -94
- data/spec/unit/dsl/resource_reference_spec.rb +0 -150
- data/spec/unit/dsl/type_reference_spec.rb +0 -164
- data/spec/unit/util/manifest_filetype_helper_spec.rb +0 -29
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'puppet/resource/type'
|
2
|
+
|
3
|
+
# Type of the objects inside of which pure ruby manifest files are
|
4
|
+
# executed. Provides methods for creating defines, hostclasses, and
|
5
|
+
# nodes.
|
6
|
+
class Puppet::DSL::ResourceTypeAPI
|
7
|
+
def initialize
|
8
|
+
@__created_ast_objects__ = []
|
9
|
+
end
|
10
|
+
|
11
|
+
def define(name, *args, &block)
|
12
|
+
args = args.inject([]) do |result, item|
|
13
|
+
if item.is_a?(Hash)
|
14
|
+
item.each { |p, v| result << [p, v] }
|
15
|
+
else
|
16
|
+
result << item
|
17
|
+
end
|
18
|
+
result
|
19
|
+
end
|
20
|
+
@__created_ast_objects__.push Puppet::Parser::AST::Definition.new(name, {:arguments => args}, &block)
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
|
24
|
+
def hostclass(name, options = {}, &block)
|
25
|
+
@__created_ast_objects__.push Puppet::Parser::AST::Hostclass.new(name, options, &block)
|
26
|
+
nil
|
27
|
+
end
|
28
|
+
|
29
|
+
def node(name, options = {}, &block)
|
30
|
+
name = [name] unless name.is_a?(Array)
|
31
|
+
@__created_ast_objects__.push Puppet::Parser::AST::Node.new(name, options, &block)
|
32
|
+
nil
|
33
|
+
end
|
34
|
+
end
|
data/lib/puppet/module_tool.rb
CHANGED
@@ -104,20 +104,32 @@ module Puppet
|
|
104
104
|
|
105
105
|
def self.set_option_defaults(options)
|
106
106
|
sep = File::PATH_SEPARATOR
|
107
|
-
if options[:target_dir]
|
108
|
-
options[:target_dir] = File.expand_path(options[:target_dir])
|
109
|
-
end
|
110
107
|
|
111
|
-
|
108
|
+
if options[:environment]
|
109
|
+
Puppet.settings[:environment] = options[:environment]
|
110
|
+
else
|
111
|
+
options[:environment] = Puppet.settings[:environment]
|
112
|
+
end
|
112
113
|
|
113
|
-
options[:modulepath]
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
114
|
+
if options[:modulepath]
|
115
|
+
Puppet.settings[:modulepath] = options[:modulepath]
|
116
|
+
else
|
117
|
+
# (#14872) make sure the module path of the desired environment is used
|
118
|
+
# when determining the default value of the --target-dir option
|
119
|
+
Puppet.settings[:modulepath] = options[:modulepath] =
|
120
|
+
Puppet.settings.value(:modulepath, options[:environment])
|
121
|
+
end
|
118
122
|
|
119
|
-
options[:target_dir]
|
120
|
-
|
123
|
+
if options[:target_dir]
|
124
|
+
options[:target_dir] = File.expand_path(options[:target_dir])
|
125
|
+
# prepend the target dir to the module path
|
126
|
+
Puppet.settings[:modulepath] = options[:modulepath] =
|
127
|
+
options[:target_dir] + sep + options[:modulepath]
|
128
|
+
else
|
129
|
+
# default to the first component of the module path
|
130
|
+
options[:target_dir] =
|
131
|
+
File.expand_path(options[:modulepath].split(sep).first)
|
132
|
+
end
|
121
133
|
end
|
122
134
|
end
|
123
135
|
end
|
@@ -148,7 +148,7 @@ Puppet::Network::FormatHandler.create(:console,
|
|
148
148
|
# Simple hash to table
|
149
149
|
if datum.is_a? Hash and datum.keys.all? { |x| x.is_a? String or x.is_a? Numeric }
|
150
150
|
output = ''
|
151
|
-
column_a = datum.map
|
151
|
+
column_a = datum.empty? ? 2 : datum.map{ |k,v| k.to_s.length }.max + 2
|
152
152
|
column_b = 79 - column_a
|
153
153
|
datum.sort_by { |k,v| k.to_s } .each do |key, value|
|
154
154
|
output << key.to_s.ljust(column_a)
|
@@ -1,9 +1,7 @@
|
|
1
1
|
require 'puppet/util'
|
2
2
|
require 'puppet/util/cacher'
|
3
|
-
require 'puppet/util/manifest_filetype_helper'
|
4
3
|
require 'monitor'
|
5
4
|
|
6
|
-
|
7
5
|
# Just define it, so this class has fewer load dependencies.
|
8
6
|
class Puppet::Node
|
9
7
|
end
|
@@ -218,7 +216,7 @@ class Puppet::Node::Environment
|
|
218
216
|
private
|
219
217
|
|
220
218
|
def perform_initial_import
|
221
|
-
return empty_parse_result if Puppet.settings[:ignoreimport]
|
219
|
+
return empty_parse_result if Puppet.settings[:ignoreimport]
|
222
220
|
parser = Puppet::Parser::Parser.new(self)
|
223
221
|
if code = Puppet.settings.uninterpolated_value(:code, name.to_s) and code != ""
|
224
222
|
parser.string = code
|
@@ -3,12 +3,15 @@ require 'puppet/parser/ast/top_level_construct'
|
|
3
3
|
class Puppet::Parser::AST::Definition < Puppet::Parser::AST::TopLevelConstruct
|
4
4
|
attr_accessor :context
|
5
5
|
|
6
|
-
def initialize(name, context = {})
|
6
|
+
def initialize(name, context = {}, &ruby_code)
|
7
7
|
@name = name
|
8
8
|
@context = context
|
9
|
+
@ruby_code = ruby_code
|
9
10
|
end
|
10
11
|
|
11
12
|
def instantiate(modname)
|
12
|
-
|
13
|
+
new_definition = Puppet::Resource::Type.new(:definition, @name, @context.merge(:module_name => modname))
|
14
|
+
new_definition.ruby_code = @ruby_code if @ruby_code
|
15
|
+
[new_definition]
|
13
16
|
end
|
14
17
|
end
|
@@ -3,13 +3,15 @@ require 'puppet/parser/ast/top_level_construct'
|
|
3
3
|
class Puppet::Parser::AST::Hostclass < Puppet::Parser::AST::TopLevelConstruct
|
4
4
|
attr_accessor :name, :context
|
5
5
|
|
6
|
-
def initialize(name, context = {})
|
6
|
+
def initialize(name, context = {}, &ruby_code)
|
7
7
|
@context = context
|
8
8
|
@name = name
|
9
|
+
@ruby_code = ruby_code
|
9
10
|
end
|
10
11
|
|
11
12
|
def instantiate(modname)
|
12
13
|
new_class = Puppet::Resource::Type.new(:hostclass, @name, @context.merge(:module_name => modname))
|
14
|
+
new_class.ruby_code = @ruby_code if @ruby_code
|
13
15
|
all_types = [new_class]
|
14
16
|
if code
|
15
17
|
code.each do |nested_ast_node|
|
@@ -18,7 +20,6 @@ class Puppet::Parser::AST::Hostclass < Puppet::Parser::AST::TopLevelConstruct
|
|
18
20
|
end
|
19
21
|
end
|
20
22
|
end
|
21
|
-
|
22
23
|
return all_types
|
23
24
|
end
|
24
25
|
|
@@ -3,15 +3,18 @@ require 'puppet/parser/ast/top_level_construct'
|
|
3
3
|
class Puppet::Parser::AST::Node < Puppet::Parser::AST::TopLevelConstruct
|
4
4
|
attr_accessor :names, :context
|
5
5
|
|
6
|
-
def initialize(names, context = {})
|
6
|
+
def initialize(names, context = {}, &ruby_code)
|
7
7
|
raise ArgumentError, "names should be an array" unless names.is_a? Array
|
8
8
|
@names = names
|
9
9
|
@context = context
|
10
|
+
@ruby_code = ruby_code
|
10
11
|
end
|
11
12
|
|
12
13
|
def instantiate(modname)
|
13
14
|
@names.collect do |name|
|
14
|
-
Puppet::Resource::Type.new(:node, name, @context.merge(:module_name => modname))
|
15
|
+
new_node = Puppet::Resource::Type.new(:node, name, @context.merge(:module_name => modname))
|
16
|
+
new_node.ruby_code = @ruby_code if @ruby_code
|
17
|
+
new_node
|
15
18
|
end
|
16
19
|
end
|
17
20
|
end
|
@@ -11,7 +11,7 @@ class Puppet::Parser::AST
|
|
11
11
|
|
12
12
|
# Return the parameter and the value.
|
13
13
|
def evaluate(scope)
|
14
|
-
Puppet::Parser::Resource::Param.new(
|
14
|
+
return Puppet::Parser::Resource::Param.new(
|
15
15
|
:name => @param,
|
16
16
|
:value => @value.safeevaluate(scope),
|
17
17
|
:source => scope.source, :line => self.line, :file => self.file,
|
@@ -3,10 +3,8 @@ require 'forwardable'
|
|
3
3
|
require 'puppet/node'
|
4
4
|
require 'puppet/resource/catalog'
|
5
5
|
require 'puppet/util/errors'
|
6
|
-
require 'puppet/util/manifest_filetype_helper'
|
7
6
|
|
8
7
|
require 'puppet/resource/type_collection_helper'
|
9
|
-
require 'puppet/dsl/parser'
|
10
8
|
|
11
9
|
# Maintain a graph of scopes, along with a bunch of data
|
12
10
|
# about the individual catalog we're compiling.
|
@@ -92,7 +90,6 @@ class Puppet::Parser::Compiler
|
|
92
90
|
# This is the main entry into our catalog.
|
93
91
|
def compile
|
94
92
|
# Set the client's parameters into the top scope.
|
95
|
-
|
96
93
|
set_node_parameters
|
97
94
|
create_settings_scope
|
98
95
|
|
@@ -113,10 +110,6 @@ class Puppet::Parser::Compiler
|
|
113
110
|
|
114
111
|
def_delegator :@collections, :delete, :delete_collection
|
115
112
|
|
116
|
-
def assign_ruby_code(file)
|
117
|
-
Puppet::DSL::Parser.prepare_for_evaluation @main, File.read(file), file
|
118
|
-
end
|
119
|
-
|
120
113
|
# Return the node's environment.
|
121
114
|
def environment
|
122
115
|
unless defined?(@environment)
|
@@ -286,9 +279,6 @@ class Puppet::Parser::Compiler
|
|
286
279
|
|
287
280
|
add_resource(@topscope, @main_resource)
|
288
281
|
|
289
|
-
file = Puppet.settings.value :manifest, environment
|
290
|
-
assign_ruby_code file if Puppet::Util::ManifestFiletypeHelper.is_ruby_filename? file
|
291
|
-
|
292
282
|
@main_resource.evaluate
|
293
283
|
end
|
294
284
|
|
data/lib/puppet/parser/lexer.rb
CHANGED
@@ -25,6 +25,8 @@ class Puppet::Parser::Lexer
|
|
25
25
|
end
|
26
26
|
|
27
27
|
class Token
|
28
|
+
ALWAYS_ACCEPTABLE = Proc.new { |context| true }
|
29
|
+
|
28
30
|
include Puppet::Util::MethodHelper
|
29
31
|
|
30
32
|
attr_accessor :regex, :name, :string, :skip, :incr_line, :skip_text, :accumulate
|
@@ -40,6 +42,7 @@ class Puppet::Parser::Lexer
|
|
40
42
|
end
|
41
43
|
|
42
44
|
set_options(options)
|
45
|
+
@acceptable_when = ALWAYS_ACCEPTABLE
|
43
46
|
end
|
44
47
|
|
45
48
|
def to_s
|
@@ -47,8 +50,15 @@ class Puppet::Parser::Lexer
|
|
47
50
|
end
|
48
51
|
|
49
52
|
def acceptable?(context={})
|
50
|
-
|
51
|
-
|
53
|
+
@acceptable_when.call(context)
|
54
|
+
end
|
55
|
+
|
56
|
+
# Define when the token is able to match.
|
57
|
+
# This provides context that cannot be expressed otherwise, such as feature flags.
|
58
|
+
#
|
59
|
+
# @param block [Proc] a proc that given a context returns a boolean
|
60
|
+
def acceptable_when(block)
|
61
|
+
@acceptable_when = block
|
52
62
|
end
|
53
63
|
end
|
54
64
|
|
@@ -157,15 +167,40 @@ class Puppet::Parser::Lexer
|
|
157
167
|
"<boolean>" => :BOOLEAN
|
158
168
|
)
|
159
169
|
|
170
|
+
module Contextual
|
171
|
+
QUOTE_TOKENS = [:DQPRE,:DQMID]
|
172
|
+
REGEX_INTRODUCING_TOKENS = [:NODE,:LBRACE,:RBRACE,:MATCH,:NOMATCH,:COMMA]
|
173
|
+
|
174
|
+
NOT_INSIDE_QUOTES = Proc.new do |context|
|
175
|
+
!QUOTE_TOKENS.include? context[:after]
|
176
|
+
end
|
177
|
+
|
178
|
+
INSIDE_QUOTES = Proc.new do |context|
|
179
|
+
QUOTE_TOKENS.include? context[:after]
|
180
|
+
end
|
181
|
+
|
182
|
+
IN_REGEX_POSITION = Proc.new do |context|
|
183
|
+
REGEX_INTRODUCING_TOKENS.include? context[:after]
|
184
|
+
end
|
185
|
+
|
186
|
+
IN_STRING_INTERPOLATION = Proc.new do |context|
|
187
|
+
context[:string_interpolation_depth] > 0
|
188
|
+
end
|
189
|
+
|
190
|
+
DASHED_VARIABLES_ALLOWED = Proc.new do |context|
|
191
|
+
Puppet[:allow_variables_with_dashes]
|
192
|
+
end
|
193
|
+
|
194
|
+
VARIABLE_AND_DASHES_ALLOWED = Proc.new do |context|
|
195
|
+
Contextual::DASHED_VARIABLES_ALLOWED.call(context) and TOKENS[:VARIABLE].acceptable?(context)
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
160
199
|
# Numbers are treated separately from names, so that they may contain dots.
|
161
200
|
TOKENS.add_token :NUMBER, %r{\b(?:0[xX][0-9A-Fa-f]+|0?\d+(?:\.\d+)?(?:[eE]-?\d+)?)\b} do |lexer, value|
|
162
201
|
[TOKENS[:NAME], value]
|
163
202
|
end
|
164
|
-
|
165
|
-
def (TOKENS[:NUMBER]).acceptable?(context={})
|
166
|
-
![:DQPRE,:DQMID].include? context[:after]
|
167
|
-
end
|
168
|
-
#:startdoc:
|
203
|
+
TOKENS[:NUMBER].acceptable_when Contextual::NOT_INSIDE_QUOTES
|
169
204
|
|
170
205
|
TOKENS.add_token :NAME, %r{((::)?[a-z0-9][-\w]*)(::[a-z0-9][-\w]*)*} do |lexer, value|
|
171
206
|
string_token = self
|
@@ -179,13 +214,9 @@ class Puppet::Parser::Lexer
|
|
179
214
|
end
|
180
215
|
[string_token, value]
|
181
216
|
end
|
182
|
-
[:NAME
|
183
|
-
|
184
|
-
|
185
|
-
![:DQPRE,:DQMID].include? context[:after]
|
186
|
-
end
|
187
|
-
#:startdoc:
|
188
|
-
}
|
217
|
+
[:NAME, :CLASSREF].each do |name_token|
|
218
|
+
TOKENS[name_token].acceptable_when Contextual::NOT_INSIDE_QUOTES
|
219
|
+
end
|
189
220
|
|
190
221
|
TOKENS.add_token :COMMENT, %r{#.*}, :accumulate => true, :skip => true do |lexer,value|
|
191
222
|
value.sub!(/# ?/,'')
|
@@ -208,12 +239,7 @@ class Puppet::Parser::Lexer
|
|
208
239
|
regex = value.sub(%r{\A/}, "").sub(%r{/\Z}, '').gsub("\\/", "/")
|
209
240
|
[self, Regexp.new(regex)]
|
210
241
|
end
|
211
|
-
|
212
|
-
#:stopdoc: # Issue #4161
|
213
|
-
def (TOKENS[:REGEX]).acceptable?(context={})
|
214
|
-
[:NODE,:LBRACE,:RBRACE,:MATCH,:NOMATCH,:COMMA].include? context[:after]
|
215
|
-
end
|
216
|
-
#:startdoc:
|
242
|
+
TOKENS[:REGEX].acceptable_when Contextual::IN_REGEX_POSITION
|
217
243
|
|
218
244
|
TOKENS.add_token :RETURN, "\n", :skip => true, :incr_line => true, :skip_text => true
|
219
245
|
|
@@ -231,20 +257,14 @@ class Puppet::Parser::Lexer
|
|
231
257
|
TOKENS.add_token :DQCONT, /\}/ do |lexer, value|
|
232
258
|
lexer.tokenize_interpolated_string(DQ_continuation_token_types)
|
233
259
|
end
|
234
|
-
|
235
|
-
def (TOKENS[:DQCONT]).acceptable?(context={})
|
236
|
-
context[:string_interpolation_depth] > 0
|
237
|
-
end
|
238
|
-
#:startdoc:
|
260
|
+
TOKENS[:DQCONT].acceptable_when Contextual::IN_STRING_INTERPOLATION
|
239
261
|
|
240
262
|
TOKENS.add_token :DOLLAR_VAR_WITH_DASH, %r{\$(?:::)?(?:[-\w]+::)*[-\w]+} do |lexer, value|
|
241
263
|
lexer.warn_if_variable_has_hyphen(value)
|
242
264
|
|
243
265
|
[TOKENS[:VARIABLE], value[1..-1]]
|
244
266
|
end
|
245
|
-
|
246
|
-
Puppet[:allow_variables_with_dashes]
|
247
|
-
end
|
267
|
+
TOKENS[:DOLLAR_VAR_WITH_DASH].acceptable_when Contextual::DASHED_VARIABLES_ALLOWED
|
248
268
|
|
249
269
|
TOKENS.add_token :DOLLAR_VAR, %r{\$(::)?(\w+::)*\w+} do |lexer, value|
|
250
270
|
[TOKENS[:VARIABLE],value[1..-1]]
|
@@ -255,19 +275,10 @@ class Puppet::Parser::Lexer
|
|
255
275
|
|
256
276
|
[TOKENS[:VARIABLE], value]
|
257
277
|
end
|
258
|
-
|
259
|
-
def (TOKENS[:VARIABLE_WITH_DASH]).acceptable?(context={})
|
260
|
-
Puppet[:allow_variables_with_dashes] and TOKENS[:VARIABLE].acceptable?(context)
|
261
|
-
end
|
262
|
-
#:startdoc:
|
278
|
+
TOKENS[:VARIABLE_WITH_DASH].acceptable_when Contextual::VARIABLE_AND_DASHES_ALLOWED
|
263
279
|
|
264
280
|
TOKENS.add_token :VARIABLE, %r{(::)?(\w+::)*\w+}
|
265
|
-
|
266
|
-
def (TOKENS[:VARIABLE]).acceptable?(context={})
|
267
|
-
[:DQPRE,:DQMID].include? context[:after]
|
268
|
-
end
|
269
|
-
#:startdoc:
|
270
|
-
|
281
|
+
TOKENS[:VARIABLE].acceptable_when Contextual::INSIDE_QUOTES
|
271
282
|
|
272
283
|
TOKENS.sort_tokens
|
273
284
|
|
@@ -136,18 +136,36 @@ class Puppet::Parser::Parser
|
|
136
136
|
|
137
137
|
# how should I do error handling here?
|
138
138
|
def parse(string = nil)
|
139
|
-
self.
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
139
|
+
if self.file =~ /\.rb$/
|
140
|
+
main = parse_ruby_file
|
141
|
+
else
|
142
|
+
self.string = string if string
|
143
|
+
begin
|
144
|
+
@yydebug = false
|
145
|
+
main = yyparse(@lexer,:scan)
|
146
|
+
rescue Puppet::ParseError => except
|
147
|
+
except.line ||= @lexer.line
|
148
|
+
except.file ||= @lexer.file
|
149
|
+
raise except
|
150
|
+
rescue => except
|
151
|
+
raise Puppet::ParseError.new(except.message, @lexer.file, @lexer.line, except)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
# Store the results as the top-level class.
|
155
|
+
return Puppet::Parser::AST::Hostclass.new('', :code => main)
|
150
156
|
ensure
|
151
157
|
@lexer.clear
|
152
158
|
end
|
159
|
+
|
160
|
+
def parse_ruby_file
|
161
|
+
Puppet.deprecation_warning("Use of the Ruby DSL is deprecated.")
|
162
|
+
|
163
|
+
# Execute the contents of the file inside its own "main" object so
|
164
|
+
# that it can call methods in the resource type API.
|
165
|
+
main_object = Puppet::DSL::ResourceTypeAPI.new
|
166
|
+
main_object.instance_eval(File.read(self.file))
|
167
|
+
|
168
|
+
# Then extract any types that were created.
|
169
|
+
Puppet::Parser::AST::ASTArray.new :children => main_object.instance_eval { @__created_ast_objects__ }
|
170
|
+
end
|
153
171
|
end
|
data/lib/puppet/parser/scope.rb
CHANGED
@@ -379,7 +379,7 @@ class Puppet::Parser::Scope
|
|
379
379
|
|
380
380
|
if options[:append]
|
381
381
|
table[name] = append_value(undef_as('', self[name]), value)
|
382
|
-
else
|
382
|
+
else
|
383
383
|
table[name] = value
|
384
384
|
end
|
385
385
|
end
|
@@ -407,7 +407,7 @@ class Puppet::Parser::Scope
|
|
407
407
|
bound_value.merge(new_value)
|
408
408
|
else
|
409
409
|
if bound_value.is_a?(Hash)
|
410
|
-
raise ArgumentError, "Trying to append to a hash with something which is not a hash is unsupported"
|
410
|
+
raise ArgumentError, "Trying to append to a hash with something which is not a hash is unsupported"
|
411
411
|
end
|
412
412
|
bound_value + new_value
|
413
413
|
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'find'
|
2
2
|
require 'forwardable'
|
3
3
|
require 'puppet/node/environment'
|
4
|
-
require 'puppet/dsl/parser'
|
5
|
-
require 'puppet/util/manifest_filetype_helper'
|
6
4
|
|
7
5
|
class Puppet::Parser::TypeLoader
|
8
6
|
extend Forwardable
|
@@ -84,38 +82,17 @@ class Puppet::Parser::TypeLoader
|
|
84
82
|
end
|
85
83
|
|
86
84
|
loaded_asts = []
|
87
|
-
loaded_ruby_types = []
|
88
85
|
files.each do |file|
|
89
|
-
|
90
|
-
|
86
|
+
unless Puppet::Util.absolute_path?(file)
|
87
|
+
file = File.join(dir, file)
|
88
|
+
end
|
91
89
|
@loading_helper.do_once(file) do
|
92
|
-
|
93
|
-
known_before = known_resource_types.definitions.values +
|
94
|
-
known_resource_types.nodes.values +
|
95
|
-
known_resource_types.hostclasses.values
|
96
|
-
|
97
|
-
type = Puppet::Resource::Type.new(:hostclass, '')
|
98
|
-
begin
|
99
|
-
Puppet::DSL::Parser.prepare_for_evaluation type, File.read(file), file
|
100
|
-
rescue => e
|
101
|
-
raise Puppet::ParseError, e.message
|
102
|
-
end
|
103
|
-
type.ruby_code.each { |c| c.evaluate(nil, known_resource_types) }
|
104
|
-
|
105
|
-
known_now = known_resource_types.definitions.values +
|
106
|
-
known_resource_types.nodes.values +
|
107
|
-
known_resource_types.hostclasses.values
|
108
|
-
loaded_ruby_types = known_now - known_before
|
109
|
-
else
|
110
|
-
loaded_asts << parse_file(file)
|
111
|
-
end
|
90
|
+
loaded_asts << parse_file(file)
|
112
91
|
end
|
113
92
|
end
|
114
|
-
|
115
|
-
loaded_puppet_types = loaded_asts.inject([]) do |loaded_types, ast|
|
93
|
+
loaded_asts.inject([]) do |loaded_types, ast|
|
116
94
|
loaded_types + known_resource_types.import_ast(ast, modname)
|
117
95
|
end
|
118
|
-
loaded_ruby_types + loaded_puppet_types
|
119
96
|
end
|
120
97
|
|
121
98
|
def import_all
|
@@ -124,8 +101,7 @@ class Puppet::Parser::TypeLoader
|
|
124
101
|
# given first/foo and second/foo, only files from first/foo will be loaded.
|
125
102
|
environment.modules.each do |mod|
|
126
103
|
Find.find(mod.manifests) do |path|
|
127
|
-
if
|
128
|
-
Puppet::Util::ManifestFiletypeHelper.is_puppet_filename? path
|
104
|
+
if path =~ /\.pp$/ or path =~ /\.rb$/
|
129
105
|
import(path)
|
130
106
|
end
|
131
107
|
end
|
@@ -163,7 +139,7 @@ class Puppet::Parser::TypeLoader
|
|
163
139
|
Puppet.debug("importing '#{file}' in environment #{environment}")
|
164
140
|
parser = Puppet::Parser::Parser.new(environment)
|
165
141
|
parser.file = file
|
166
|
-
parser.parse
|
142
|
+
return parser.parse
|
167
143
|
end
|
168
144
|
|
169
145
|
private
|