Skip to content

Commit a94b611

Browse files
author
Will Meek
committed
(FM-7819) Readme updates with transport class example
This commit updates the readme with examples of the transport class and an example transport schema.
1 parent c932bb0 commit a94b611

File tree

1 file changed

+71
-8
lines changed

1 file changed

+71
-8
lines changed

README.md

Lines changed: 71 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,34 +174,97 @@ The generated unit tests in `spec/unit/puppet/provider/foo_spec.rb` get automati
174174

175175
## Remote Resources
176176

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.
177+
Support for remote resources is enabled through the use of a `transport` class. A transport class contains the code for managing connections and processing information to/from the remote resource. Please see the [Resource API specification](https://github.com/puppetlabs/puppet-specifications/tree/master/language/resource-api#transport) document on how to create a transport class.
178178

179179
### `puppet device` support
180180

181-
To connect to a remote resource through `puppet device` a `transport` must be called through a device shim.
181+
To connect to a remote resource through `puppet device` a `transport` class must be called through a device shim.
182+
183+
For example, the `device` class will be a pass through to `transport`:
182184

183185
```ruby
184-
# lib/puppet/util/network_device/remote_thing.rb
186+
# lib/puppet/util/network_device/device_type/device.rb
185187

186188
require 'puppet'
187189
require 'puppet/resource_api/transport/wrapper'
188-
# force registering the transport
189-
require 'puppet/transport/schema/remote_thing'
190+
# force registering the transport schema
191+
require 'puppet/transport/schema/device_type'
190192

191-
module Puppet::Util::NetworkDevice::RemoteThing
193+
module Puppet::Util::NetworkDevice::DeviceType
192194
class Device < Puppet::ResourceApi::Transport::Wrapper
193195
def initialize(url_or_config, _options = {})
194-
super('remote_thing', url_or_config)
196+
super('device_type', url_or_config)
197+
end
198+
end
199+
end
200+
```
201+
202+
This requires a `transport` class and schema, as detailed in the [Resource API specification](https://github.com/puppetlabs/puppet-specifications/tree/master/language/resource-api#transport), for example a transport class:
203+
204+
```ruby
205+
# lib/puppet/transport/device_type.rb
206+
module Puppet::Transport
207+
# The main connection class to a PAN-OS API endpoint
208+
class DeviceType
209+
def initialize(context, connection_info)
210+
# Initialization eg. validate connection_info
211+
end
212+
213+
def verify(context)
214+
# Test that transport can talk to the remote target
215+
end
216+
217+
def facts(context)
218+
# Access target, return a Facter facts hash
219+
end
220+
221+
def close(context)
222+
# Close connection, free up resources
195223
end
196224
end
197225
end
198226
```
199227

228+
An example of a corresponding schema may look like:
229+
230+
```ruby
231+
# lib/puppet/transport/device_type.rb
232+
Puppet::ResourceAPI.register_transport(
233+
name: 'device_type', # points at class Puppet::Transport::DeviceType
234+
desc: 'Connects to a device_type',
235+
# features: [], # future extension points
236+
connection_info: {
237+
hostname: {
238+
type: 'String',
239+
desc: 'The host to connect to.',
240+
},
241+
username: {
242+
type: 'String',
243+
desc: 'The user.',
244+
},
245+
password: {
246+
type: 'String',
247+
sensitive: true,
248+
desc: 'The password to connect.',
249+
},
250+
enable_password: {
251+
type: 'String',
252+
sensitive: true,
253+
desc: 'The password escalate to enable access.',
254+
},
255+
port: {
256+
type: 'Integer',
257+
desc: 'The port to connect to.',
258+
},
259+
},
260+
)
261+
```
262+
200263
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).
201264

202265
#### Transport/Device specific providers
203266

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`.
267+
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 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`.
205268

206269
## Further Reading
207270

0 commit comments

Comments
 (0)