ansible / proposals

Repository for sharing and tracking progress on enhancement proposals for Ansible.
Creative Commons Zero v1.0 Universal
93 stars 19 forks source link

New connection plugin for HTTP(S)-based APIs #103

Closed Qalthos closed 6 years ago

Qalthos commented 6 years ago

Proposal: HTTP(S)-transport connection plugin

Author: Nathaniel Case <@Qalthos>

Date: 2018-04-10

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

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:

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.

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

Documentation

caphrim007 commented 6 years ago

is this proposal only in the context of Arista?

sivel commented 6 years ago

Just wanted to point to a PR that I have been working on that will enable creating a Request object, that can handle cookies/headers/etc from a global perspective across multiple requests.

I believe the Request PR can improve functionality in such a plugin as mentioned here.

https://github.com/ansible/ansible/pull/37622

privateip commented 6 years ago

@Qalthos i have some questions / doubts that his will be generic enough to be handled in the connection plugin if we are targetting any request of http.

build_request(self, commands, output_format, **kwargs) returns a tuple of (data, headers) suitable for being used with open_url()

This method would only be uses in specific instances of network devices sending CLI commands and would be better handled in a plugin that provides messaging structure. That would allow the connection plugin here to be generic enough to handle all http transport use cases as discussed https://github.com/ansible/proposals/issues/102#issuecomment-377630313

Qalthos commented 6 years ago

@caphrim007 Not exactly. This proposal covers eAPI as the first consumer of the plugin (and to reuse as much as possible from #102), but if you have needs not covered by the Problems heading, please note them here so that can be tracked.

@sivel That PR looks like it would make this a lot easier, yes.

caphrim007 commented 6 years ago

@Qalthos most of the items in the Problems section are also applicable to F5. Additionally, I would include

The reason for the above is that some of the work I need to do involves the device actually rebooting, and I cant have the module fail with a connection terminated when that happens.

bcoca commented 6 years ago

Proposals that try to solve similar or related issues:

auth plugins #24 stackable connection plugins #25 special namespaced credential vars #81 cloud shared credentials #90

Qalthos commented 6 years ago

@caphrim007 I can add that detail. Connections already have a reset() method, which I have neglected t add, which in this case would just call close()

caphrim007 commented 6 years ago

@Qalthos does the reset work from inside the module itself? Would it handle an authentication case where,

Qalthos commented 6 years ago

Based on conversations with @privateip, I've reorganized the flow of this proposal to try to reduce the need to copy network_cli so closely.

@caphrim007 Yes, clearing that header and indicating that it should be re-acquired is one of the two functions of close, along with closing the persistent connection socket. This will force connect() to be called again on next use, which should restore the information.