puppet-resource_api 0.9.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.dependency_decisions.yml +7 -0
- data/.fixtures.yml +8 -0
- data/.gitignore +3 -0
- data/.rubocop.yml +23 -4
- data/.travis.yml +2 -3
- data/CHANGELOG.md +19 -0
- data/Gemfile +4 -1
- data/README.md +18 -19
- data/Rakefile +7 -2
- data/lib/puppet/resource_api.rb +80 -21
- data/lib/puppet/resource_api/base_context.rb +10 -0
- data/lib/puppet/resource_api/glue.rb +15 -12
- data/lib/puppet/resource_api/simple_provider.rb +6 -1
- data/lib/puppet/resource_api/version.rb +1 -1
- data/puppet-resource_api.gemspec +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3a91327b209438f84007c4f5b948c5d49722af0af7e0507d8dc03dd2c1205532
|
4
|
+
data.tar.gz: c431efc192e7dae991959d9eaa9ae05a0839631d319b9d688189d117a20936b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e42c3f71f955b864442b795f10ce22de17685316d55555de9240576924246ac4ff4f1aa4b55fd383a6b9bca74f0308f36575806637c2cf4a952914de7d22b7c9
|
7
|
+
data.tar.gz: 6f01341aac1f7886ceb0d455e9a63302dca562fb11f4fd896196c5d1c182b83ea9b2ace5b6d491db28e2a069f26c468d0411d2f5fbaa5d66fd849d6f305d5e55
|
data/.dependency_decisions.yml
CHANGED
@@ -89,3 +89,10 @@
|
|
89
89
|
:why: https://github.com/masover/blankslate/blob/f0a73b80c34bc3ad94dc3195d12a227a8fe30019/MIT-LICENSE
|
90
90
|
:versions: []
|
91
91
|
:when: 2017-11-17 14:05:09.534340925 Z
|
92
|
+
- - :license
|
93
|
+
- puppetlabs_spec_helper
|
94
|
+
- Apache 2.0
|
95
|
+
- :who: DavidS
|
96
|
+
:why:
|
97
|
+
:versions: []
|
98
|
+
:when: 2018-03-09 18:04:29.175843919 Z
|
data/.fixtures.yml
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
# This file can be used to install module depdencies for unit testing
|
2
|
+
# See https://github.com/puppetlabs/puppetlabs_spec_helper#using-fixtures for details
|
3
|
+
---
|
4
|
+
fixtures:
|
5
|
+
forge_modules:
|
6
|
+
# stdlib: "puppetlabs/stdlib"
|
7
|
+
symlinks:
|
8
|
+
test_module: "#{source_dir}/spec/fixtures/test_module"
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -62,10 +62,6 @@ Style/TrailingCommaInArguments:
|
|
62
62
|
Description: Prefer always trailing comma on multiline argument lists. This makes
|
63
63
|
diffs, and re-ordering nicer.
|
64
64
|
EnforcedStyleForMultiline: comma
|
65
|
-
Style/TrailingCommaInLiteral:
|
66
|
-
Description: Prefer always trailing comma on multiline literals. This makes diffs,
|
67
|
-
and re-ordering nicer.
|
68
|
-
EnforcedStyleForMultiline: comma
|
69
65
|
Style/SymbolArray:
|
70
66
|
Description: Using percent style obscures symbolic intent of array's contents.
|
71
67
|
EnforcedStyle: brackets
|
@@ -135,3 +131,26 @@ Style/BracesAroundHashParameters:
|
|
135
131
|
# see http://www.virtuouscode.com/2016/01/06/about-the-ruby-squiggly-heredoc-syntax/
|
136
132
|
Layout/IndentHeredoc:
|
137
133
|
Enabled: false
|
134
|
+
|
135
|
+
# Updated in 0.53 (or thereabouts)
|
136
|
+
Style/TrailingCommaInArrayLiteral:
|
137
|
+
Description: Prefer always trailing comma on multiline literals. This makes diffs,
|
138
|
+
and re-ordering nicer.
|
139
|
+
EnforcedStyleForMultiline: comma
|
140
|
+
Style/TrailingCommaInHashLiteral:
|
141
|
+
Description: Prefer always trailing comma on multiline literals. This makes diffs,
|
142
|
+
and re-ordering nicer.
|
143
|
+
EnforcedStyleForMultiline: comma
|
144
|
+
|
145
|
+
# Add allowing "is", as it is a technical term in puppet
|
146
|
+
Naming/UncommunicativeMethodParamName:
|
147
|
+
Description: Checks for method parameter names that contain capital letters, end in
|
148
|
+
numbers, or do not meet a minimal length.
|
149
|
+
Enabled: true
|
150
|
+
MinNameLength: 3
|
151
|
+
AllowNamesEndingInNumbers: true
|
152
|
+
AllowedNames:
|
153
|
+
- io
|
154
|
+
- id
|
155
|
+
- is
|
156
|
+
ForbiddenNames: []
|
data/.travis.yml
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
sudo: false
|
2
2
|
language: ruby
|
3
|
-
before_install: gem install bundler -v 1.15.4
|
4
3
|
bundler_args: "--without development"
|
5
4
|
script:
|
6
5
|
- echo travis_fold:start:DEBUG
|
@@ -14,9 +13,9 @@ matrix:
|
|
14
13
|
- rvm: 2.4.1
|
15
14
|
env: PUPPET_GEM_VERSION='~> 5'
|
16
15
|
- rvm: jruby-1.7.26
|
17
|
-
env: PUPPET_GEM_VERSION='~> 5'
|
16
|
+
env: PUPPET_GEM_VERSION='~> 5' JRUBY_OPTS="--debug"
|
18
17
|
- rvm: jruby-9.1.9.0
|
19
|
-
env: PUPPET_GEM_VERSION='~> 5'
|
18
|
+
env: PUPPET_GEM_VERSION='~> 5' JRUBY_OPTS="--debug"
|
20
19
|
- rvm: 2.4.1
|
21
20
|
env: CHECK=rubocop
|
22
21
|
- rvm: 2.4.1
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,24 @@
|
|
3
3
|
All significant changes to this repo will be summarized in this file.
|
4
4
|
|
5
5
|
|
6
|
+
## [v0.10.0](https://github.com/puppetlabs/puppet-resource_api/tree/v0.10.0) (2018-03-21)
|
7
|
+
[Full Changelog](https://github.com/puppetlabs/puppet-resource_api/compare/v0.9.0...v0.10.0)
|
8
|
+
|
9
|
+
**Implemented enhancements:**
|
10
|
+
|
11
|
+
- \(PDK-512\) Add support for simple\_get\_filter [\#37](https://github.com/puppetlabs/puppet-resource_api/pull/37) ([da-ar](https://github.com/da-ar))
|
12
|
+
- \(PDK-822\) Implement proper namevar handling [\#36](https://github.com/puppetlabs/puppet-resource_api/pull/36) ([DavidS](https://github.com/DavidS))
|
13
|
+
- \(PDK-513\) implement `supports\_noop` [\#31](https://github.com/puppetlabs/puppet-resource_api/pull/31) ([DavidS](https://github.com/DavidS))
|
14
|
+
- \(PDK-511\) Add canonicalization checking if puppet strict is on. [\#30](https://github.com/puppetlabs/puppet-resource_api/pull/30) ([da-ar](https://github.com/da-ar))
|
15
|
+
- \(PDK-508\) implement autorequire and friends [\#29](https://github.com/puppetlabs/puppet-resource_api/pull/29) ([DavidS](https://github.com/DavidS))
|
16
|
+
- Update README with PDK 1.4 commands and messages [\#28](https://github.com/puppetlabs/puppet-resource_api/pull/28) ([DavidS](https://github.com/DavidS))
|
17
|
+
|
18
|
+
**Merged pull requests:**
|
19
|
+
|
20
|
+
- Cleanups [\#34](https://github.com/puppetlabs/puppet-resource_api/pull/34) ([DavidS](https://github.com/DavidS))
|
21
|
+
- Cleanup test module [\#33](https://github.com/puppetlabs/puppet-resource_api/pull/33) ([DavidS](https://github.com/DavidS))
|
22
|
+
- Update to rubocop 0.53.0 [\#32](https://github.com/puppetlabs/puppet-resource_api/pull/32) ([DavidS](https://github.com/DavidS))
|
23
|
+
|
6
24
|
## [v0.9.0](https://github.com/puppetlabs/puppet-resource_api/tree/v0.9.0) (2018-02-22)
|
7
25
|
[Full Changelog](https://github.com/puppetlabs/puppet-resource_api/compare/v0.3.0...v0.9.0)
|
8
26
|
|
@@ -17,6 +35,7 @@ All significant changes to this repo will be summarized in this file.
|
|
17
35
|
|
18
36
|
**Merged pull requests:**
|
19
37
|
|
38
|
+
- Release prep v0.9.0 [\#27](https://github.com/puppetlabs/puppet-resource_api/pull/27) ([DavidS](https://github.com/DavidS))
|
20
39
|
- Add a note on device support to the README [\#26](https://github.com/puppetlabs/puppet-resource_api/pull/26) ([DavidS](https://github.com/DavidS))
|
21
40
|
- Remove Command API [\#25](https://github.com/puppetlabs/puppet-resource_api/pull/25) ([DavidS](https://github.com/DavidS))
|
22
41
|
|
data/Gemfile
CHANGED
@@ -15,6 +15,9 @@ group :tests do
|
|
15
15
|
gem 'rubocop-rspec'
|
16
16
|
gem 'rubocop'
|
17
17
|
gem 'simplecov-console'
|
18
|
+
# the test gems required for module testing
|
19
|
+
gem 'puppetlabs_spec_helper', github: 'DavidS/puppetlabs_spec_helper', ref: 'refactor'
|
20
|
+
gem 'rspec-puppet'
|
18
21
|
end
|
19
22
|
|
20
23
|
group :development do
|
@@ -39,5 +42,5 @@ end
|
|
39
42
|
if ENV['PUPPET_GEM_VERSION']
|
40
43
|
gem 'puppet', *location_for(ENV['PUPPET_GEM_VERSION'])
|
41
44
|
else
|
42
|
-
gem 'puppet',
|
45
|
+
gem 'puppet', github: 'DavidS/puppet', ref: 'device-apply'
|
43
46
|
end
|
data/README.md
CHANGED
@@ -5,9 +5,7 @@ This is an implementation of the [Resource API](https://github.com/DavidS/puppet
|
|
5
5
|
|
6
6
|
## Getting started
|
7
7
|
|
8
|
-
* Install the [PDK](https://puppet.com/download-puppet-development-kit).
|
9
|
-
* As of January 2018, the required PDK features are still in development.
|
10
|
-
See [PDK-506](https://tickets.puppetlabs.com/browse/PDK-506) for progress.
|
8
|
+
* Install the [PDK](https://puppet.com/download-puppet-development-kit) 1.4.
|
11
9
|
|
12
10
|
* Create a [new module](https://puppet.com/docs/pdk/latest/pdk_generating_modules.html) with the PDK, or work with an existing PDK-enabled module.
|
13
11
|
|
@@ -24,10 +22,11 @@ spec/spec_helper.rb:
|
|
24
22
|
mock_with: ':rspec'
|
25
23
|
```
|
26
24
|
|
27
|
-
* Apply the changes by running `pdk
|
25
|
+
* Apply the changes by running `pdk update`:
|
28
26
|
|
29
27
|
```
|
30
|
-
|
28
|
+
$ pdk update
|
29
|
+
pdk (INFO): Updating david-example using the default template, from 1.4.1 to 1.4.1
|
31
30
|
|
32
31
|
----------Files to be modified----------
|
33
32
|
Gemfile
|
@@ -35,39 +34,36 @@ spec/spec_helper.rb
|
|
35
34
|
|
36
35
|
----------------------------------------
|
37
36
|
|
38
|
-
You can find a report of differences in
|
37
|
+
You can find a report of differences in update_report.txt.
|
39
38
|
|
40
|
-
pdk (INFO): Module conversion is a potentially destructive action. Ensure that you have committed your module to a version control system or have a backup, and review the changes above before continuing.
|
41
39
|
Do you want to continue and make these changes to your module? Yes
|
42
|
-
[✔] Resolving Gemfile dependencies.
|
43
40
|
|
44
|
-
------------
|
41
|
+
------------Update completed------------
|
45
42
|
|
46
43
|
2 files modified.
|
47
44
|
|
48
|
-
|
45
|
+
$
|
49
46
|
```
|
50
47
|
|
51
48
|
* Create the required files for a new type and provider in the module with `pdk new provider <provider_name>`.
|
52
49
|
|
53
50
|
```
|
54
|
-
|
55
|
-
pdk (INFO): Creating '
|
56
|
-
pdk (INFO): Creating '
|
57
|
-
pdk (INFO): Creating '
|
58
|
-
|
51
|
+
$ pdk new provider foo
|
52
|
+
pdk (INFO): Creating '.../example/lib/puppet/type/foo.rb' from template.
|
53
|
+
pdk (INFO): Creating '.../example/lib/puppet/provider/foo/foo.rb' from template.
|
54
|
+
pdk (INFO): Creating '.../example/spec/unit/puppet/provider/foo/foo_spec.rb' from template.
|
55
|
+
$
|
59
56
|
```
|
60
57
|
|
61
58
|
The three generated files are the type, the implementation, and the unit tests. The default template contains an example that demonstrates the basic workings of the Resource API. This allows the unit tests to run immediately after creating the provider:
|
62
59
|
|
63
60
|
```
|
64
|
-
|
65
|
-
[✔] Installing missing Gemfile dependencies.
|
61
|
+
$ pdk test unit
|
66
62
|
[✔] Preparing to run the unit tests.
|
67
63
|
[✔] Running unit tests.
|
68
|
-
Evaluated
|
64
|
+
Evaluated 4 tests in 0.012065973 seconds: 0 failures, 0 pending.
|
69
65
|
[✔] Cleaning up after running unit tests.
|
70
|
-
|
66
|
+
$
|
71
67
|
```
|
72
68
|
|
73
69
|
### Writing the Type
|
@@ -204,6 +200,9 @@ There are still a few notable gaps between the implementation and the specificat
|
|
204
200
|
* Only a single runtime environment (the Puppet commands) is currently implemented.
|
205
201
|
* `auto*` definitions.
|
206
202
|
|
203
|
+
Restrictions of running under puppet:
|
204
|
+
* `supports_noop` is not effective, as puppet doesn't call into the type under noop.
|
205
|
+
|
207
206
|
## Development
|
208
207
|
|
209
208
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/Rakefile
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'bundler/gem_tasks'
|
2
|
+
require 'puppetlabs_spec_helper/tasks/fixtures'
|
2
3
|
|
3
4
|
task :default => :spec
|
4
5
|
|
@@ -13,10 +14,14 @@ end
|
|
13
14
|
require 'rspec/core/rake_task'
|
14
15
|
|
15
16
|
RSpec::Core::RakeTask.new(:spec) do |t|
|
16
|
-
|
17
|
-
|
17
|
+
Rake::Task[:spec_prep].invoke
|
18
|
+
# thanks to the fixtures/modules/ symlinks this needs to exclude fixture modules explicitely
|
19
|
+
excludes = ['fixtures/**/*.rb,fixtures/modules/*/**/*.rb']
|
20
|
+
if RUBY_PLATFORM == 'java'
|
21
|
+
excludes += ['acceptance/**/*.rb', 'integration/**/*.rb', 'puppet/resource_api/*_context_spec.rb', 'puppet/util/network_device/simple/device_spec.rb']
|
18
22
|
t.rspec_opts = '--tag ~agent_test'
|
19
23
|
end
|
24
|
+
t.exclude_pattern = "spec/{#{excludes.join ','}}"
|
20
25
|
end
|
21
26
|
|
22
27
|
namespace :spec do
|
data/lib/puppet/resource_api.rb
CHANGED
@@ -10,6 +10,11 @@ module Puppet::ResourceApi
|
|
10
10
|
raise Puppet::DevError, 'requires a name' unless definition.key? :name
|
11
11
|
raise Puppet::DevError, 'requires attributes' unless definition.key? :attributes
|
12
12
|
|
13
|
+
definition[:features] ||= []
|
14
|
+
supported_features = %w[supports_noop canonicalize remote_resource simple_get_filter].freeze
|
15
|
+
unknown_features = definition[:features] - supported_features
|
16
|
+
Puppet.warning("Unknown feature detected: #{unknown_features.inspect}") unless unknown_features.empty?
|
17
|
+
|
13
18
|
# prepare the ruby module for the provider
|
14
19
|
# this has to happen before Puppet::Type.newtype starts autoloading providers
|
15
20
|
# it also needs to be guarded against the namespace already being defined by something
|
@@ -33,7 +38,15 @@ module Puppet::ResourceApi
|
|
33
38
|
self.class.my_provider
|
34
39
|
end
|
35
40
|
|
36
|
-
|
41
|
+
define_singleton_method(:feature_support?) do |feature|
|
42
|
+
definition[:features] && definition[:features].include?(feature)
|
43
|
+
end
|
44
|
+
|
45
|
+
def feature_support?(feature)
|
46
|
+
self.class.feature_support?(feature)
|
47
|
+
end
|
48
|
+
|
49
|
+
if feature_support?('remote_resource')
|
37
50
|
apply_to_device
|
38
51
|
end
|
39
52
|
|
@@ -41,7 +54,7 @@ module Puppet::ResourceApi
|
|
41
54
|
# $stderr.puts "A: #{attributes.inspect}"
|
42
55
|
attributes = attributes.to_hash if attributes.is_a? Puppet::Resource
|
43
56
|
# $stderr.puts "B: #{attributes.inspect}"
|
44
|
-
if
|
57
|
+
if feature_support?('canonicalize')
|
45
58
|
attributes = my_provider.canonicalize(context, [attributes])[0]
|
46
59
|
end
|
47
60
|
# $stderr.puts "C: #{attributes.inspect}"
|
@@ -80,18 +93,6 @@ module Puppet::ResourceApi
|
|
80
93
|
|
81
94
|
# read-only values do not need type checking, but can have default values
|
82
95
|
if options[:behaviour] != :read_only
|
83
|
-
# TODO: this should use Pops infrastructure to avoid hardcoding stuff, and enhance type fidelity
|
84
|
-
# validate do |v|
|
85
|
-
# type = Puppet::Pops::Types::TypeParser.singleton.parse(options[:type]).normalize
|
86
|
-
# if type.instance?(v)
|
87
|
-
# return true
|
88
|
-
# else
|
89
|
-
# inferred_type = Puppet::Pops::Types::TypeCalculator.infer_set(v)
|
90
|
-
# error_msg = Puppet::Pops::Types::TypeMismatchDescriber.new.describe_mismatch("#{DEFINITION[:name]}.#{name}", type, inferred_type)
|
91
|
-
# raise Puppet::ResourceError, error_msg
|
92
|
-
# end
|
93
|
-
# end
|
94
|
-
|
95
96
|
if options.key? :default
|
96
97
|
defaultto options[:default]
|
97
98
|
end
|
@@ -165,14 +166,21 @@ module Puppet::ResourceApi
|
|
165
166
|
# force autoloading of the provider
|
166
167
|
provider(name)
|
167
168
|
my_provider.get(context).map do |resource_hash|
|
168
|
-
Puppet::ResourceApi::TypeShim.new(resource_hash[namevar_name], resource_hash, name)
|
169
|
+
Puppet::ResourceApi::TypeShim.new(resource_hash[namevar_name], resource_hash, name, namevar_name)
|
169
170
|
end
|
170
171
|
end
|
171
172
|
|
172
173
|
define_method(:retrieve) do
|
173
174
|
# puts "retrieve(#{title.inspect})"
|
174
|
-
result
|
175
|
-
|
175
|
+
result = Puppet::Resource.new(self.class, title)
|
176
|
+
|
177
|
+
current_state = if feature_support?('simple_get_filter')
|
178
|
+
my_provider.get(context, [title]).first
|
179
|
+
else
|
180
|
+
my_provider.get(context).find { |h| h[namevar_name] == title }
|
181
|
+
end
|
182
|
+
|
183
|
+
strict_check(current_state) if current_state && feature_support?('canonicalize')
|
176
184
|
|
177
185
|
# require 'pry'; binding.pry
|
178
186
|
|
@@ -181,7 +189,7 @@ module Puppet::ResourceApi
|
|
181
189
|
result[k] = v
|
182
190
|
end
|
183
191
|
else
|
184
|
-
result[
|
192
|
+
result[namevar_name] = title
|
185
193
|
result[:ensure] = :absent
|
186
194
|
end
|
187
195
|
|
@@ -192,11 +200,10 @@ module Puppet::ResourceApi
|
|
192
200
|
|
193
201
|
define_method(:flush) do
|
194
202
|
# puts 'flush'
|
195
|
-
# require'pry';binding.pry
|
196
203
|
target_state = Hash[@parameters.map { |k, v| [k, v.value] }]
|
197
204
|
# remove puppet's injected metaparams
|
198
205
|
target_state.delete(:loglevel)
|
199
|
-
target_state = my_provider.canonicalize(context, [target_state]).first if
|
206
|
+
target_state = my_provider.canonicalize(context, [target_state]).first if feature_support?('canonicalize')
|
200
207
|
|
201
208
|
retrieve unless @rapi_current_state
|
202
209
|
|
@@ -205,10 +212,44 @@ module Puppet::ResourceApi
|
|
205
212
|
|
206
213
|
Puppet.debug("Target State: #{target_state.inspect}")
|
207
214
|
|
208
|
-
|
215
|
+
if feature_support?('supports_noop')
|
216
|
+
my_provider.set(context, { title => { is: @rapi_current_state, should: target_state } }, noop: noop?)
|
217
|
+
else
|
218
|
+
my_provider.set(context, title => { is: @rapi_current_state, should: target_state }) unless noop?
|
219
|
+
end
|
209
220
|
raise 'Execution encountered an error' if context.failed?
|
210
221
|
end
|
211
222
|
|
223
|
+
define_method(:strict_check) do |current_state|
|
224
|
+
return if Puppet.settings[:strict] == :off
|
225
|
+
|
226
|
+
# if strict checking is on we must notify if the values are changed by canonicalize
|
227
|
+
# make a deep copy to perform the operation on and to compare against later
|
228
|
+
state_clone = Marshal.load(Marshal.dump(current_state))
|
229
|
+
state_clone = my_provider.canonicalize(context, [state_clone]).first
|
230
|
+
|
231
|
+
# compare the clone against the current state to see if changes have been made by canonicalize
|
232
|
+
return unless state_clone && (current_state != state_clone)
|
233
|
+
|
234
|
+
#:nocov:
|
235
|
+
# codecov fails to register this multiline as covered, even though simplecov does.
|
236
|
+
message = <<MESSAGE.strip
|
237
|
+
#{definition[:name]}[#{current_state[namevar_name]}]#get has not provided canonicalized values.
|
238
|
+
Returned values: #{current_state.inspect}
|
239
|
+
Canonicalized values: #{state_clone.inspect}
|
240
|
+
MESSAGE
|
241
|
+
#:nocov:
|
242
|
+
|
243
|
+
case Puppet.settings[:strict]
|
244
|
+
when :warning
|
245
|
+
Puppet.warning(message)
|
246
|
+
when :error
|
247
|
+
raise Puppet::Error, message
|
248
|
+
end
|
249
|
+
|
250
|
+
return nil
|
251
|
+
end
|
252
|
+
|
212
253
|
define_singleton_method(:context) do
|
213
254
|
@context ||= PuppetContext.new(definition[:name])
|
214
255
|
end
|
@@ -216,6 +257,24 @@ module Puppet::ResourceApi
|
|
216
257
|
def context
|
217
258
|
self.class.context
|
218
259
|
end
|
260
|
+
|
261
|
+
[:autorequire, :autobefore, :autosubscribe, :autonotify].each do |auto|
|
262
|
+
next unless definition[auto]
|
263
|
+
|
264
|
+
definition[auto].each do |type, values|
|
265
|
+
Puppet.debug("Registering #{auto} for #{type}: #{values.inspect}")
|
266
|
+
send(auto, type.downcase.to_sym) do
|
267
|
+
[values].flatten.map do |v|
|
268
|
+
match = %r{\A\$(.*)\Z}.match(v) if v.is_a? String
|
269
|
+
if match.nil?
|
270
|
+
v
|
271
|
+
else
|
272
|
+
self[match[1].to_sym]
|
273
|
+
end
|
274
|
+
end
|
275
|
+
end
|
276
|
+
end
|
277
|
+
end
|
219
278
|
end
|
220
279
|
end
|
221
280
|
module_function :register_type
|
@@ -16,6 +16,16 @@ class Puppet::ResourceApi::BaseContext
|
|
16
16
|
@failed
|
17
17
|
end
|
18
18
|
|
19
|
+
def feature_support?(feature)
|
20
|
+
supported = Puppet::Type.type(@typename).feature_support?(feature)
|
21
|
+
if supported
|
22
|
+
Puppet.debug("#{@typename} supports `#{feature}`")
|
23
|
+
else
|
24
|
+
Puppet.debug("#{@typename} does not support `#{feature}`")
|
25
|
+
end
|
26
|
+
supported
|
27
|
+
end
|
28
|
+
|
19
29
|
[:debug, :info, :notice, :warning, :err].each do |level|
|
20
30
|
define_method(level) do |*args|
|
21
31
|
if args.length == 1
|
@@ -2,37 +2,40 @@
|
|
2
2
|
module Puppet::ResourceApi
|
3
3
|
# A trivial class to provide the functionality required to push data through the existing type/provider parts of puppet
|
4
4
|
class TypeShim
|
5
|
-
attr_reader :values, :typename
|
5
|
+
attr_reader :values, :typename, :namevar
|
6
6
|
|
7
|
-
def initialize(title, resource_hash, typename)
|
7
|
+
def initialize(title, resource_hash, typename, namevarname)
|
8
8
|
# internalize and protect - needs to go deeper
|
9
|
-
@values
|
9
|
+
@values = resource_hash.dup
|
10
10
|
# "name" is a privileged key
|
11
|
-
@values[
|
12
|
-
@typename = typename
|
11
|
+
@values[namevarname] = title
|
13
12
|
@values.freeze
|
13
|
+
|
14
|
+
@typename = typename
|
15
|
+
@namevar = namevarname
|
14
16
|
end
|
15
17
|
|
16
18
|
def to_resource
|
17
|
-
ResourceShim.new(@values, @typename)
|
19
|
+
ResourceShim.new(@values, @typename, @namevar)
|
18
20
|
end
|
19
21
|
|
20
22
|
def name
|
21
|
-
values[
|
23
|
+
values[@namevar]
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
25
27
|
# A trivial class to provide the functionality required to push data through the existing type/provider parts of puppet
|
26
28
|
class ResourceShim
|
27
|
-
attr_reader :values, :typename
|
29
|
+
attr_reader :values, :typename, :namevar
|
28
30
|
|
29
|
-
def initialize(resource_hash, typename)
|
31
|
+
def initialize(resource_hash, typename, namevarname)
|
30
32
|
@values = resource_hash.dup.freeze # whatevs
|
31
33
|
@typename = typename
|
34
|
+
@namevar = namevarname
|
32
35
|
end
|
33
36
|
|
34
37
|
def title
|
35
|
-
values[
|
38
|
+
values[@namevar]
|
36
39
|
end
|
37
40
|
|
38
41
|
def prune_parameters(*_args)
|
@@ -41,12 +44,12 @@ module Puppet::ResourceApi
|
|
41
44
|
end
|
42
45
|
|
43
46
|
def to_manifest
|
44
|
-
(["#{@typename} { #{values[
|
47
|
+
(["#{@typename} { #{values[@namevar].inspect}: "] + values.keys.reject { |k| k == @namevar }.map { |k| " #{k} => #{Puppet::Parameter.format_value_for_display(values[k])}," } + ['}']).join("\n")
|
45
48
|
end
|
46
49
|
|
47
50
|
# Convert our resource to yaml for Hiera purposes.
|
48
51
|
def to_hierayaml
|
49
|
-
([" #{values[
|
52
|
+
([" #{values[@namevar]}: "] + values.keys.reject { |k| k == @namevar }.map { |k| " #{k}: #{Puppet::Parameter.format_value_for_display(values[k])}" }).join("\n") + "\n"
|
50
53
|
end
|
51
54
|
end
|
52
55
|
end
|
@@ -7,7 +7,12 @@ module Puppet::ResourceApi
|
|
7
7
|
class SimpleProvider
|
8
8
|
def set(context, changes)
|
9
9
|
changes.each do |name, change|
|
10
|
-
is =
|
10
|
+
is = if context.feature_support?('simple_get_filter')
|
11
|
+
change.key?(:is) ? change[:is] : (get(context, [name]) || []).find { |r| r[:name] == name }
|
12
|
+
else
|
13
|
+
change.key?(:is) ? change[:is] : (get(context) || []).find { |r| r[:name] == name }
|
14
|
+
end
|
15
|
+
|
11
16
|
should = change[:should]
|
12
17
|
|
13
18
|
is = { name: name, ensure: 'absent' } if is.nil?
|
data/puppet-resource_api.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet-resource_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Schmitt
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-03-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hocon
|
@@ -32,6 +32,7 @@ extensions: []
|
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
34
|
- ".dependency_decisions.yml"
|
35
|
+
- ".fixtures.yml"
|
35
36
|
- ".gitignore"
|
36
37
|
- ".rspec"
|
37
38
|
- ".rubocop.yml"
|
@@ -76,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
77
|
version: '0'
|
77
78
|
requirements: []
|
78
79
|
rubyforge_project:
|
79
|
-
rubygems_version: 2.
|
80
|
+
rubygems_version: 2.7.6
|
80
81
|
signing_key:
|
81
82
|
specification_version: 4
|
82
83
|
summary: This library provides a simple way to write new native resources for puppet.
|