puppet-resource_api 1.9.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +57 -52
- data/lib/puppet/resource_api/base_context.rb +11 -7
- data/lib/puppet/resource_api/data_type_handling.rb +15 -19
- data/lib/puppet/resource_api/glue.rb +4 -7
- data/lib/puppet/resource_api/parameter.rb +2 -2
- data/lib/puppet/resource_api/property.rb +9 -14
- data/lib/puppet/resource_api/provider_get_cache.rb +41 -0
- data/lib/puppet/resource_api/puppet_context.rb +1 -0
- data/lib/puppet/resource_api/simple_provider.rb +19 -19
- data/lib/puppet/resource_api/transport/wrapper.rb +5 -3
- data/lib/puppet/resource_api/transport.rb +24 -31
- data/lib/puppet/resource_api/type_definition.rb +38 -45
- data/lib/puppet/resource_api/value_creator.rb +4 -6
- data/lib/puppet/resource_api/version.rb +1 -1
- data/lib/puppet/resource_api.rb +120 -113
- data/lib/puppet/util/network_device/simple/device.rb +2 -0
- metadata +8 -3
data/lib/puppet/resource_api.rb
CHANGED
|
@@ -5,6 +5,7 @@ require 'puppet/resource_api/data_type_handling'
|
|
|
5
5
|
require 'puppet/resource_api/glue'
|
|
6
6
|
require 'puppet/resource_api/parameter'
|
|
7
7
|
require 'puppet/resource_api/property'
|
|
8
|
+
require 'puppet/resource_api/provider_get_cache'
|
|
8
9
|
require 'puppet/resource_api/puppet_context' unless RUBY_PLATFORM == 'java'
|
|
9
10
|
require 'puppet/resource_api/read_only_parameter'
|
|
10
11
|
require 'puppet/resource_api/transport'
|
|
@@ -32,9 +33,7 @@ module Puppet::ResourceApi
|
|
|
32
33
|
# this has to happen before Puppet::Type.newtype starts autoloading providers
|
|
33
34
|
# it also needs to be guarded against the namespace already being defined by something
|
|
34
35
|
# else to avoid ruby warnings
|
|
35
|
-
unless Puppet::Provider.const_defined?(class_name_from_type_name(definition[:name]), false)
|
|
36
|
-
Puppet::Provider.const_set(class_name_from_type_name(definition[:name]), Module.new)
|
|
37
|
-
end
|
|
36
|
+
Puppet::Provider.const_set(class_name_from_type_name(definition[:name]), Module.new) unless Puppet::Provider.const_defined?(class_name_from_type_name(definition[:name]), false)
|
|
38
37
|
|
|
39
38
|
Puppet::Type.newtype(definition[:name].to_sym) do
|
|
40
39
|
# The :desc value is already cleaned up by the TypeDefinition validation
|
|
@@ -65,8 +64,15 @@ module Puppet::ResourceApi
|
|
|
65
64
|
self.class.type_definition
|
|
66
65
|
end
|
|
67
66
|
|
|
68
|
-
if type_definition.feature?('remote_resource')
|
|
69
|
-
|
|
67
|
+
apply_to_device if type_definition.feature?('remote_resource')
|
|
68
|
+
|
|
69
|
+
define_singleton_method(:rsapi_provider_get_cache) do
|
|
70
|
+
# This gives a new cache per resource provider on each Puppet run:
|
|
71
|
+
@rsapi_provider_get_cache ||= Puppet::ResourceApi::ProviderGetCache.new
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def rsapi_provider_get_cache
|
|
75
|
+
self.class.rsapi_provider_get_cache
|
|
70
76
|
end
|
|
71
77
|
|
|
72
78
|
def initialize(attributes)
|
|
@@ -84,49 +90,21 @@ module Puppet::ResourceApi
|
|
|
84
90
|
# undo puppet's unwrapping of Sensitive values to provide a uniform experience for providers
|
|
85
91
|
# See https://tickets.puppetlabs.com/browse/PDK-1091 for investigation and background
|
|
86
92
|
sensitives.each do |name|
|
|
87
|
-
if attributes.key?(name) && !attributes[name].is_a?(Puppet::Pops::Types::PSensitiveType::Sensitive)
|
|
88
|
-
attributes[name] = Puppet::Pops::Types::PSensitiveType::Sensitive.new(attributes[name])
|
|
89
|
-
end
|
|
93
|
+
attributes[name] = Puppet::Pops::Types::PSensitiveType::Sensitive.new(attributes[name]) if attributes.key?(name) && !attributes[name].is_a?(Puppet::Pops::Types::PSensitiveType::Sensitive)
|
|
90
94
|
end
|
|
91
95
|
|
|
92
96
|
# $stderr.puts "B: #{attributes.inspect}"
|
|
93
|
-
if type_definition.feature?('canonicalize')
|
|
94
|
-
attributes = my_provider.canonicalize(context, [attributes])[0]
|
|
95
|
-
end
|
|
97
|
+
attributes = my_provider.canonicalize(context, [attributes])[0] if type_definition.feature?('canonicalize')
|
|
96
98
|
|
|
97
99
|
# the `Puppet::Resource::Ral.find` method, when `instances` does not return a match, uses a Hash with a `:name` key to create
|
|
98
100
|
# an "absent" resource. This is often hit by `puppet resource`. This needs to work, even if the namevar is not called `name`.
|
|
99
101
|
# This bit here relies on the default `title_patterns` (see below) to match the title back to the first (and often only) namevar
|
|
100
102
|
if type_definition.attributes[:name].nil? && attributes[:title].nil?
|
|
101
103
|
attributes[:title] = attributes.delete(:name)
|
|
102
|
-
if attributes[:title].nil? && !type_definition.namevars.empty?
|
|
103
|
-
attributes[:title] = @title
|
|
104
|
-
end
|
|
104
|
+
attributes[:title] = @title if attributes[:title].nil? && !type_definition.namevars.empty?
|
|
105
105
|
end
|
|
106
106
|
|
|
107
|
-
|
|
108
|
-
super(attributes)
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
# Override finish method to ensure scope tags (like class names) are properly inherited
|
|
112
|
-
# This is called after the resource is added to the catalog and containment is established
|
|
113
|
-
def finish
|
|
114
|
-
super if defined?(super)
|
|
115
|
-
return unless @catalog
|
|
116
|
-
|
|
117
|
-
# Use pathbuilder to tag all containing classes
|
|
118
|
-
# Pathbuilder returns the containment hierarchy; class names appear as plain strings
|
|
119
|
-
# while other resources have the format "Type[title]"
|
|
120
|
-
return unless respond_to?(:pathbuilder)
|
|
121
|
-
|
|
122
|
-
pathbuilder.each do |container|
|
|
123
|
-
next unless container.is_a?(String)
|
|
124
|
-
|
|
125
|
-
# Classes don't contain '[' or ']' characters, resources do
|
|
126
|
-
# Classes: "Test::Modules_11462", "Settings"
|
|
127
|
-
# Resources: "Stage[main]", "Firewall[001 test rule]"
|
|
128
|
-
tag(container) unless container.include?('[')
|
|
129
|
-
end
|
|
107
|
+
super
|
|
130
108
|
end
|
|
131
109
|
|
|
132
110
|
def name
|
|
@@ -151,7 +129,7 @@ module Puppet::ResourceApi
|
|
|
151
129
|
@rsapi_canonicalized_target_state ||= begin
|
|
152
130
|
# skip puppet's injected metaparams
|
|
153
131
|
actual_params = @parameters.select { |k, _v| type_definition.attributes.key? k }
|
|
154
|
-
target_state =
|
|
132
|
+
target_state = actual_params.transform_values(&:rs_value)
|
|
155
133
|
target_state = my_provider.canonicalize(context, [target_state]).first if type_definition.feature?('canonicalize')
|
|
156
134
|
target_state
|
|
157
135
|
end
|
|
@@ -162,22 +140,33 @@ module Puppet::ResourceApi
|
|
|
162
140
|
def generate
|
|
163
141
|
# If feature `custom_generate` has been set then call the generate function within the provider and return the given results
|
|
164
142
|
return unless type_definition&.feature?('custom_generate')
|
|
143
|
+
|
|
165
144
|
should_hash = rsapi_canonicalized_target_state
|
|
166
145
|
is_hash = rsapi_current_state
|
|
167
146
|
title = rsapi_title
|
|
168
147
|
|
|
169
148
|
# Ensure that a custom `generate` method has been created within the provider
|
|
170
149
|
raise(Puppet::DevError, 'No generate method found within the types provider') unless my_provider.respond_to?(:generate)
|
|
150
|
+
|
|
171
151
|
# Call the providers custom `generate` method
|
|
172
|
-
|
|
152
|
+
my_provider.generate(context, title, is_hash, should_hash)
|
|
173
153
|
|
|
174
154
|
# Return array of resources
|
|
175
|
-
rules_resources
|
|
176
155
|
end
|
|
177
156
|
|
|
178
157
|
def rsapi_current_state
|
|
179
|
-
|
|
180
|
-
|
|
158
|
+
return @rsapi_current_state if @rsapi_current_state
|
|
159
|
+
|
|
160
|
+
# If the current state is not set, then check the cache and, if a value is
|
|
161
|
+
# found, ensure it passes strict_check before allowing it to be used:
|
|
162
|
+
cached_value = rsapi_provider_get_cache.get(rsapi_title)
|
|
163
|
+
strict_check(cached_value) if cached_value
|
|
164
|
+
@rsapi_current_state = cached_value
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
def rsapi_current_state=(value)
|
|
168
|
+
rsapi_provider_get_cache.add(rsapi_title, value)
|
|
169
|
+
@rsapi_current_state = value
|
|
181
170
|
end
|
|
182
171
|
|
|
183
172
|
def to_resource
|
|
@@ -201,11 +190,11 @@ module Puppet::ResourceApi
|
|
|
201
190
|
definition[:attributes].each do |name, options|
|
|
202
191
|
type = Puppet::ResourceApi::DataTypeHandling.parse_puppet_type(
|
|
203
192
|
:name,
|
|
204
|
-
options[:type]
|
|
193
|
+
options[:type]
|
|
205
194
|
)
|
|
206
195
|
|
|
207
196
|
# skip read only vars and the namevar
|
|
208
|
-
next if [
|
|
197
|
+
next if %i[read_only namevar].include? options[:behaviour]
|
|
209
198
|
|
|
210
199
|
# skip properties if the resource is being deleted
|
|
211
200
|
next if definition[:attributes][:ensure] &&
|
|
@@ -232,7 +221,7 @@ module Puppet::ResourceApi
|
|
|
232
221
|
custom_insync_trigger_options = {
|
|
233
222
|
type: 'Enum[do_not_specify_in_manifest]',
|
|
234
223
|
desc: 'A hidden property which enables a type with custom insync to perform an insync check without specifying any insyncable properties',
|
|
235
|
-
default: 'do_not_specify_in_manifest'
|
|
224
|
+
default: 'do_not_specify_in_manifest'
|
|
236
225
|
}
|
|
237
226
|
|
|
238
227
|
type_definition.create_attribute_in(self, :rsapi_custom_insync_trigger, :newproperty, Puppet::ResourceApi::Property, custom_insync_trigger_options)
|
|
@@ -241,16 +230,12 @@ module Puppet::ResourceApi
|
|
|
241
230
|
definition[:attributes].each do |name, options|
|
|
242
231
|
# puts "#{name}: #{options.inspect}"
|
|
243
232
|
|
|
244
|
-
if options[:behaviour]
|
|
245
|
-
unless [:read_only, :namevar, :parameter, :init_only].include? options[:behaviour]
|
|
246
|
-
raise Puppet::ResourceError, "`#{options[:behaviour]}` is not a valid behaviour value"
|
|
247
|
-
end
|
|
248
|
-
end
|
|
233
|
+
raise Puppet::ResourceError, "`#{options[:behaviour]}` is not a valid behaviour value" if options[:behaviour] && !(%i[read_only namevar parameter init_only].include? options[:behaviour])
|
|
249
234
|
|
|
250
235
|
# TODO: using newparam everywhere would suppress change reporting
|
|
251
236
|
# that would allow more fine-grained reporting through context,
|
|
252
237
|
# but require more invest in hooking up the infrastructure to emulate existing data
|
|
253
|
-
if [
|
|
238
|
+
if %i[parameter namevar].include? options[:behaviour]
|
|
254
239
|
param_or_property = :newparam
|
|
255
240
|
parent = Puppet::ResourceApi::Parameter
|
|
256
241
|
elsif options[:behaviour] == :read_only
|
|
@@ -264,57 +249,77 @@ module Puppet::ResourceApi
|
|
|
264
249
|
type_definition.create_attribute_in(self, name, param_or_property, parent, options)
|
|
265
250
|
end
|
|
266
251
|
|
|
252
|
+
def self.rsapi_provider_get(names = nil)
|
|
253
|
+
# If the cache has been marked as having all instances, then just return the
|
|
254
|
+
# full contents:
|
|
255
|
+
return rsapi_provider_get_cache.all if rsapi_provider_get_cache.cached_all? && names.nil?
|
|
256
|
+
|
|
257
|
+
fetched = if type_definition.feature?('simple_get_filter')
|
|
258
|
+
my_provider.get(context, names)
|
|
259
|
+
else
|
|
260
|
+
my_provider.get(context)
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
fetched.each do |resource_hash|
|
|
264
|
+
type_definition.check_schema(resource_hash)
|
|
265
|
+
rsapi_provider_get_cache.add(build_title(type_definition, resource_hash), resource_hash)
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
if names.nil? && !type_definition.feature?('simple_get_filter')
|
|
269
|
+
# Mark the cache as having all possible instances:
|
|
270
|
+
rsapi_provider_get_cache.cached_all
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
fetched
|
|
274
|
+
end
|
|
275
|
+
|
|
267
276
|
def self.instances
|
|
268
277
|
# puts 'instances'
|
|
269
278
|
# force autoloading of the provider
|
|
270
279
|
provider(type_definition.name)
|
|
271
280
|
|
|
272
|
-
|
|
273
|
-
my_provider.get(context, [])
|
|
274
|
-
else
|
|
275
|
-
my_provider.get(context)
|
|
276
|
-
end
|
|
277
|
-
|
|
278
|
-
initial_fetch.map do |resource_hash|
|
|
279
|
-
type_definition.check_schema(resource_hash)
|
|
281
|
+
rsapi_provider_get.map do |resource_hash|
|
|
280
282
|
# allow a :title from the provider to override the default
|
|
281
283
|
result = if resource_hash.key? :title
|
|
282
284
|
new(title: resource_hash[:title])
|
|
283
285
|
else
|
|
284
286
|
new(title: build_title(type_definition, resource_hash))
|
|
285
287
|
end
|
|
288
|
+
# Cache the state in the generated resource, but unfortunately
|
|
289
|
+
# this only benefits "puppet resource", not apply runs:
|
|
286
290
|
result.cache_current_state(resource_hash)
|
|
287
291
|
result
|
|
288
292
|
end
|
|
289
293
|
end
|
|
290
294
|
|
|
291
295
|
def refresh_current_state
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
end
|
|
297
|
-
|
|
298
|
-
if @rsapi_current_state
|
|
299
|
-
type_definition.check_schema(@rsapi_current_state)
|
|
300
|
-
strict_check(@rsapi_current_state)
|
|
296
|
+
current_state = self.class.rsapi_provider_get([rsapi_title]).find { |h| namevar_match?(h) }
|
|
297
|
+
|
|
298
|
+
if current_state
|
|
299
|
+
strict_check(current_state)
|
|
301
300
|
else
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
301
|
+
current_state = if rsapi_title.is_a? Hash
|
|
302
|
+
rsapi_title.dup
|
|
303
|
+
else
|
|
304
|
+
{ title: rsapi_title }
|
|
305
|
+
end
|
|
306
|
+
current_state[:ensure] = :absent if type_definition.ensurable?
|
|
308
307
|
end
|
|
308
|
+
self.rsapi_current_state = current_state
|
|
309
309
|
end
|
|
310
310
|
|
|
311
|
-
# Use this to set the current state from the `instances` method
|
|
311
|
+
# Use this to set the current state from the `instances` method. "puppet resources"
|
|
312
|
+
# needs this to minimize provider get() calls, but during a Puppet apply run
|
|
313
|
+
# the instances() method is only used by resource generation, and resource
|
|
314
|
+
# generators use and then discard the resources created by `instances``, so this
|
|
315
|
+
# does not help with that:
|
|
312
316
|
def cache_current_state(resource_hash)
|
|
313
|
-
|
|
314
|
-
strict_check(
|
|
317
|
+
self.rsapi_current_state = resource_hash
|
|
318
|
+
strict_check(resource_hash)
|
|
315
319
|
end
|
|
316
320
|
|
|
317
321
|
def retrieve
|
|
322
|
+
refresh_current_state unless rsapi_current_state
|
|
318
323
|
Puppet.debug("Current State: #{rsapi_current_state.inspect}")
|
|
319
324
|
|
|
320
325
|
result = Puppet::Resource.new(self.class, title, parameters: rsapi_current_state)
|
|
@@ -338,17 +343,18 @@ module Puppet::ResourceApi
|
|
|
338
343
|
# puts 'flush'
|
|
339
344
|
target_state = rsapi_canonicalized_target_state
|
|
340
345
|
|
|
341
|
-
retrieve unless
|
|
346
|
+
retrieve unless rsapi_current_state
|
|
342
347
|
|
|
343
|
-
return if
|
|
348
|
+
return if rsapi_current_state == target_state
|
|
344
349
|
|
|
345
350
|
Puppet.debug("Target State: #{target_state.inspect}")
|
|
346
351
|
|
|
347
352
|
# enforce init_only attributes
|
|
348
|
-
if Puppet.settings[:strict] != :off &&
|
|
353
|
+
if Puppet.settings[:strict] != :off && rsapi_current_state && (rsapi_current_state[:ensure] == 'present' && target_state[:ensure] == 'present')
|
|
349
354
|
target_state.each do |name, value|
|
|
350
|
-
next unless type_definition.attributes[name][:behaviour] == :init_only && value !=
|
|
351
|
-
|
|
355
|
+
next unless type_definition.attributes[name][:behaviour] == :init_only && value != rsapi_current_state[name]
|
|
356
|
+
|
|
357
|
+
message = "Attempting to change `#{name}` init_only attribute value from `#{rsapi_current_state[name]}` to `#{value}`"
|
|
352
358
|
case Puppet.settings[:strict]
|
|
353
359
|
when :warning
|
|
354
360
|
Puppet.warning(message)
|
|
@@ -359,9 +365,9 @@ module Puppet::ResourceApi
|
|
|
359
365
|
end
|
|
360
366
|
|
|
361
367
|
if type_definition.feature?('supports_noop')
|
|
362
|
-
my_provider.set(context, { rsapi_title => { is:
|
|
368
|
+
my_provider.set(context, { rsapi_title => { is: rsapi_current_state, should: target_state } }, noop: noop?)
|
|
363
369
|
else
|
|
364
|
-
my_provider.set(context, rsapi_title => { is:
|
|
370
|
+
my_provider.set(context, rsapi_title => { is: rsapi_current_state, should: target_state }) unless noop?
|
|
365
371
|
end
|
|
366
372
|
if context.failed?
|
|
367
373
|
context.reset_failed
|
|
@@ -369,16 +375,16 @@ module Puppet::ResourceApi
|
|
|
369
375
|
end
|
|
370
376
|
|
|
371
377
|
# remember that we have successfully reached our desired state
|
|
372
|
-
|
|
378
|
+
self.rsapi_current_state = target_state
|
|
373
379
|
end
|
|
374
380
|
|
|
375
381
|
def raise_missing_attrs
|
|
376
|
-
error_msg = "The following mandatory attributes were not provided:\n *
|
|
382
|
+
error_msg = "The following mandatory attributes were not provided:\n * #{@missing_attrs.join(", \n * ")}"
|
|
377
383
|
raise Puppet::ResourceError, error_msg if @missing_attrs.any? && (value(:ensure) != :absent && !value(:ensure).nil?)
|
|
378
384
|
end
|
|
379
385
|
|
|
380
386
|
def raise_missing_params
|
|
381
|
-
error_msg = "The following mandatory parameters were not provided:\n *
|
|
387
|
+
error_msg = "The following mandatory parameters were not provided:\n * #{@missing_params.join(", \n * ")}"
|
|
382
388
|
raise Puppet::ResourceError, error_msg
|
|
383
389
|
end
|
|
384
390
|
|
|
@@ -409,14 +415,14 @@ module Puppet::ResourceApi
|
|
|
409
415
|
# compare the clone against the current state to see if changes have been made by canonicalize
|
|
410
416
|
return unless state_clone && (current_state != state_clone)
|
|
411
417
|
|
|
412
|
-
|
|
418
|
+
# :nocov:
|
|
413
419
|
# codecov fails to register this multiline as covered, even though simplecov does.
|
|
414
|
-
message =
|
|
415
|
-
#{type_definition.name}[#{@title}]#get has not provided canonicalized values.
|
|
416
|
-
Returned values: #{current_state.inspect}
|
|
417
|
-
Canonicalized values: #{state_clone.inspect}
|
|
418
|
-
MESSAGE
|
|
419
|
-
|
|
420
|
+
message = <<~MESSAGE.strip
|
|
421
|
+
#{type_definition.name}[#{@title}]#get has not provided canonicalized values.
|
|
422
|
+
Returned values: #{current_state.inspect}
|
|
423
|
+
Canonicalized values: #{state_clone.inspect}
|
|
424
|
+
MESSAGE
|
|
425
|
+
# :nocov:
|
|
420
426
|
strict_message(message)
|
|
421
427
|
end
|
|
422
428
|
|
|
@@ -431,6 +437,7 @@ MESSAGE
|
|
|
431
437
|
self.class.title_patterns.each do |regexp, symbols|
|
|
432
438
|
captures = regexp.match(current_state[:title])
|
|
433
439
|
next if captures.nil?
|
|
440
|
+
|
|
434
441
|
symbols.zip(captures[1..-1]).each do |symbol_and_lambda, capture|
|
|
435
442
|
# The Resource API does not support passing procs in title_patterns
|
|
436
443
|
# so, unlike Puppet::Resource, we do not need to handle that here.
|
|
@@ -444,15 +451,15 @@ MESSAGE
|
|
|
444
451
|
|
|
445
452
|
namevars = type_definition.namevars.reject { |namevar| title_hash[namevar] == rsapi_title[namevar] }
|
|
446
453
|
|
|
447
|
-
|
|
454
|
+
# :nocov:
|
|
448
455
|
# codecov fails to register this multiline as covered, even though simplecov does.
|
|
449
|
-
message =
|
|
450
|
-
#{type_definition.name}[#{@title}]#get has provided a title attribute which does not match all namevars.
|
|
451
|
-
Namevars which do not match: #{namevars.inspect}
|
|
452
|
-
Returned parsed title hash: #{title_hash.inspect}
|
|
453
|
-
Expected hash: #{rsapi_title.inspect}
|
|
454
|
-
MESSAGE
|
|
455
|
-
|
|
456
|
+
message = <<~MESSAGE.strip
|
|
457
|
+
#{type_definition.name}[#{@title}]#get has provided a title attribute which does not match all namevars.
|
|
458
|
+
Namevars which do not match: #{namevars.inspect}
|
|
459
|
+
Returned parsed title hash: #{title_hash.inspect}
|
|
460
|
+
Expected hash: #{rsapi_title.inspect}
|
|
461
|
+
MESSAGE
|
|
462
|
+
# :nocov:
|
|
456
463
|
strict_message(message)
|
|
457
464
|
end
|
|
458
465
|
|
|
@@ -468,7 +475,7 @@ MESSAGE
|
|
|
468
475
|
@title_patterns ||= if type_definition.definition.key? :title_patterns
|
|
469
476
|
parse_title_patterns(type_definition.definition[:title_patterns])
|
|
470
477
|
else
|
|
471
|
-
[[
|
|
478
|
+
[[/(.*)/m, [[type_definition.namevars.first]]]]
|
|
472
479
|
end
|
|
473
480
|
end
|
|
474
481
|
|
|
@@ -489,14 +496,14 @@ MESSAGE
|
|
|
489
496
|
end
|
|
490
497
|
end
|
|
491
498
|
|
|
492
|
-
[
|
|
499
|
+
%i[autorequire autobefore autosubscribe autonotify].each do |auto|
|
|
493
500
|
next unless definition[auto]
|
|
494
501
|
|
|
495
502
|
definition[auto].each do |type, values|
|
|
496
503
|
Puppet.debug("Registering #{auto} for #{type}: #{values.inspect}")
|
|
497
504
|
send(auto, type.downcase.to_sym) do
|
|
498
505
|
resolved = [values].flatten.map do |v|
|
|
499
|
-
match =
|
|
506
|
+
match = /\A\$(.*)\Z/.match(v) if v.is_a? String
|
|
500
507
|
if match.nil?
|
|
501
508
|
v
|
|
502
509
|
else
|
|
@@ -505,13 +512,13 @@ MESSAGE
|
|
|
505
512
|
end
|
|
506
513
|
# Flatten to handle any resolved array properties and filter any nil
|
|
507
514
|
# values resulting from unspecified optional parameters:
|
|
508
|
-
resolved.flatten.reject
|
|
515
|
+
resolved.flatten.reject(&:nil?)
|
|
509
516
|
end
|
|
510
517
|
end
|
|
511
518
|
end
|
|
512
519
|
end
|
|
513
520
|
end
|
|
514
|
-
module_function :register_type
|
|
521
|
+
module_function :register_type
|
|
515
522
|
|
|
516
523
|
def load_provider(type_name)
|
|
517
524
|
class_name = class_name_from_type_name(type_name)
|
|
@@ -534,20 +541,20 @@ MESSAGE
|
|
|
534
541
|
end
|
|
535
542
|
rescue NameError
|
|
536
543
|
if device_name # line too long # rubocop:disable Style/GuardClause
|
|
537
|
-
raise Puppet::DevError, "Found neither the device-specific provider class Puppet::Provider::#{class_name}::#{device_class_name} in puppet/provider/#{type_name}/#{device_name}"\
|
|
538
|
-
|
|
544
|
+
raise Puppet::DevError, "Found neither the device-specific provider class Puppet::Provider::#{class_name}::#{device_class_name} in puppet/provider/#{type_name}/#{device_name} " \
|
|
545
|
+
"nor the generic provider class Puppet::Provider::#{class_name}::#{class_name} in puppet/provider/#{type_name}/#{type_name}"
|
|
539
546
|
else
|
|
540
547
|
raise Puppet::DevError, "provider class Puppet::Provider::#{class_name}::#{class_name} not found in puppet/provider/#{type_name}/#{type_name}"
|
|
541
548
|
end
|
|
542
549
|
end
|
|
543
|
-
module_function :load_provider
|
|
550
|
+
module_function :load_provider
|
|
544
551
|
|
|
545
552
|
def load_default_provider(class_name, type_name_sym)
|
|
546
553
|
# loads the "puppet/provider/#{type_name}/#{type_name}" file through puppet
|
|
547
554
|
Puppet::Type.type(type_name_sym).provider(type_name_sym)
|
|
548
555
|
Puppet::Provider.const_get(class_name, false).const_get(class_name, false)
|
|
549
556
|
end
|
|
550
|
-
module_function :load_default_provider
|
|
557
|
+
module_function :load_default_provider
|
|
551
558
|
|
|
552
559
|
def load_device_provider(class_name, type_name_sym, device_class_name, device_name_sym)
|
|
553
560
|
# loads the "puppet/provider/#{type_name}/#{device_name}" file through puppet
|
|
@@ -559,13 +566,13 @@ MESSAGE
|
|
|
559
566
|
load_default_provider(class_name, type_name_sym)
|
|
560
567
|
end
|
|
561
568
|
end
|
|
562
|
-
module_function :load_device_provider
|
|
569
|
+
module_function :load_device_provider
|
|
563
570
|
|
|
564
571
|
# keeps the existing register API format. e.g. Puppet::ResourceApi.register_type
|
|
565
572
|
def register_transport(schema)
|
|
566
573
|
Puppet::ResourceApi::Transport.register(schema)
|
|
567
574
|
end
|
|
568
|
-
module_function :register_transport
|
|
575
|
+
module_function :register_transport
|
|
569
576
|
|
|
570
577
|
def self.class_name_from_type_name(type_name)
|
|
571
578
|
type_name.to_s.split('_').map(&:capitalize).join
|
|
@@ -7,6 +7,7 @@ require 'hocon/config_syntax'
|
|
|
7
7
|
module Puppet::Util; end
|
|
8
8
|
# avoid loading puppet code base
|
|
9
9
|
class Puppet::Util::NetworkDevice; end
|
|
10
|
+
|
|
10
11
|
module Puppet::Util::NetworkDevice::Simple
|
|
11
12
|
# A basic device class, that reads its configuration from the provided URL.
|
|
12
13
|
# The URL has to be a local file URL.
|
|
@@ -26,6 +27,7 @@ module Puppet::Util::NetworkDevice::Simple
|
|
|
26
27
|
|
|
27
28
|
def config
|
|
28
29
|
raise "Trying to load config from '#{@url.path}, but file does not exist." if @url && !File.exist?(@url.path)
|
|
30
|
+
|
|
29
31
|
@config ||= Hocon.load(@url.path, syntax: Hocon::ConfigSyntax::HOCON)
|
|
30
32
|
end
|
|
31
33
|
end
|
metadata
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: puppet-resource_api
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- David Schmitt
|
|
8
|
+
autorequire:
|
|
8
9
|
bindir: exe
|
|
9
10
|
cert_chain: []
|
|
10
|
-
date:
|
|
11
|
+
date: 2025-03-14 00:00:00.000000000 Z
|
|
11
12
|
dependencies:
|
|
12
13
|
- !ruby/object:Gem::Dependency
|
|
13
14
|
name: hocon
|
|
@@ -23,6 +24,7 @@ dependencies:
|
|
|
23
24
|
- - ">="
|
|
24
25
|
- !ruby/object:Gem::Version
|
|
25
26
|
version: '1.0'
|
|
27
|
+
description:
|
|
26
28
|
email:
|
|
27
29
|
- david.schmitt@puppet.com
|
|
28
30
|
executables: []
|
|
@@ -52,6 +54,7 @@ files:
|
|
|
52
54
|
- lib/puppet/resource_api/io_context.rb
|
|
53
55
|
- lib/puppet/resource_api/parameter.rb
|
|
54
56
|
- lib/puppet/resource_api/property.rb
|
|
57
|
+
- lib/puppet/resource_api/provider_get_cache.rb
|
|
55
58
|
- lib/puppet/resource_api/puppet_context.rb
|
|
56
59
|
- lib/puppet/resource_api/read_only_parameter.rb
|
|
57
60
|
- lib/puppet/resource_api/simple_provider.rb
|
|
@@ -66,6 +69,7 @@ homepage: https://github.com/puppetlabs/puppet-resource_api
|
|
|
66
69
|
licenses:
|
|
67
70
|
- Apache-2.0
|
|
68
71
|
metadata: {}
|
|
72
|
+
post_install_message:
|
|
69
73
|
rdoc_options: []
|
|
70
74
|
require_paths:
|
|
71
75
|
- lib
|
|
@@ -80,7 +84,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
80
84
|
- !ruby/object:Gem::Version
|
|
81
85
|
version: '0'
|
|
82
86
|
requirements: []
|
|
83
|
-
rubygems_version: 3.6
|
|
87
|
+
rubygems_version: 3.1.6
|
|
88
|
+
signing_key:
|
|
84
89
|
specification_version: 4
|
|
85
90
|
summary: This library provides a simple way to write new native resources for puppet.
|
|
86
91
|
test_files: []
|