puppet-resource_api 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -0
- data/README.md +26 -26
- data/lib/puppet/resource_api.rb +3 -5
- data/lib/puppet/resource_api/glue.rb +13 -7
- data/lib/puppet/resource_api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38b8eb932adfb3053e1c50635928a012dc633d23
|
4
|
+
data.tar.gz: d26dbf883c69aab91c4966cfdda0856a8fd8cd57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 583c982b7c88fc4d000c9b42f883f7996b0afac1375ea2b178b7fc6c377091b40da40a5295214fea2d10f29f1ec253fb8d36a048febb14df57aea5932b186398
|
7
|
+
data.tar.gz: d3856e0fb094b7c944a6ea773a19106f67f269476f56e0a22a2f7fe8376270a639fdecaff575926033778532f0b533563bf28c757f826e3ebb8e1be6643bd33e
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,19 @@
|
|
3
3
|
All significant changes to this repo will be summarized in this file.
|
4
4
|
|
5
5
|
|
6
|
+
## [v0.3.0](https://github.com/puppetlabs/puppet-resource_api/tree/v0.3.0) (2018-02-21)
|
7
|
+
[Full Changelog](https://github.com/puppetlabs/puppet-resource_api/compare/v0.2.2...v0.3.0)
|
8
|
+
|
9
|
+
**Implemented enhancements:**
|
10
|
+
|
11
|
+
- \(FM-6797\) Add debug logging of current and target states [\#21](https://github.com/puppetlabs/puppet-resource_api/pull/21) ([da-ar](https://github.com/da-ar))
|
12
|
+
- \(PDK-803\) Add YAML output for resources [\#19](https://github.com/puppetlabs/puppet-resource_api/pull/19) ([shermdog](https://github.com/shermdog))
|
13
|
+
- Edits on resource api readme [\#17](https://github.com/puppetlabs/puppet-resource_api/pull/17) ([clairecadman](https://github.com/clairecadman))
|
14
|
+
|
15
|
+
**Fixed bugs:**
|
16
|
+
|
17
|
+
- \(PDK-569\) `puppet resource` now displays type name correctly [\#18](https://github.com/puppetlabs/puppet-resource_api/pull/18) ([tphoney](https://github.com/tphoney))
|
18
|
+
|
6
19
|
## [v0.2.2](https://github.com/puppetlabs/puppet-resource_api/tree/v0.2.2) (2018-01-25)
|
7
20
|
[Full Changelog](https://github.com/puppetlabs/puppet-resource_api/compare/v0.2.1...v0.2.2)
|
8
21
|
|
@@ -10,6 +23,10 @@ All significant changes to this repo will be summarized in this file.
|
|
10
23
|
|
11
24
|
- make the server parts JRuby compatible [\#15](https://github.com/puppetlabs/puppet-resource_api/pull/15) ([DavidS](https://github.com/DavidS))
|
12
25
|
|
26
|
+
**Merged pull requests:**
|
27
|
+
|
28
|
+
- Release prep v0.2.2 [\#16](https://github.com/puppetlabs/puppet-resource_api/pull/16) ([DavidS](https://github.com/DavidS))
|
29
|
+
|
13
30
|
## [v0.2.1](https://github.com/puppetlabs/puppet-resource_api/tree/v0.2.1) (2018-01-24)
|
14
31
|
[Full Changelog](https://github.com/puppetlabs/puppet-resource_api/compare/v0.2.0...v0.2.1)
|
15
32
|
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@ This is an implementation of the [Resource API](https://github.com/DavidS/puppet
|
|
6
6
|
## Getting started
|
7
7
|
|
8
8
|
* Install the [PDK](https://puppet.com/download-puppet-development-kit).
|
9
|
-
* As of
|
9
|
+
* As of January 2018, the required PDK features are still in development.
|
10
10
|
See [PDK-506](https://tickets.puppetlabs.com/browse/PDK-506) for progress.
|
11
11
|
|
12
12
|
* 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.
|
@@ -58,7 +58,7 @@ pdk (INFO): Creating '/home/david/git/example/spec/unit/puppet/provider/foo/foo_
|
|
58
58
|
~/git/example$
|
59
59
|
```
|
60
60
|
|
61
|
-
The three generated files are the type, the
|
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:
|
62
62
|
|
63
63
|
```
|
64
64
|
~/git/example$ pdk test unit
|
@@ -72,7 +72,7 @@ The three generated files are the type, the actual implementation, and unit test
|
|
72
72
|
|
73
73
|
### Writing the Type
|
74
74
|
|
75
|
-
The type contains the shape of your resources. The template
|
75
|
+
The type contains the shape of your resources. The template provides the necessary `name` and `ensure` attributes. You can modify their description and the name's type to match your resource. Add more attributes as you need.
|
76
76
|
|
77
77
|
```ruby
|
78
78
|
# lib/puppet/type/foo.rb
|
@@ -99,18 +99,18 @@ Puppet::ResourceApi.register_type(
|
|
99
99
|
```
|
100
100
|
|
101
101
|
The following keys are available for defining attributes:
|
102
|
-
* `type`: the
|
102
|
+
* `type`: the Puppet 4 data type allowed in this attribute. You can use all [data types](https://puppet.com/docs/puppet/latest/lang_data_abstract.html#parent-types) matching `Scalar` and `Data`.
|
103
103
|
* `desc`: a string describing this attribute. This is used in creating the automated API docs with [puppet-strings](https://github.com/puppetlabs/puppet-strings).
|
104
|
-
* `default`: a default value
|
105
|
-
* `behaviour`/`behavior`: how the attribute behaves.
|
106
|
-
* `namevar`: marks an attribute as part of the "primary key"
|
107
|
-
* `init_only`: this attribute can only be set during creation of the resource. Its value will be reported going forward, but trying to change it later
|
108
|
-
* `read_only`: values for this attribute will be returned by `get()`, but `set()` is not able to change them. Values for this should never be specified in a manifest. For example the checksum of a file, or the MAC address of a network interface.
|
109
|
-
* `parameter`: these attributes influence how the provider behaves, and cannot be read from the target system. For example, the target file on inifile, or credentials to access an API.
|
104
|
+
* `default`: a default value used by the runtime environment; when the caller does not specify a value for this attribute.
|
105
|
+
* `behaviour`/`behavior`: how the attribute behaves. The current available values include:
|
106
|
+
* `namevar`: marks an attribute as part of the "primary key" or "identity" of the resource. A given set of `namevar` values needs to distinctively identify an instance.
|
107
|
+
* `init_only`: this attribute can only be set during the creation of the resource. Its value will be reported going forward, but trying to change it later leads to an error. For example, the base image for a VM or the UID of a user.
|
108
|
+
* `read_only`: values for this attribute will be returned by `get()`, but `set()` is not able to change them. Values for this should never be specified in a manifest. For example, the checksum of a file, or the MAC address of a network interface.
|
109
|
+
* `parameter`: these attributes influence how the provider behaves, and cannot be read from the target system. For example, the target file on inifile, or the credentials to access an API.
|
110
110
|
|
111
111
|
### Writing the Provider
|
112
112
|
|
113
|
-
The provider is the
|
113
|
+
The provider is the most important part of your new resource, as it reads and enforces state. Here is the example generated by `pdk new provider`:
|
114
114
|
|
115
115
|
```ruby
|
116
116
|
require 'puppet/resource_api'
|
@@ -152,7 +152,7 @@ end
|
|
152
152
|
|
153
153
|
The optional `initialize` method can be used to set up state that is available throughout the execution of the catalog. This is most often used for locally acting providers to set up command helpers, or to establish a connection, when talking to a service (e.g. when managing a database).
|
154
154
|
|
155
|
-
The `get(context)` method returns a list of hashes describing the resources that are currently on the target system. The basic example would always return an empty list. Here is an example of
|
155
|
+
The `get(context)` method returns a list of hashes describing the resources that are currently on the target system. The basic example would always return an empty list. Here is an example of resources that could be returned from this:
|
156
156
|
|
157
157
|
```ruby
|
158
158
|
[
|
@@ -167,7 +167,7 @@ The `get(context)` method returns a list of hashes describing the resources that
|
|
167
167
|
]
|
168
168
|
```
|
169
169
|
|
170
|
-
The `create`/`update`/`delete` methods get called by the `SimpleProvider` base-class to change the system as requested by the catalog. The `name` argument is the name of the resource being processed. `should` contains the attribute hash - in the same format as `get` returns - with the values in the catalog.
|
170
|
+
The `create`/`update`/`delete` methods get called by the `SimpleProvider` base-class to change the system as requested by the catalog. The `name` argument is the name of the resource that is being processed. `should` contains the attribute hash - in the same format as `get` returns - with the values in the catalog.
|
171
171
|
|
172
172
|
### Unit testing
|
173
173
|
|
@@ -175,33 +175,33 @@ The generated unit tests in `spec/unit/puppet/provider/foo_spec.rb` get automati
|
|
175
175
|
|
176
176
|
### Further Reading
|
177
177
|
|
178
|
-
The [Resource API](https://github.com/DavidS/puppet-specifications/blob/resourceapi/language/resource-api/README.md) describes
|
178
|
+
The [Resource API](https://github.com/DavidS/puppet-specifications/blob/resourceapi/language/resource-api/README.md) describes details of all the capabilities of this gem.
|
179
179
|
|
180
180
|
This [Introduction to Testing Puppet Modules](https://www.netways.de/index.php?id=3445#c44135) talk describes rspec usage in more detail.
|
181
181
|
|
182
|
-
The [RSpec docs](https://relishapp.com/rspec)
|
182
|
+
The [RSpec docs](https://relishapp.com/rspec) provide an overview of the capabilities of rspec.
|
183
183
|
|
184
|
-
Read [betterspecs](http://www.betterspecs.org/) for general guidelines on what
|
184
|
+
Read [betterspecs](http://www.betterspecs.org/) for general guidelines on what is considered good specs.
|
185
185
|
|
186
186
|
## Known Issues
|
187
187
|
|
188
|
-
This gem is still under heavy development. This section is a living document of what
|
188
|
+
This gem is still under heavy development. This section is a living document of what is already done, and what items are still outstanding.
|
189
189
|
|
190
|
-
|
191
|
-
*
|
192
|
-
*
|
193
|
-
*
|
194
|
-
*
|
190
|
+
Currently working:
|
191
|
+
* Basic type and provider definition, using `name`, `desc`, and `attributes`.
|
192
|
+
* The `canonicalize` and `remote_resource` features.
|
193
|
+
* All the logging facilities.
|
194
|
+
* Executing the new provider under the following commands:
|
195
195
|
* `puppet apply`
|
196
196
|
* `puppet resource`
|
197
197
|
* `puppet agent`
|
198
198
|
* `puppet device` (if applicable)
|
199
199
|
|
200
200
|
|
201
|
-
There are still a few notable gaps between the implementation
|
202
|
-
* Only a single runtime environment (the
|
203
|
-
* `auto*` definitions
|
204
|
-
*
|
201
|
+
There are still a few notable gaps between the implementation and the specification:
|
202
|
+
* Only a single runtime environment (the Puppet commands) is currently implemented.
|
203
|
+
* `auto*` definitions.
|
204
|
+
* The Commands API is mostly implemented, but deployment is blocked on upstream work (PDK-580). Use regular Ruby `system()` calls as a workaround, with their underlying encoding and safety issues.
|
205
205
|
|
206
206
|
## Development
|
207
207
|
|
data/lib/puppet/resource_api.rb
CHANGED
@@ -156,7 +156,7 @@ module Puppet::ResourceApi
|
|
156
156
|
# force autoloading of the provider
|
157
157
|
provider(name)
|
158
158
|
my_provider.get(context).map do |resource_hash|
|
159
|
-
Puppet::ResourceApi::TypeShim.new(resource_hash[namevar_name], resource_hash)
|
159
|
+
Puppet::ResourceApi::TypeShim.new(resource_hash[namevar_name], resource_hash, name)
|
160
160
|
end
|
161
161
|
end
|
162
162
|
|
@@ -176,9 +176,8 @@ module Puppet::ResourceApi
|
|
176
176
|
result[:ensure] = :absent
|
177
177
|
end
|
178
178
|
|
179
|
-
# puts "retrieved #{current_state.inspect}"
|
180
|
-
|
181
179
|
@rapi_current_state = current_state
|
180
|
+
Puppet.debug("Current State: #{@rapi_current_state.inspect}")
|
182
181
|
result
|
183
182
|
end
|
184
183
|
|
@@ -195,8 +194,7 @@ module Puppet::ResourceApi
|
|
195
194
|
# require 'pry'; binding.pry
|
196
195
|
return if @rapi_current_state == target_state
|
197
196
|
|
198
|
-
|
199
|
-
# puts "target_state: #{target_state.inspect}"
|
197
|
+
Puppet.debug("Target State: #{target_state.inspect}")
|
200
198
|
|
201
199
|
my_provider.set(context, title => { is: @rapi_current_state, should: target_state })
|
202
200
|
raise 'Execution encountered an error' if context.failed?
|
@@ -2,18 +2,19 @@
|
|
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
|
5
|
+
attr_reader :values, :typename
|
6
6
|
|
7
|
-
def initialize(title, resource_hash)
|
7
|
+
def initialize(title, resource_hash, typename)
|
8
8
|
# internalize and protect - needs to go deeper
|
9
9
|
@values = resource_hash.dup
|
10
10
|
# "name" is a privileged key
|
11
11
|
@values[:name] = title
|
12
|
+
@typename = typename
|
12
13
|
@values.freeze
|
13
14
|
end
|
14
15
|
|
15
16
|
def to_resource
|
16
|
-
ResourceShim.new(@values)
|
17
|
+
ResourceShim.new(@values, @typename)
|
17
18
|
end
|
18
19
|
|
19
20
|
def name
|
@@ -23,10 +24,11 @@ module Puppet::ResourceApi
|
|
23
24
|
|
24
25
|
# A trivial class to provide the functionality required to push data through the existing type/provider parts of puppet
|
25
26
|
class ResourceShim
|
26
|
-
attr_reader :values
|
27
|
+
attr_reader :values, :typename
|
27
28
|
|
28
|
-
def initialize(resource_hash)
|
29
|
+
def initialize(resource_hash, typename)
|
29
30
|
@values = resource_hash.dup.freeze # whatevs
|
31
|
+
@typename = typename
|
30
32
|
end
|
31
33
|
|
32
34
|
def title
|
@@ -39,8 +41,12 @@ module Puppet::ResourceApi
|
|
39
41
|
end
|
40
42
|
|
41
43
|
def to_manifest
|
42
|
-
#
|
43
|
-
|
44
|
+
(["#{@typename} { #{values[:name].inspect}: "] + values.keys.reject { |k| k == :name }.map { |k| " #{k} => #{values[k].inspect}," } + ['}']).join("\n")
|
45
|
+
end
|
46
|
+
|
47
|
+
# Convert our resource to yaml for Hiera purposes.
|
48
|
+
def to_hierayaml
|
49
|
+
([" #{values[:name]}: "] + values.keys.reject { |k| k == :name }.map { |k| " #{k}: #{Puppet::Parameter.format_value_for_display(values[k])}" }).join("\n") + "\n"
|
44
50
|
end
|
45
51
|
end
|
46
52
|
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: 0.
|
4
|
+
version: 0.3.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-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: childprocess
|