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: language/resource-api/README.md
+58-40Lines changed: 58 additions & 40 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -363,11 +363,11 @@ class Puppet::Provider::Nx9k_vlan::Nexus
363
363
end
364
364
```
365
365
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).
367
367
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.
369
369
370
-
### Transport
370
+
### Transports
371
371
372
372
```ruby
373
373
# lib/puppet/transport/schema/nexus.rb
@@ -412,12 +412,26 @@ class Puppet::Transport::Nexus
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.
418
430
419
431
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`.
420
432
433
+
#### Schema
434
+
421
435
A transport schema accepts the following keywords:
422
436
423
437
* `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:
436
450
* `remote-*`: any key starting with `remote-` is reserved for future use.
437
451
* `implementations`: reserved by Bolt.
438
452
453
+
#### Implementation
454
+
439
455
The transport implementation must implement the following methods:
440
456
441
457
* `initialize(context, connection_info)`
@@ -465,42 +481,9 @@ To allow implementors a wide latitude in implementing connection and retry handl
465
481
466
482
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.
467
483
468
-
### Direct Access to Transports
469
-
470
-
It is possible to use a RSAPI Transport directly using the `connect` method:
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
488
485
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
-
BeforePuppet6.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.
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).
528
513
529
-
### Porting existing code
514
+
#### Porting existing code
530
515
531
516
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.
532
517
@@ -539,6 +524,39 @@ The following replacements have provided a good starting point for these changes
539
524
540
525
Of course this list can't be exhaustive and will depend on the specifics of your codebase.
541
526
527
+
#### Direct Access to Transports
528
+
529
+
It is possible to use a RSAPI Transport directly using the `connect` method:
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
0 commit comments