You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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/):
*[Actual provider with validation and xml processing](https://github.com/puppetlabs/puppetlabs-panos/blob/master/lib/puppet/provider/panos_address/panos_address.rb)
7
+
*[New unit tests](https://github.com/puppetlabs/puppetlabs-panos/blob/master/spec/unit/puppet/provider/panos_provider_spec.rb) for 100% coverage.
8
+
9
+
## [Find the full Resource API documentation here](https://github.com/puppetlabs/puppet-specifications/blob/master/language/resource-api/README.md)
10
+
11
+
## Related Documents
12
+
13
+
* The [Resource API specs](https://github.com/puppetlabs/puppet-specifications/blob/master/language/resource-api/README.md) describes details of all the capabilities of this gem.
14
+
* The [puppetlabs-hue module](https://github.com/puppetlabs/puppetlabs-hue) is a very simple example for using the Resource API for remote resources.
15
+
* The [meraki module](https://github.com/meraki/puppet-module) is a full example for using the Resource API for remote resources.
16
+
* This [Introduction to Testing Puppet Modules](https://www.netways.de/index.php?id=3445#c44135) talk describes rspec usage in more detail.
17
+
* The [RSpec docs](https://relishapp.com/rspec) provide an overview of the capabilities of rspec.
18
+
* Read [betterspecs](http://www.betterspecs.org/) for general guidelines on what is considered good specs.
19
+
20
+
4
21
5
22
## Deployment
6
23
@@ -112,6 +129,8 @@ The following keys are available for defining attributes:
112
129
*`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.
113
130
*`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.
114
131
132
+
Further information about types can be found in The [Resource API](https://github.com/puppetlabs/puppet-specifications/blob/master/language/resource-api/README.md#resource-definition-type)
133
+
115
134
### Writing the Provider
116
135
117
136
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`:
@@ -168,6 +187,11 @@ The `get(context)` method returns a list of hashes describing the resources that
168
187
169
188
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.
*[Implmentation of simple providers](https://github.com/puppetlabs/puppet-specifications/blob/master/language/resource-api/README.md#implementing-simple-providers)
The generated unit tests in `spec/unit/puppet/provider/foo_spec.rb` get automatically evaluated with `pdk test unit`.
@@ -262,9 +286,7 @@ Do not use the following keywords when writing a schema:
262
286
263
287
After the device class, transport class and transport schema have been implemented, `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).
264
288
265
-
#### Transport/device specific providers
266
-
267
-
To allow modules to deal with different backends independently, the Resource API implements a mechanism to use different API providers side by side. For a given transport/device class (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`.
289
+
* Further reading can be found in The [Resource API](https://github.com/puppetlabs/puppet-specifications/blob/master/language/resource-api/README.md#transports).
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.
316
+
### Getting Started
317
+
1. Download the [Puppet Development Kit](https://puppet.com/download-puppet-development-kit).
318
+
2. Create a [new module](https://puppet.com/docs/pdk/latest/pdk_generating_modules.html) by running `pdk new module <MODULE_NAME>`.
319
+
3. Open `.sync.yml` and add the follwing code to to add the `puppet-resource-api` gem:
320
+
```
321
+
# .sync.yml
322
+
---
323
+
Gemfile:
324
+
optional:
325
+
':development':
326
+
- gem: 'puppet-resource_api'
327
+
spec/spec_helper.rb:
328
+
mock_with: ':rspec'
329
+
```
330
+
4. Run `pdk update` to apply the changes.
331
+
5. Run `pdk new provider <provider_name>` to create the type and provider files.
295
332
296
-
The [hue_rsapi module](https://github.com/da-ar/hue_rsapi) is a very simple example for using the Resource API for remote resources.
333
+
### The Type, Provider and Transport
334
+
The type is a template for the nessesary resources such as `name` and `ensure`. More attributes can be added, as well as modified to match our resources.
297
335
298
-
The [meraki module](https://github.com/meraki/puppet-module) is a full example for using the Resource API for remote resources.
336
+
The provider reads and enforces the state. An `initialize` method can be used for establising connection. `get(context)` can be used to et a hash list of resources on the target system.
337
+
The `create`/`update`/`delete` methods get called by the `SimpleProvider` base-class to change the system as requested by the catalog.
338
+
`should`contins the attriute hash with the values in the catalog.
339
+
See full description above for examples.
299
340
300
-
This [Introduction to Testing Puppet Modules](https://www.netways.de/index.php?id=3445#c44135) talk describes rspec usage in more detail.
341
+
Remote resource support is enable thourhg the `transport` class, which manages connections and information to and form remote resources. See above for an example transport class and a fll list of keywords for the transport class.
301
342
302
-
The [RSpec docs](https://relishapp.com/rspec) provide an overview of the capabilities of rspec.
343
+
For more detailed explainations, refer to the content above, or the [Resource API](https://github.com/puppetlabs/puppet-specifications/blob/master/language/resource-api/README.md) specification.
303
344
304
-
Read [betterspecs](http://www.betterspecs.org/) for general guidelines on what is considered good specs.
345
+
## Contributing
346
+
We are always welcoming bug reports and pull requests on the Resource API, so that we can continue to improve it to the best of our ability. If you would like to contribute, [have a look at our GitHub](https://github.com/puppetlabs/puppet-resource_api).
0 commit comments