Created
June 5, 2018 16:47
-
-
Save ganeshrn/b261f1a33c477eb0ef620d2cddd167b9 to your computer and use it in GitHub Desktop.
network_cli code flow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
There are multiple moving parts in this code flow. | |
To start with network_cli connection plugin is applicable for network platforms that support persistent | |
connection with the remote host across task. | |
The method called on connection object (connection.edit_config) is serialised in json string as per jsonrpc 2.0 spec [0] | |
and is send over to socket [1]. The receiving end of the socket is a daemon process called "ansible-connection" | |
which is spawned from task_executor [2] at the time of connection creation to the remote host. | |
"ansible-connection" receives the json string and calls handle_request method [3] on the object of JsonRpcServer class | |
In the initialization steps, "ansible-connection" loads the connection plugin ("network-cli" plugin in this case) and | |
register it with object JsonRpcServer class [4]. handle_request() in turn decodes the json string | |
to fetch the method name, arguments and invokes it on the object of Connection class defined in network_cli [5] | |
network_cli _connect() method which is called at the time of connection initialization [6] & [7] handles the | |
connection with the remote host and also loads the cliconf and terminal plugins within the Connection object | |
based on the value of "network_os" [8] (nxos in this case) | |
So the call connection.edit_config ends up in Connection class defined in network_cli as and "edit_config" method | |
is not directly defined in this class it searches for the method with the same name in nxos cliconf and terminal plugin. | |
Since edit_config is defined in nxos cliconf plugin [9] it gets invoked. | |
nxos_vlan --> load_config --> connection.edit_config --> ansible-connection -> network_cli --> nxos cliconf | |
|------ module side code ---------------------------| |--------------- controller code -----------------| | |
[0] http://www.jsonrpc.org/specification | |
[1] https://github.com/ansible/ansible/blob/devel/lib/ansible/module_utils/connection.py#L158 | |
[2] https://github.com/ansible/ansible/blob/devel/lib/ansible/executor/task_executor.py#L917 | |
[3] https://github.com/ansible/ansible/blob/devel/bin/ansible-connection#L123 | |
[4] https://github.com/ansible/ansible/blob/devel/bin/ansible-connection#L89 | |
[5] https://github.com/ansible/ansible/blob/devel/lib/ansible/utils/jsonrpc.py#L25 | |
[6] https://github.com/ansible/ansible/blob/devel/bin/ansible-connection#L87 | |
[7] https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/connection/network_cli.py#L287 | |
[8] https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/connection/network_cli.py#L318 | |
[9] https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/connection/network_cli.py#L225 | |
You can refer the httpapi proposal here https://github.com/ansible/proposals/issues/103 which deals with the | |
similar requirement. | |
FYI httpapi connection support is present in devel branch and will be available with Ansible 2.6 version onwards |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment