puppet-resource_api 1.5.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9e2e55069c15f749148ae6c4a9fc626e77191f0ebba51123893f5d82c6d22a9d
4
- data.tar.gz: 7add3eb881e226501009caf3150001ee7d83891e301a5d41081fffe3dd77d4cf
3
+ metadata.gz: 1aa62aa45972c81860d638d83bc416d5e2f8c459f2c05ca95d60e5df470bed21
4
+ data.tar.gz: 6c5783f8b8fb63b9502166ce696a923191b3a20e77bcfb4f2c61e3331fa713fc
5
5
  SHA512:
6
- metadata.gz: d34e5647c07817985e6ec9029e2e7635dc94f0873943af524ae737d27166fe5da76a7bbc8649785d46f7aa0a99097c97e70478a6d797b0cb28562734d1d478d7
7
- data.tar.gz: 1341a7774319c44650747f1ccba7178e70db1dff676c019d7614ae1ee8fa94af5f33ecaff8eb51ad2942b6a97252e25c8c381f12088b7fd33f8bf07ebdce91d2
6
+ metadata.gz: 997ab672ae396571471897d1041a86ed86f70f38cc11816fb4df0128268a189b461a492738a674a207dbb0df544fcddb868b13c8c1d6d9b6930b195a012b3fa5
7
+ data.tar.gz: 3a4a058a1def23f378f0ca5cd1fa9cce0d0b3fa5f15e9c034a85ed5edd24486cca67e94a45a219ce7cfae51e88f6abda0728d4a661c1601d674d62e021cff413
data/.travis.yml CHANGED
@@ -54,6 +54,8 @@ matrix:
54
54
  env: PUPPET_GEM_VERSION='~> 4.7.0'
55
55
  - rvm: 2.5.1
56
56
  env: PUPPET_GEM_VERSION='https://github.com/puppetlabs/puppet.git#master'
57
+ - rvm: 2.5.1
58
+ env: PUPPET_GEM_VERSION='https://github.com/puppetlabs/puppet.git#6.0.x'
57
59
  notifications:
58
60
  hipchat:
59
61
  rooms:
data/CHANGELOG.md CHANGED
@@ -3,6 +3,25 @@
3
3
  All significant changes to this repo will be summarized in this file.
4
4
 
5
5
 
6
+ ## [v1.6.0](https://github.com/puppetlabs/puppet-resource_api/tree/v1.6.0) (2018-09-25)
7
+ [Full Changelog](https://github.com/puppetlabs/puppet-resource_api/compare/v1.5.0...v1.6.0)
8
+
9
+ **Implemented enhancements:**
10
+
11
+ - \(PDK-1185\) Implement allowances for device-specific providers [\#126](https://github.com/puppetlabs/puppet-resource_api/pull/126) ([DavidS](https://github.com/DavidS))
12
+ - \(PDK-1143\) Allow SimpleProvider to handle multiple namevars [\#125](https://github.com/puppetlabs/puppet-resource_api/pull/125) ([da-ar](https://github.com/da-ar))
13
+
14
+ **Fixed bugs:**
15
+
16
+ - Update README walkthrough [\#122](https://github.com/puppetlabs/puppet-resource_api/pull/122) ([AlmogCohen](https://github.com/AlmogCohen))
17
+
18
+ **Merged pull requests:**
19
+
20
+ - Update README [\#124](https://github.com/puppetlabs/puppet-resource_api/pull/124) ([clairecadman](https://github.com/clairecadman))
21
+ - Update README [\#123](https://github.com/puppetlabs/puppet-resource_api/pull/123) ([DavidS](https://github.com/DavidS))
22
+ - \(maint\) Add Travis job for Puppet 6.0.x branch [\#120](https://github.com/puppetlabs/puppet-resource_api/pull/120) ([da-ar](https://github.com/da-ar))
23
+ - Release prep for v1.5.0 [\#119](https://github.com/puppetlabs/puppet-resource_api/pull/119) ([DavidS](https://github.com/DavidS))
24
+
6
25
  ## [v1.5.0](https://github.com/puppetlabs/puppet-resource_api/tree/v1.5.0) (2018-09-12)
7
26
  [Full Changelog](https://github.com/puppetlabs/puppet-resource_api/compare/v1.4.2...v1.5.0)
8
27
 
data/Gemfile CHANGED
@@ -24,6 +24,8 @@ group :tests do
24
24
  # the test gems required for module testing
25
25
  gem 'puppetlabs_spec_helper', '~> 2.7'
26
26
  gem 'rspec-puppet'
27
+
28
+ gem 'CFPropertyList'
27
29
  end
28
30
 
29
31
  group :development do
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # Puppet::ResourceApi [![TravisCI Build Status](https://travis-ci.org/puppetlabs/puppet-resource_api.svg?branch=master)](https://travis-ci.org/puppetlabs/puppet-resource_api) [![Appveyor Build status](https://ci.appveyor.com/api/projects/status/8o9s1ax0hs8lm5fd/branch/master?svg=true)](https://ci.appveyor.com/project/puppetlabs/puppet-resource-api/branch/master) [![codecov](https://codecov.io/gh/puppetlabs/puppet-resource_api/branch/master/graph/badge.svg)](https://codecov.io/gh/puppetlabs/puppet-resource_api)
2
2
 
3
- This is an implementation of the [Resource API](https://github.com/puppetlabs/puppet-specifications/blob/master/language/resource-api/README.md) proposal. Find a working example of a new-style provider in the [experimental puppetlabs-apt branch](https://github.com/DavidS/puppetlabs-apt/blob/resource-api-experiments/lib/puppet/provider/apt_key2/apt_key2.rb). There is also the corresponding [type](https://github.com/DavidS/puppetlabs-apt/blob/resource-api-experiments/lib/puppet/type/apt_key2.rb), [provider](https://github.com/DavidS/puppetlabs-apt/blob/resource-api-experiments/lib/puppet/provider/apt_key2/apt_key2.rb), and [new unit tests](https://github.com/DavidS/puppetlabs-apt/blob/resource-api-experiments/spec/unit/puppet/provider/apt_key2/apt_key2_spec.rb) for 100% coverage.
3
+ This is an implementation of the [Resource API](https://github.com/puppetlabs/puppet-specifications/blob/master/language/resource-api/README.md) specification. Find a working example of a new-style providers in the [Palo Alto Firewall module](https://github.com/puppetlabs/puppetlabs-panos/): [base provider](https://github.com/puppetlabs/puppetlabs-panos/blob/master/lib/puppet/provider/panos_provider.rb), [type](https://github.com/puppetlabs/puppetlabs-panos/blob/master/lib/puppet/type/panos_address.rb), [actual provider with validation and xml processing](https://github.com/puppetlabs/puppetlabs-panos/blob/master/lib/puppet/provider/panos_address/panos_address.rb), and [new unit tests](https://github.com/puppetlabs/puppetlabs-panos/blob/master/spec/unit/puppet/provider/panos_provider_spec.rb) for 100% coverage.
4
+
5
+ ## Deployment
6
+
7
+ The `puppet-resource_api` gem is part of the [Puppet 6 Platform](https://puppet.com/blog/introducing-puppet-6). With older versions of Puppet, you can use the [puppetlabs-resource_api module](https://forge.puppet.com/puppetlabs/resource_api) to install the gem on your servers and agents.
4
8
 
5
9
  ## Getting Started
6
10
 
@@ -8,7 +12,7 @@ This is an implementation of the [Resource API](https://github.com/puppetlabs/pu
8
12
 
9
13
  2. 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. To create a new module, run `pdk new module <MODULE_NAME>` from the command line, specifying the name of the module. Respond to the dialog questions.
10
14
 
11
- 3. To add the `puppet-resource_api` gem and enable "modern" rspec-style mocking, open the `sync.yml` file in your editor, and add the following content:
15
+ 3. To add the `puppet-resource_api` gem and enable "modern" rspec-style mocking, open the `.sync.yml` file in your editor, and add the following content:
12
16
 
13
17
  ```
14
18
  # .sync.yml
@@ -55,16 +59,17 @@ $ pdk new provider foo
55
59
  pdk (INFO): Creating '.../example/lib/puppet/type/foo.rb' from template.
56
60
  pdk (INFO): Creating '.../example/lib/puppet/provider/foo/foo.rb' from template.
57
61
  pdk (INFO): Creating '.../example/spec/unit/puppet/provider/foo/foo_spec.rb' from template.
62
+ pdk (INFO): Creating '.../example/spec/unit/puppet/type/foo_spec.rb' from template.
58
63
  $
59
64
  ```
60
65
 
61
- 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, which will look like this:
66
+ The four 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, which will look like this:
62
67
 
63
68
  ```
64
69
  $ pdk test unit
65
70
  [✔] Preparing to run the unit tests.
66
71
  [✔] Running unit tests.
67
- Evaluated 4 tests in 0.012065973 seconds: 0 failures, 0 pending.
72
+ Evaluated 5 tests in 0.012065973 seconds: 0 failures, 0 pending.
68
73
  [✔] Cleaning up after running unit tests.
69
74
  $
70
75
  ```
@@ -175,6 +180,10 @@ The provider needs to specify the `remote_resource` feature to enable the second
175
180
 
176
181
  After this, `puppet device` will be able to use the new provider, and supply it (through the device class) with the URL specified in the [`device.conf`](https://puppet.com/docs/puppet/5.3/config_file_device.html).
177
182
 
183
+ #### Device-specific providers
184
+
185
+ To allow modules to deal with different backends independently of each other, the Resource API also implements a mechanism to use different API providers side-by-side. For a given device type (see above), the Resource API will first try to load a `Puppet::Provider::TypeName::DeviceType` class from `lib/puppet/provider/type_name/device_type.rb`, before falling back to the regular provider at `Puppet::Provider::TypeName::TypeName`.
186
+
178
187
  ### Further Reading
179
188
 
180
189
  The [Resource API](https://github.com/puppetlabs/puppet-specifications/blob/master/language/resource-api/README.md) describes details of all the capabilities of this gem.
@@ -4,6 +4,7 @@ require 'puppet/resource_api/puppet_context' unless RUBY_PLATFORM == 'java'
4
4
  require 'puppet/resource_api/type_definition'
5
5
  require 'puppet/resource_api/version'
6
6
  require 'puppet/type'
7
+ require 'puppet/util/network_device'
7
8
 
8
9
  module Puppet::ResourceApi
9
10
  @warning_count = 0
@@ -54,7 +55,8 @@ module Puppet::ResourceApi
54
55
 
55
56
  # Keeps a copy of the provider around. Weird naming to avoid clashes with puppet's own `provider` member
56
57
  define_singleton_method(:my_provider) do
57
- @my_provider ||= Puppet::ResourceApi.load_provider(definition[:name]).new
58
+ @my_provider ||= Hash.new { |hash, key| hash[key] = Puppet::ResourceApi.load_provider(definition[:name]).new }
59
+ @my_provider[Puppet::Util::NetworkDevice.current.class]
58
60
  end
59
61
 
60
62
  # make the provider available in the instance's namespace
@@ -514,14 +516,48 @@ MESSAGE
514
516
  def load_provider(type_name)
515
517
  class_name = class_name_from_type_name(type_name)
516
518
  type_name_sym = type_name.to_sym
519
+ device_name = if Puppet::Util::NetworkDevice.current.nil?
520
+ nil
521
+ else
522
+ # extract the device type from the currently loaded device's class
523
+ Puppet::Util::NetworkDevice.current.class.name.split('::')[-2].downcase
524
+ end
525
+ device_class_name = class_name_from_type_name(device_name)
526
+
527
+ if device_name
528
+ device_name_sym = device_name.to_sym if device_name
529
+ load_device_provider(class_name, type_name_sym, device_class_name, device_name_sym)
530
+ else
531
+ load_default_provider(class_name, type_name_sym)
532
+ end
533
+ rescue NameError
534
+ if device_name # line too long # rubocop:disable Style/GuardClause
535
+ raise Puppet::DevError, "Found neither the device-specific provider class Puppet::Provider::#{class_name}::#{device_class_name} in puppet/provider/#{type_name}/#{device_name}"\
536
+ " nor the generic provider class Puppet::Provider::#{class_name}::#{class_name} in puppet/provider/#{type_name}/#{type_name}"
537
+ else
538
+ raise Puppet::DevError, "provider class Puppet::Provider::#{class_name}::#{class_name} not found in puppet/provider/#{type_name}/#{type_name}"
539
+ end
540
+ end
541
+ module_function :load_provider # rubocop:disable Style/AccessModifierDeclarations
517
542
 
543
+ def load_default_provider(class_name, type_name_sym)
518
544
  # loads the "puppet/provider/#{type_name}/#{type_name}" file through puppet
519
545
  Puppet::Type.type(type_name_sym).provider(type_name_sym)
520
546
  Puppet::Provider.const_get(class_name).const_get(class_name)
521
- rescue NameError
522
- raise Puppet::DevError, "class #{class_name} not found in puppet/provider/#{type_name}/#{type_name}"
523
547
  end
524
- module_function :load_provider # rubocop:disable Style/AccessModifierDeclarations
548
+ module_function :load_default_provider # rubocop:disable Style/AccessModifierDeclarations
549
+
550
+ def load_device_provider(class_name, type_name_sym, device_class_name, device_name_sym)
551
+ # loads the "puppet/provider/#{type_name}/#{device_name}" file through puppet
552
+ Puppet::Type.type(type_name_sym).provider(device_name_sym)
553
+ provider_module = Puppet::Provider.const_get(class_name)
554
+ if provider_module.const_defined?(device_class_name)
555
+ provider_module.const_get(device_class_name)
556
+ else
557
+ load_default_provider(class_name, type_name_sym)
558
+ end
559
+ end
560
+ module_function :load_device_provider # rubocop:disable Style/AccessModifierDeclarations
525
561
 
526
562
  def self.class_name_from_type_name(type_name)
527
563
  type_name.to_s.split('_').map(&:capitalize).join
@@ -22,17 +22,28 @@ module Puppet::ResourceApi
22
22
  is = { name: name, ensure: 'absent' } if is.nil?
23
23
  should = { name: name, ensure: 'absent' } if should.nil?
24
24
 
25
+ name_hash = if context.type.namevars.length > 1
26
+ # pass a name_hash containing the values of all namevars
27
+ name_hash = { title: name }
28
+ context.type.namevars.each do |namevar|
29
+ name_hash[namevar] = change[:should][namevar]
30
+ end
31
+ name_hash
32
+ else
33
+ name
34
+ end
35
+
25
36
  if is[:ensure].to_s == 'absent' && should[:ensure].to_s == 'present'
26
37
  context.creating(name) do
27
- create(context, name, should)
38
+ create(context, name_hash, should)
28
39
  end
29
40
  elsif is[:ensure].to_s == 'present' && should[:ensure].to_s == 'present'
30
41
  context.updating(name) do
31
- update(context, name, should)
42
+ update(context, name_hash, should)
32
43
  end
33
44
  elsif is[:ensure].to_s == 'present' && should[:ensure].to_s == 'absent'
34
45
  context.deleting(name) do
35
- delete(context, name)
46
+ delete(context, name_hash)
36
47
  end
37
48
  end
38
49
  end
@@ -1,5 +1,5 @@
1
1
  module Puppet
2
2
  module ResourceApi
3
- VERSION = '1.5.0'.freeze
3
+ VERSION = '1.6.0'.freeze
4
4
  end
5
5
  end
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: 1.5.0
4
+ version: 1.6.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-09-12 00:00:00.000000000 Z
11
+ date: 2018-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hocon
@@ -82,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
82
  version: '0'
83
83
  requirements: []
84
84
  rubyforge_project:
85
- rubygems_version: 2.7.6
85
+ rubygems_version: 2.7.3
86
86
  signing_key:
87
87
  specification_version: 4
88
88
  summary: This library provides a simple way to write new native resources for puppet.