Skip to content

Commit 3ae711f

Browse files
authored
Merge pull request #139 from DavidS/FM-7878-update-transports
(FM-7878) Update transport docs
2 parents 0223fcf + f09d3ae commit 3ae711f

File tree

1 file changed

+58
-40
lines changed

1 file changed

+58
-40
lines changed

language/resource-api/README.md

Lines changed: 58 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -363,11 +363,11 @@ class Puppet::Provider::Nx9k_vlan::Nexus
363363
end
364364
```
365365

366-
Declaring this feature restricts the resource from being run "locally". It executes all external interactions through the `context.transport` instance. The way the instance is set up is runtime specific. In Puppet, it is configured through the [`device.conf`](https://puppet.com/docs/puppet/5.3/config_file_device.html) file, and only available when running under [`puppet device`](https://puppet.com/docs/puppet/5.3/man/device.html).
366+
Declaring this feature restricts the resource from being run "locally". It executes all external interactions through the `context.transport` instance. The way the instance is set up is runtime specific. In Puppet, it is configured through the [`device.conf`](https://puppet.com/docs/puppet/5.3/config_file_device.html) file, and only available when running under [`puppet device`](https://puppet.com/docs/puppet/5.3/man/device.html). We recommend using the [device_manager module](https://forge.puppet.com/puppetlabs/device_manager) to deploy device configuration and credentials. In Bolt, credentials are passed in through the [`inventory.yaml`](https://puppet.com/docs/bolt/latest/inventory_file.html#remote-targets).
367367

368-
To support Puppet versions prior to 6, see the [Legacy Support](#legacy-support) section below.
368+
To use remote resources, you need a transport. See below for how they are defined and implemented.
369369

370-
### Transport
370+
### Transports
371371

372372
```ruby
373373
# lib/puppet/transport/schema/nexus.rb
@@ -412,12 +412,26 @@ class Puppet::Transport::Nexus
412412
def facts(context); {}; end
413413
def close(context); end
414414
end
415+
416+
# lib/puppet/util/network_device/nexus/device.rb
417+
require 'puppet/resource_api/transport/wrapper'
418+
require 'puppet/transport/schema/nexus'
419+
420+
module Puppet::Util::NetworkDevice::Nexus
421+
class Device < Puppet::ResourceApi::Transport::Wrapper
422+
def initialize(url_or_config, _options = {})
423+
super('nexus', url_or_config)
424+
end
425+
end
426+
end
415427
```
416428
417429
A transport connects providers to the remote target. It consists of the schema and the implementation. The schema is defined in the same manner as a `Type`, except instead of `attributes` you define `connection_info` which describes the shape of the data which is passed to the implementation for a connection to be made.
418430
419431
Password attributes should also set `sensitive: true` to ensure that the data is handled securely. Attributes marked with this flag allow any UI based off this schema to make appropriate presentation choices. The value will be passed to the transport wrapped in a `Puppet::Pops::Types::PSensitiveType::Sensitive`. This will keep the value from being logged or saved inadvertently while it is being transmitted between components. To access the value within the Transport use the `unwrap` method. e.g. `connection_info[:password].unwrap`.
420432
433+
#### Schema
434+
421435
A transport schema accepts the following keywords:
422436
423437
* `uri`: use when you need to specify a specific URL to connect to. All of the following keys will be computed from the `uri` when possible. In the future more url parts may be computed from the URI.
@@ -436,6 +450,8 @@ Do not use the following keywords when writing a schema:
436450
* `remote-*`: any key starting with `remote-` is reserved for future use.
437451
* `implementations`: reserved by Bolt.
438452
453+
#### Implementation
454+
439455
The transport implementation must implement the following methods:
440456
441457
* `initialize(context, connection_info)`
@@ -465,42 +481,9 @@ To allow implementors a wide latitude in implementing connection and retry handl
465481
466482
1. Any other methods on the transport are to be used by providers and tasks talking to this kind of target. Those operations are free to use any error signalling mechanism that is convenient. Providers and tasks will have to provide appropriate error signalling to the runtime.
467483
468-
### Direct Access to Transports
469-
470-
It is possible to use a RSAPI Transport directly using the `connect` method:
471-
472-
`Puppet::ResourceApi::Transport.connect(name, config)`
473-
474-
1. `register` the transport schema for the remote resource by:
475-
* Directly calling into `Puppet::ResourceApi.register_transport`
476-
* Loading an existing schema using `require 'puppet/transport/schema/<transportname>`
477-
* Setting up Puppet's autoloader for `'puppet/transport/schema'`
478-
2. `connect` to the transport by name, passing the connection info
479-
3. When the transport has been initialized, `connect` will return the `Transport` object
480-
481-
See above for possible exceptions coming from initializing a transport.
482-
483-
To get a list of all registered transports, call the `list` method:
484-
485-
`Puppet::ResourceApi::Transport.list`
486-
487-
It will return a hash of all registered transport schemas keyed by their name. Each entry in the list is the transport schema definition as passed to `register_transport`:
484+
#### Bridging into Puppet
488485
489-
490-
```ruby
491-
{
492-
'nexus' => {
493-
name: 'nexus',
494-
desc: 'Connects to a Cisco Nexus device',
495-
# ...
496-
# the rest of the transport schema definition here
497-
},
498-
}
499-
```
500-
501-
### Legacy Support
502-
503-
Before Puppet 6.X (TBD), remote resources were only supported through the `Puppet::Util::NetworkDevice` namespace. To make a module useful on these older versions, a shim `Device` class needs to be provided to connect the dots:
486+
Before the Resource API, remote resources were only supported through the `Puppet::Util::NetworkDevice` namespace. To connect your Transport in a way that Puppet understands, you need to provide a shim `Device` class.
504487
505488
```ruby
506489
# lib/puppet/type/nx9k_vlan.rb
@@ -524,9 +507,11 @@ module Puppet::Util::NetworkDevice::Nexus
524507
end
525508
```
526509
527-
Inheriting from `Puppet::ResourceApi::Transport::Wrapper` will ensure that the necessary `Device` methods will be implemented using your transport.
510+
Inheriting from `Puppet::ResourceApi::Transport::Wrapper` ensures that the necessary `Device` methods are implemented using your transport. Specify the transport name in the `super` call to make the connection.
511+
512+
> Note that because of the way the Resource API is bundled with Puppet agent packages, agent versions 6.0 through 6.3 are incompatible with this way of executing remote content. These versions will not be supported after [support for PE 2019.0 ends in August 2019](https://puppet.com/misc/puppet-enterprise-lifecycle).
528513
529-
### Porting existing code
514+
#### Porting existing code
530515
531516
To port your existing device code as a transport, move the class to `Puppet::Transport`, remove mention of the `Puppet::Util::NetworkDevice::Simple::Device` (if it was used) and change the initialisation to accept and process a `connection_info` hash instead of the previous structures. When accessing the `connection_info` in your new transport, change all string keys to symbols (e.g. `'foo'` to `:foo`). Add `context` as first argument to your `initialize` and `facts` method.
532517
@@ -539,6 +524,39 @@ The following replacements have provided a good starting point for these changes
539524
540525
Of course this list can't be exhaustive and will depend on the specifics of your codebase.
541526
527+
#### Direct Access to Transports
528+
529+
It is possible to use a RSAPI Transport directly using the `connect` method:
530+
531+
`Puppet::ResourceApi::Transport.connect(name, config)`
532+
533+
1. `register` the transport schema for the remote resource by:
534+
* Directly calling into `Puppet::ResourceApi.register_transport`
535+
* Loading an existing schema using `require 'puppet/transport/schema/<transportname>`
536+
* Setting up Puppet's autoloader for `'puppet/transport/schema'`
537+
2. `connect` to the transport by name, passing the connection info
538+
3. When the transport has been initialized, `connect` will return the `Transport` object
539+
540+
See above for possible exceptions coming from initializing a transport.
541+
542+
To get a list of all registered transports, call the `list` method:
543+
544+
`Puppet::ResourceApi::Transport.list`
545+
546+
It will return a hash of all registered transport schemas keyed by their name. Each entry in the list is the transport schema definition as passed to `register_transport`:
547+
548+
549+
```ruby
550+
{
551+
'nexus' => {
552+
name: 'nexus',
553+
desc: 'Connects to a Cisco Nexus device',
554+
# ...
555+
# the rest of the transport schema definition here
556+
},
557+
}
558+
```
559+
542560

543561
## Runtime environment
544562

0 commit comments

Comments
 (0)