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
Copy file name to clipboardExpand all lines: README.md
+71-8Lines changed: 71 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -174,34 +174,97 @@ The generated unit tests in `spec/unit/puppet/provider/foo_spec.rb` get automati
174
174
175
175
## Remote Resources
176
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.
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.
178
178
179
179
### `puppet device` support
180
180
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`:
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
+
modulePuppet::Transport
207
+
# The main connection class to a PAN-OS API endpoint
208
+
classDeviceType
209
+
definitialize(context, connection_info)
210
+
# Initialization eg. validate connection_info
211
+
end
212
+
213
+
defverify(context)
214
+
# Test that transport can talk to the remote target
215
+
end
216
+
217
+
deffacts(context)
218
+
# Access target, return a Facter facts hash
219
+
end
220
+
221
+
defclose(context)
222
+
# Close connection, free up resources
195
223
end
196
224
end
197
225
end
198
226
```
199
227
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
+
200
263
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).
201
264
202
265
#### Transport/Device specific providers
203
266
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`.
0 commit comments