puppet-resource_api 1.9.2 → 2.0.1
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 +378 -414
- 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 -90
- 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,28 +90,22 @@ 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
107
|
attributes[:sensitive_parameters] = sensitives unless sensitives.empty?
|
|
108
|
-
super
|
|
108
|
+
super
|
|
109
109
|
end
|
|
110
110
|
|
|
111
111
|
# Override finish method to ensure scope tags (like class names) are properly inherited
|
|
@@ -151,7 +151,7 @@ module Puppet::ResourceApi
|
|
|
151
151
|
@rsapi_canonicalized_target_state ||= begin
|
|
152
152
|
# skip puppet's injected metaparams
|
|
153
153
|
actual_params = @parameters.select { |k, _v| type_definition.attributes.key? k }
|
|
154
|
-
target_state =
|
|
154
|
+
target_state = actual_params.transform_values(&:rs_value)
|
|
155
155
|
target_state = my_provider.canonicalize(context, [target_state]).first if type_definition.feature?('canonicalize')
|
|
156
156
|
target_state
|
|
157
157
|
end
|
|
@@ -162,22 +162,33 @@ module Puppet::ResourceApi
|
|
|
162
162
|
def generate
|
|
163
163
|
# If feature `custom_generate` has been set then call the generate function within the provider and return the given results
|
|
164
164
|
return unless type_definition&.feature?('custom_generate')
|
|
165
|
+
|
|
165
166
|
should_hash = rsapi_canonicalized_target_state
|
|
166
167
|
is_hash = rsapi_current_state
|
|
167
168
|
title = rsapi_title
|
|
168
169
|
|
|
169
170
|
# Ensure that a custom `generate` method has been created within the provider
|
|
170
171
|
raise(Puppet::DevError, 'No generate method found within the types provider') unless my_provider.respond_to?(:generate)
|
|
172
|
+
|
|
171
173
|
# Call the providers custom `generate` method
|
|
172
|
-
|
|
174
|
+
my_provider.generate(context, title, is_hash, should_hash)
|
|
173
175
|
|
|
174
176
|
# Return array of resources
|
|
175
|
-
rules_resources
|
|
176
177
|
end
|
|
177
178
|
|
|
178
179
|
def rsapi_current_state
|
|
179
|
-
|
|
180
|
-
|
|
180
|
+
return @rsapi_current_state if @rsapi_current_state
|
|
181
|
+
|
|
182
|
+
# If the current state is not set, then check the cache and, if a value is
|
|
183
|
+
# found, ensure it passes strict_check before allowing it to be used:
|
|
184
|
+
cached_value = rsapi_provider_get_cache.get(rsapi_title)
|
|
185
|
+
strict_check(cached_value) if cached_value
|
|
186
|
+
@rsapi_current_state = cached_value
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
def rsapi_current_state=(value)
|
|
190
|
+
rsapi_provider_get_cache.add(rsapi_title, value)
|
|
191
|
+
@rsapi_current_state = value
|
|
181
192
|
end
|
|
182
193
|
|
|
183
194
|
def to_resource
|
|
@@ -201,11 +212,11 @@ module Puppet::ResourceApi
|
|
|
201
212
|
definition[:attributes].each do |name, options|
|
|
202
213
|
type = Puppet::ResourceApi::DataTypeHandling.parse_puppet_type(
|
|
203
214
|
:name,
|
|
204
|
-
options[:type]
|
|
215
|
+
options[:type]
|
|
205
216
|
)
|
|
206
217
|
|
|
207
218
|
# skip read only vars and the namevar
|
|
208
|
-
next if [
|
|
219
|
+
next if %i[read_only namevar].include? options[:behaviour]
|
|
209
220
|
|
|
210
221
|
# skip properties if the resource is being deleted
|
|
211
222
|
next if definition[:attributes][:ensure] &&
|
|
@@ -232,7 +243,7 @@ module Puppet::ResourceApi
|
|
|
232
243
|
custom_insync_trigger_options = {
|
|
233
244
|
type: 'Enum[do_not_specify_in_manifest]',
|
|
234
245
|
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'
|
|
246
|
+
default: 'do_not_specify_in_manifest'
|
|
236
247
|
}
|
|
237
248
|
|
|
238
249
|
type_definition.create_attribute_in(self, :rsapi_custom_insync_trigger, :newproperty, Puppet::ResourceApi::Property, custom_insync_trigger_options)
|
|
@@ -241,16 +252,12 @@ module Puppet::ResourceApi
|
|
|
241
252
|
definition[:attributes].each do |name, options|
|
|
242
253
|
# puts "#{name}: #{options.inspect}"
|
|
243
254
|
|
|
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
|
|
255
|
+
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
256
|
|
|
250
257
|
# TODO: using newparam everywhere would suppress change reporting
|
|
251
258
|
# that would allow more fine-grained reporting through context,
|
|
252
259
|
# but require more invest in hooking up the infrastructure to emulate existing data
|
|
253
|
-
if [
|
|
260
|
+
if %i[parameter namevar].include? options[:behaviour]
|
|
254
261
|
param_or_property = :newparam
|
|
255
262
|
parent = Puppet::ResourceApi::Parameter
|
|
256
263
|
elsif options[:behaviour] == :read_only
|
|
@@ -264,18 +271,35 @@ module Puppet::ResourceApi
|
|
|
264
271
|
type_definition.create_attribute_in(self, name, param_or_property, parent, options)
|
|
265
272
|
end
|
|
266
273
|
|
|
274
|
+
def self.rsapi_provider_get(names = nil)
|
|
275
|
+
# If the cache has been marked as having all instances, then just return the
|
|
276
|
+
# full contents:
|
|
277
|
+
return rsapi_provider_get_cache.all if rsapi_provider_get_cache.cached_all? && names.nil?
|
|
278
|
+
|
|
279
|
+
fetched = if type_definition.feature?('simple_get_filter')
|
|
280
|
+
my_provider.get(context, names)
|
|
281
|
+
else
|
|
282
|
+
my_provider.get(context)
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
fetched.each do |resource_hash|
|
|
286
|
+
rsapi_provider_get_cache.add(build_title(type_definition, resource_hash), resource_hash)
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
if names.nil? && !type_definition.feature?('simple_get_filter')
|
|
290
|
+
# Mark the cache as having all possible instances:
|
|
291
|
+
rsapi_provider_get_cache.cached_all
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
fetched
|
|
295
|
+
end
|
|
296
|
+
|
|
267
297
|
def self.instances
|
|
268
298
|
# puts 'instances'
|
|
269
299
|
# force autoloading of the provider
|
|
270
300
|
provider(type_definition.name)
|
|
271
301
|
|
|
272
|
-
|
|
273
|
-
my_provider.get(context, [])
|
|
274
|
-
else
|
|
275
|
-
my_provider.get(context)
|
|
276
|
-
end
|
|
277
|
-
|
|
278
|
-
initial_fetch.map do |resource_hash|
|
|
302
|
+
rsapi_provider_get.map do |resource_hash|
|
|
279
303
|
type_definition.check_schema(resource_hash)
|
|
280
304
|
# allow a :title from the provider to override the default
|
|
281
305
|
result = if resource_hash.key? :title
|
|
@@ -283,38 +307,42 @@ module Puppet::ResourceApi
|
|
|
283
307
|
else
|
|
284
308
|
new(title: build_title(type_definition, resource_hash))
|
|
285
309
|
end
|
|
310
|
+
# Cache the state in the generated resource, but unfortunately
|
|
311
|
+
# this only benefits "puppet resource", not apply runs:
|
|
286
312
|
result.cache_current_state(resource_hash)
|
|
287
313
|
result
|
|
288
314
|
end
|
|
289
315
|
end
|
|
290
316
|
|
|
291
317
|
def refresh_current_state
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
if @rsapi_current_state
|
|
299
|
-
type_definition.check_schema(@rsapi_current_state)
|
|
300
|
-
strict_check(@rsapi_current_state)
|
|
318
|
+
current_state = self.class.rsapi_provider_get([rsapi_title]).find { |h| namevar_match?(h) }
|
|
319
|
+
|
|
320
|
+
if current_state
|
|
321
|
+
type_definition.check_schema(current_state)
|
|
322
|
+
strict_check(current_state)
|
|
301
323
|
else
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
324
|
+
current_state = if rsapi_title.is_a? Hash
|
|
325
|
+
rsapi_title.dup
|
|
326
|
+
else
|
|
327
|
+
{ title: rsapi_title }
|
|
328
|
+
end
|
|
329
|
+
current_state[:ensure] = :absent if type_definition.ensurable?
|
|
308
330
|
end
|
|
331
|
+
self.rsapi_current_state = current_state
|
|
309
332
|
end
|
|
310
333
|
|
|
311
|
-
# Use this to set the current state from the `instances` method
|
|
334
|
+
# Use this to set the current state from the `instances` method. "puppet resources"
|
|
335
|
+
# needs this to minimize provider get() calls, but during a Puppet apply run
|
|
336
|
+
# the instances() method is only used by resource generation, and resource
|
|
337
|
+
# generators use and then discard the resources created by `instances``, so this
|
|
338
|
+
# does not help with that:
|
|
312
339
|
def cache_current_state(resource_hash)
|
|
313
|
-
|
|
314
|
-
strict_check(
|
|
340
|
+
self.rsapi_current_state = resource_hash
|
|
341
|
+
strict_check(resource_hash)
|
|
315
342
|
end
|
|
316
343
|
|
|
317
344
|
def retrieve
|
|
345
|
+
refresh_current_state unless rsapi_current_state
|
|
318
346
|
Puppet.debug("Current State: #{rsapi_current_state.inspect}")
|
|
319
347
|
|
|
320
348
|
result = Puppet::Resource.new(self.class, title, parameters: rsapi_current_state)
|
|
@@ -338,17 +366,18 @@ module Puppet::ResourceApi
|
|
|
338
366
|
# puts 'flush'
|
|
339
367
|
target_state = rsapi_canonicalized_target_state
|
|
340
368
|
|
|
341
|
-
retrieve unless
|
|
369
|
+
retrieve unless rsapi_current_state
|
|
342
370
|
|
|
343
|
-
return if
|
|
371
|
+
return if rsapi_current_state == target_state
|
|
344
372
|
|
|
345
373
|
Puppet.debug("Target State: #{target_state.inspect}")
|
|
346
374
|
|
|
347
375
|
# enforce init_only attributes
|
|
348
|
-
if Puppet.settings[:strict] != :off &&
|
|
376
|
+
if Puppet.settings[:strict] != :off && rsapi_current_state && (rsapi_current_state[:ensure] == 'present' && target_state[:ensure] == 'present')
|
|
349
377
|
target_state.each do |name, value|
|
|
350
|
-
next unless type_definition.attributes[name][:behaviour] == :init_only && value !=
|
|
351
|
-
|
|
378
|
+
next unless type_definition.attributes[name][:behaviour] == :init_only && value != rsapi_current_state[name]
|
|
379
|
+
|
|
380
|
+
message = "Attempting to change `#{name}` init_only attribute value from `#{rsapi_current_state[name]}` to `#{value}`"
|
|
352
381
|
case Puppet.settings[:strict]
|
|
353
382
|
when :warning
|
|
354
383
|
Puppet.warning(message)
|
|
@@ -359,9 +388,9 @@ module Puppet::ResourceApi
|
|
|
359
388
|
end
|
|
360
389
|
|
|
361
390
|
if type_definition.feature?('supports_noop')
|
|
362
|
-
my_provider.set(context, { rsapi_title => { is:
|
|
391
|
+
my_provider.set(context, { rsapi_title => { is: rsapi_current_state, should: target_state } }, noop: noop?)
|
|
363
392
|
else
|
|
364
|
-
my_provider.set(context, rsapi_title => { is:
|
|
393
|
+
my_provider.set(context, rsapi_title => { is: rsapi_current_state, should: target_state }) unless noop?
|
|
365
394
|
end
|
|
366
395
|
if context.failed?
|
|
367
396
|
context.reset_failed
|
|
@@ -369,16 +398,16 @@ module Puppet::ResourceApi
|
|
|
369
398
|
end
|
|
370
399
|
|
|
371
400
|
# remember that we have successfully reached our desired state
|
|
372
|
-
|
|
401
|
+
self.rsapi_current_state = target_state
|
|
373
402
|
end
|
|
374
403
|
|
|
375
404
|
def raise_missing_attrs
|
|
376
|
-
error_msg = "The following mandatory attributes were not provided:\n *
|
|
405
|
+
error_msg = "The following mandatory attributes were not provided:\n * #{@missing_attrs.join(", \n * ")}"
|
|
377
406
|
raise Puppet::ResourceError, error_msg if @missing_attrs.any? && (value(:ensure) != :absent && !value(:ensure).nil?)
|
|
378
407
|
end
|
|
379
408
|
|
|
380
409
|
def raise_missing_params
|
|
381
|
-
error_msg = "The following mandatory parameters were not provided:\n *
|
|
410
|
+
error_msg = "The following mandatory parameters were not provided:\n * #{@missing_params.join(", \n * ")}"
|
|
382
411
|
raise Puppet::ResourceError, error_msg
|
|
383
412
|
end
|
|
384
413
|
|
|
@@ -409,14 +438,14 @@ module Puppet::ResourceApi
|
|
|
409
438
|
# compare the clone against the current state to see if changes have been made by canonicalize
|
|
410
439
|
return unless state_clone && (current_state != state_clone)
|
|
411
440
|
|
|
412
|
-
|
|
441
|
+
# :nocov:
|
|
413
442
|
# 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
|
-
|
|
443
|
+
message = <<~MESSAGE.strip
|
|
444
|
+
#{type_definition.name}[#{@title}]#get has not provided canonicalized values.
|
|
445
|
+
Returned values: #{current_state.inspect}
|
|
446
|
+
Canonicalized values: #{state_clone.inspect}
|
|
447
|
+
MESSAGE
|
|
448
|
+
# :nocov:
|
|
420
449
|
strict_message(message)
|
|
421
450
|
end
|
|
422
451
|
|
|
@@ -431,6 +460,7 @@ MESSAGE
|
|
|
431
460
|
self.class.title_patterns.each do |regexp, symbols|
|
|
432
461
|
captures = regexp.match(current_state[:title])
|
|
433
462
|
next if captures.nil?
|
|
463
|
+
|
|
434
464
|
symbols.zip(captures[1..-1]).each do |symbol_and_lambda, capture|
|
|
435
465
|
# The Resource API does not support passing procs in title_patterns
|
|
436
466
|
# so, unlike Puppet::Resource, we do not need to handle that here.
|
|
@@ -444,15 +474,15 @@ MESSAGE
|
|
|
444
474
|
|
|
445
475
|
namevars = type_definition.namevars.reject { |namevar| title_hash[namevar] == rsapi_title[namevar] }
|
|
446
476
|
|
|
447
|
-
|
|
477
|
+
# :nocov:
|
|
448
478
|
# 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
|
-
|
|
479
|
+
message = <<~MESSAGE.strip
|
|
480
|
+
#{type_definition.name}[#{@title}]#get has provided a title attribute which does not match all namevars.
|
|
481
|
+
Namevars which do not match: #{namevars.inspect}
|
|
482
|
+
Returned parsed title hash: #{title_hash.inspect}
|
|
483
|
+
Expected hash: #{rsapi_title.inspect}
|
|
484
|
+
MESSAGE
|
|
485
|
+
# :nocov:
|
|
456
486
|
strict_message(message)
|
|
457
487
|
end
|
|
458
488
|
|
|
@@ -468,7 +498,7 @@ MESSAGE
|
|
|
468
498
|
@title_patterns ||= if type_definition.definition.key? :title_patterns
|
|
469
499
|
parse_title_patterns(type_definition.definition[:title_patterns])
|
|
470
500
|
else
|
|
471
|
-
[[
|
|
501
|
+
[[/(.*)/m, [[type_definition.namevars.first]]]]
|
|
472
502
|
end
|
|
473
503
|
end
|
|
474
504
|
|
|
@@ -489,14 +519,14 @@ MESSAGE
|
|
|
489
519
|
end
|
|
490
520
|
end
|
|
491
521
|
|
|
492
|
-
[
|
|
522
|
+
%i[autorequire autobefore autosubscribe autonotify].each do |auto|
|
|
493
523
|
next unless definition[auto]
|
|
494
524
|
|
|
495
525
|
definition[auto].each do |type, values|
|
|
496
526
|
Puppet.debug("Registering #{auto} for #{type}: #{values.inspect}")
|
|
497
527
|
send(auto, type.downcase.to_sym) do
|
|
498
528
|
resolved = [values].flatten.map do |v|
|
|
499
|
-
match =
|
|
529
|
+
match = /\A\$(.*)\Z/.match(v) if v.is_a? String
|
|
500
530
|
if match.nil?
|
|
501
531
|
v
|
|
502
532
|
else
|
|
@@ -505,13 +535,13 @@ MESSAGE
|
|
|
505
535
|
end
|
|
506
536
|
# Flatten to handle any resolved array properties and filter any nil
|
|
507
537
|
# values resulting from unspecified optional parameters:
|
|
508
|
-
resolved.flatten.reject
|
|
538
|
+
resolved.flatten.reject(&:nil?)
|
|
509
539
|
end
|
|
510
540
|
end
|
|
511
541
|
end
|
|
512
542
|
end
|
|
513
543
|
end
|
|
514
|
-
module_function :register_type
|
|
544
|
+
module_function :register_type
|
|
515
545
|
|
|
516
546
|
def load_provider(type_name)
|
|
517
547
|
class_name = class_name_from_type_name(type_name)
|
|
@@ -534,20 +564,20 @@ MESSAGE
|
|
|
534
564
|
end
|
|
535
565
|
rescue NameError
|
|
536
566
|
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
|
-
|
|
567
|
+
raise Puppet::DevError, "Found neither the device-specific provider class Puppet::Provider::#{class_name}::#{device_class_name} in puppet/provider/#{type_name}/#{device_name} " \
|
|
568
|
+
"nor the generic provider class Puppet::Provider::#{class_name}::#{class_name} in puppet/provider/#{type_name}/#{type_name}"
|
|
539
569
|
else
|
|
540
570
|
raise Puppet::DevError, "provider class Puppet::Provider::#{class_name}::#{class_name} not found in puppet/provider/#{type_name}/#{type_name}"
|
|
541
571
|
end
|
|
542
572
|
end
|
|
543
|
-
module_function :load_provider
|
|
573
|
+
module_function :load_provider
|
|
544
574
|
|
|
545
575
|
def load_default_provider(class_name, type_name_sym)
|
|
546
576
|
# loads the "puppet/provider/#{type_name}/#{type_name}" file through puppet
|
|
547
577
|
Puppet::Type.type(type_name_sym).provider(type_name_sym)
|
|
548
578
|
Puppet::Provider.const_get(class_name, false).const_get(class_name, false)
|
|
549
579
|
end
|
|
550
|
-
module_function :load_default_provider
|
|
580
|
+
module_function :load_default_provider
|
|
551
581
|
|
|
552
582
|
def load_device_provider(class_name, type_name_sym, device_class_name, device_name_sym)
|
|
553
583
|
# loads the "puppet/provider/#{type_name}/#{device_name}" file through puppet
|
|
@@ -559,13 +589,13 @@ MESSAGE
|
|
|
559
589
|
load_default_provider(class_name, type_name_sym)
|
|
560
590
|
end
|
|
561
591
|
end
|
|
562
|
-
module_function :load_device_provider
|
|
592
|
+
module_function :load_device_provider
|
|
563
593
|
|
|
564
594
|
# keeps the existing register API format. e.g. Puppet::ResourceApi.register_type
|
|
565
595
|
def register_transport(schema)
|
|
566
596
|
Puppet::ResourceApi::Transport.register(schema)
|
|
567
597
|
end
|
|
568
|
-
module_function :register_transport
|
|
598
|
+
module_function :register_transport
|
|
569
599
|
|
|
570
600
|
def self.class_name_from_type_name(type_name)
|
|
571
601
|
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.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- David Schmitt
|
|
8
|
+
autorequire:
|
|
8
9
|
bindir: exe
|
|
9
10
|
cert_chain: []
|
|
10
|
-
date: 2026-
|
|
11
|
+
date: 2026-06-30 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.
|
|
87
|
+
rubygems_version: 3.4.19
|
|
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: []
|