Description
Proposal: HTTP(S)-transport connection plugin
Author: Nathaniel Case <@Qalthos>
Date: 2018-04-10
- Status: New
- Proposal type: core
- Targeted Release: 2.6
- Estimated time to implement: 6 weeks
Motivation
Implement a first order connection plugin like connection: network_cli
& connection: netconf
for HTTP(S) transports.
Allows full deprecation of connection: local
& provider:
for network devices with eAPI and NX-API implementations.
This proposal covers the connection plugin and creation of an eAPI implementation plugin, replacing #102
Problems
- As a user, I want to manage Arista devices that can only be accessed via eAPI
- As a user, I want to connect to an Arista device over eAPI without using
connection: local
andprovider
so I can use basic Ansible connection options instead, including specifying http(s) port and encrypted or non-encrypted transport type (HTTP/HTTPS) - As a user, I want existing playbooks using
connection: local
to continue to function as before without user intervention - As a user, I want to securely connect to eos devices via a proxy
- As a user, I want to securely connect using using username & password or a certificate
- As a user, I want to have enough information to debug when the connection/authentication fails
- As a user, I want to be able to control my operating mode (such as privilege mode)
- As a user, I want to be able to reset the connection using the Ansible meta handler reset_connection
Solution proposal
This connection plugin works in concert with a new API plugin system that determines the specifics of the API in question. This new plugin has the following method:
send_request(self, data, **message_kwargs)
data
should correspond to the actual message being sent to the devicemessage_kwargs
should specify how the message is sent. This will vary according to the particular API in use, but might include message type, destination, or optional headersdata
and**message_kwargs
are interpreted to create a payload to send over HTTP- This payload is sent to the connection's
send()
method, defined below. - The message response is unpacked and either sent back to the module, or an appropriate exception can be raised to indicate a failure
Additionally, there is an optional login(self)
method which can be used to acquire auth tokens. This method should call connection.send()
with the apropriate parameters.
The connection plugin itself works like the existing network_cli
and netconf
plugins, and is tasked with maintaining the session information for the module.
- When the connection is created
- check that
network_os
is set - load appropriate
cliconf
plugin, if one exists - load appropriate api implementation plugin
- check that
- When
_connect(self)
is called- ensure socket_path is valid
- call api plugin's
login()
method - set
_connected
to indicate connection is valid
- When
close(self)
is called- clear any auth token saved to force new login
- unset
_connected
reset(self)
callsclose()
ifsocket_path
is setput_file
,fetch_file
, andexec_command
all redirect to an internallocal
connection, to allow non-networking modules to function on the local host, as is done in existing network connection plugins.__getattr__
is defined so method calls made to the connection plugin not defined in the connection plugin will search first the registered API plugin, then the registered cliconf plugin, if one exists, for like-named methods to execute. In this way, the methods of those plugins are available to consumers of the connection plugin.- When
send(self, path, data, **request_kwargs)
is called- saved session information (if any) are applied to
request_kwargs
- the request's full URL is built from
{protocol}://{host}:{port}/{path}
.protocol
is'https'
if connection optionuse_ssl
is true (default), otherwise'http'
open_url(url, data, **request_args)
is called- session information (if any) is saved from the response
- the response is returned
- saved session information (if any) are applied to
Finally, some changes to the eos and nxos cliconf plugins will be necessary to use send_request
instead of send
when communicating over this new connection plugin. This is to allow using the cliconf plugin without overly burdening the API plugins with an interface designed for command-driven connections
Testing
- Add eAPI connection case to existing eos integration tests
- Move all
connection: local
tests to single test covering both transports - Each user story should be defended
- High code coverage for new code
Documentation
- EOS docs fragments need to be updated to remove mentions of "This option is only required if you are using eAPI" with reference to
connection: local
- EOS platform specific page needs to be altered to replace any reference to
connection: local
with the new connection type - The network section of the
become
guide should be updated to include the new connection type