Skip to content

Commit 7e89026

Browse files
authored
Merge pull request #199 from puppetlabs/MODULES-9258
(MODULES-9258) Improve referencing and add summary
2 parents f5e85bc + 964353e commit 7e89026

File tree

1 file changed

+53
-15
lines changed

1 file changed

+53
-15
lines changed

README.md

Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
11
# 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)
22

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.
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/):
4+
* [Base provider](https://github.com/puppetlabs/puppetlabs-panos/blob/master/lib/puppet/provider/panos_provider.rb)
5+
* [Type](https://github.com/puppetlabs/puppetlabs-panos/blob/master/lib/puppet/type/panos_address.rb)
6+
* [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+
421

522
## Deployment
623

@@ -112,6 +129,8 @@ The following keys are available for defining attributes:
112129
* `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.
113130
* `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.
114131

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+
115134
### Writing the Provider
116135

117136
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
168187

169188
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.
170189

190+
Further reading can be found in the Resource API:
191+
* [Resource Implementation](https://github.com/puppetlabs/puppet-specifications/blob/master/language/resource-api/README.md#resource-implementation-provider)
192+
* [Implmentation of simple providers](https://github.com/puppetlabs/puppet-specifications/blob/master/language/resource-api/README.md#implementing-simple-providers)
193+
* [Provider Features](https://github.com/puppetlabs/puppet-specifications/blob/master/language/resource-api/README.md#provider-features)
194+
171195
### Unit testing
172196

173197
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:
262286
263287
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).
264288

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).
268290

269291
### Puppet backwards compatibility
270292

@@ -289,19 +311,39 @@ module Puppet::Util::NetworkDevice::Device_type
289311
end
290312
```
291313

292-
## Further reading
314+
## Summary
293315

294-
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.
295332

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.
297335

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.
299340

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.
301342

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.
303344

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).
305347

306348
## Known Issues
307349

@@ -336,10 +378,6 @@ Future possibilities:
336378
* [Multiple Providers](https://tickets.puppetlabs.com/browse/PDK-530)
337379
* [Commands API](https://tickets.puppetlabs.com/browse/PDK-847)
338380

339-
## Contributing
340-
341-
Bug reports and pull requests are welcome on GitHub at https://github.com/puppetlabs/puppet-resource_api.
342-
343381
### Cutting a release
344382

345383
In some cases we need to manually cut a release outside of the regular puppet

0 commit comments

Comments
 (0)