Skip to content

Commit d1f4d8d

Browse files
committed
(FM-7819) rearrange for better reading flow
1 parent c53b201 commit d1f4d8d

File tree

1 file changed

+43
-45
lines changed

1 file changed

+43
-45
lines changed

README.md

Lines changed: 43 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -176,37 +176,6 @@ The generated unit tests in `spec/unit/puppet/provider/foo_spec.rb` get automati
176176

177177
Support for remote resources is enabled through a `transport` class. A transport class contains the code for managing connections and processing information to and from the remote resource. For information on how to create a transport class, see the [Resource API specification](https://github.com/puppetlabs/puppet-specifications/tree/master/language/resource-api#transport).
178178

179-
### `puppet device` support
180-
181-
To connect to a remote resource through `puppet device`, you must call a `transport` class through a device shim to maintain compatibility with Puppet Resource.
182-
183-
A `device` class is created that Puppet Resource will call, however this will inherit from the `transport` class which will contain the following methods (as detailed in the [Resource API specification](https://github.com/puppetlabs/puppet-specifications/tree/master/language/resource-api#transport)):
184-
* `initialize`
185-
* `verify`
186-
* `facts`
187-
* `connect`
188-
189-
For example, the `device` class will be a pass through to `transport`:
190-
191-
```ruby
192-
# lib/puppet/util/network_device/device_type/device.rb
193-
194-
require 'puppet'
195-
require 'puppet/resource_api/transport/wrapper'
196-
# force registering the transport schema
197-
require 'puppet/transport/schema/device_type'
198-
199-
module Puppet::Util::NetworkDevice::DeviceType
200-
class Device < Puppet::ResourceApi::Transport::Wrapper
201-
def initialize(url_or_config, _options = {})
202-
super('device_type', url_or_config)
203-
end
204-
end
205-
end
206-
```
207-
208-
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).
209-
210179
An example of a transport class:
211180

212181
```ruby
@@ -215,17 +184,17 @@ module Puppet::Transport
215184
# The main connection class to a PAN-OS API endpoint
216185
class DeviceType
217186
def initialize(context, connection_info)
218-
# Initialization eg. validate connection_info
187+
# Initialization eg. validate connection_info
219188
end
220-
189+
221190
def verify(context)
222191
# Test that transport can talk to the remote target
223192
end
224-
193+
225194
def facts(context)
226195
# Access target, return a Facter facts hash
227196
end
228-
197+
229198
def close(context)
230199
# Close connection, free up resources
231200
end
@@ -268,31 +237,31 @@ Puppet::ResourceAPI.register_transport(
268237
)
269238
```
270239

271-
##### Transport Schema keywords
240+
### Transport Schema keywords
272241

273242
Please note that within the transport schema, the following keywords are reserved words:
274243

275-
###### Usable within the schema
276-
244+
#### Usable within the schema
245+
277246
The following keywords are encouraged within the Transport schema:
278-
247+
279248
* `uri` - Use when you need to specify a specific URL to connect to. All of the following keys will be computed from the `uri` if possible. In the future more url parts may be computed from the URI as well.
280-
* `host` - Use to specify and IP or address to connect to.
249+
* `host` - Use to specify and IP or address to connect to.
281250
* `protocol` - Use to specify which protocol the transport should use for example `http`, `https`, `ssh` or `tcp`
282251
* `user` - The user the transport should connect as.
283252
* `port` - The port the transport should connect to.
284-
285-
###### Non-Usable within the schema
286-
253+
254+
#### Non-Usable within the schema
255+
287256
The following keywords are keywords that must not be used by the transport schema:
288-
257+
289258
* `name` - transports should use `uri` instead of name.
290259
* `path` - reserved as a uri part
291260
* `query` - reserved as a uri part
292261
* `run-on` - This is used by bolt to determine which target to proxy to. Transports should not rely on this key.
293262
* `remote-transport` - This is used to determine which transport to load. It should always be the transport class name "declassified".
294263
* `remote-*` Any key starting with `remote-` is reserved for future use.
295-
264+
296265
Note: Currently bolt inventory requires that a name be set for every target and always uses that name as the URI. This means there is no way to specify `host` separately from the host section of the `name` when parsed as a URI.
297266

298267
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).
@@ -301,6 +270,35 @@ After the device class, transport class and transport schema have been implement
301270

302271
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`.
303272

273+
### `puppet device` support
274+
275+
To connect to a remote resource through `puppet device`, you must call a `transport` class through a device shim to maintain compatibility with Puppet Resource.
276+
277+
A `device` class is created that Puppet Resource will call, however this will inherit from the `transport` class which will contain the following methods (as detailed in the [Resource API specification](https://github.com/puppetlabs/puppet-specifications/tree/master/language/resource-api#transport)):
278+
* `initialize`
279+
* `verify`
280+
* `facts`
281+
* `connect`
282+
283+
For example, the `device` class will be a pass through to `transport`:
284+
285+
```ruby
286+
# lib/puppet/util/network_device/device_type/device.rb
287+
288+
require 'puppet'
289+
require 'puppet/resource_api/transport/wrapper'
290+
# force registering the transport schema
291+
require 'puppet/transport/schema/device_type'
292+
293+
module Puppet::Util::NetworkDevice::DeviceType
294+
class Device < Puppet::ResourceApi::Transport::Wrapper
295+
def initialize(url_or_config, _options = {})
296+
super('device_type', url_or_config)
297+
end
298+
end
299+
end
300+
```
301+
304302
## Further reading
305303

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

0 commit comments

Comments
 (0)