Skip to content

Commit c932bb0

Browse files
da-arWill Meek
authored andcommitted
(FM-7819) - update readme to include transports
This commit updates the readme to mention the transport class and gives an example of a pass through on the device class.
1 parent 0c6ccda commit c932bb0

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

README.md

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,19 +172,38 @@ The `create`/`update`/`delete` methods get called by the `SimpleProvider` base-c
172172

173173
The generated unit tests in `spec/unit/puppet/provider/foo_spec.rb` get automatically evaluated with `pdk test unit`.
174174

175+
## Remote Resources
176+
177+
Support for remote resources is enabled through the use of a `transport`. A transport class conatins the code for managing connections and processing information to/from the remote resource. Please see the [RSAPI specification](https://github.com/puppetlabs/puppet-specifications/tree/master/language/resource-api#transport) document on how to create a transport.
178+
175179
### `puppet device` support
176180

177-
To support remote resources using `puppet device`, a few more steps are needed. First a `Puppet::Util::NetworkDevice::<device type>::Device` class needs to exist, which provides facts and connection management . That device class can inherit from `Puppet::Util::NetworkDevice::Simple::Device` to receive a simple default configuration parser using hocon.
181+
To connect to a remote resource through `puppet device` a `transport` must be called through a device shim.
178182

179-
The provider needs to specify the `remote_resource` feature to enable the second part of the machinery.
183+
```ruby
184+
# lib/puppet/util/network_device/remote_thing.rb
185+
186+
require 'puppet'
187+
require 'puppet/resource_api/transport/wrapper'
188+
# force registering the transport
189+
require 'puppet/transport/schema/remote_thing'
190+
191+
module Puppet::Util::NetworkDevice::RemoteThing
192+
class Device < Puppet::ResourceApi::Transport::Wrapper
193+
def initialize(url_or_config, _options = {})
194+
super('remote_thing', url_or_config)
195+
end
196+
end
197+
end
198+
```
180199

181200
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).
182201

183-
#### Device-specific providers
202+
#### Transport/Device specific providers
184203

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`.
204+
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 transport/device (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`.
186205

187-
### Further Reading
206+
## Further Reading
188207

189208
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.
190209

0 commit comments

Comments
 (0)