adds more logging output to network_cli and ansible-connection (#21716)

This commit is contained in:
Peter Sprygada 2017-02-21 09:21:41 -05:00 committed by GitHub
parent 77596951b8
commit 6e9244a9e1
2 changed files with 23 additions and 8 deletions

View file

@ -56,6 +56,8 @@ class Connection(_Connection):
def update_play_context(self, play_context):
"""Updates the play context information for the connection"""
display.vvvv('updating play_context for connection', self._play_context.remote_addr)
if self._play_context.become is False and play_context.become is True:
auth_pass = play_context.become_pass
self._terminal.on_authorize(passwd=auth_pass)
@ -69,8 +71,7 @@ class Connection(_Connection):
"""Connections to the device and sets the terminal type"""
super(Connection, self)._connect()
display.debug('starting network_cli._connect()')
display.vvvv('starting network_cli._connect()')
display.vvvv('ssh connection done, setting terminal', self._play_context.remote_addr)
network_os = self._play_context.network_os
if not network_os:
@ -84,9 +85,11 @@ class Connection(_Connection):
raise AnsibleConnectionFailure('network os %s is not supported' % network_os)
self._connected = True
display.vvvv('ssh connection has completed successfully', self._play_context.remote_addr)
@ensure_connect
def open_shell(self):
display.vvvv('attempting to open shell to device', self._play_context.remote_addr)
self._shell = self.ssh.invoke_shell()
self._shell.settimeout(self._play_context.timeout)
@ -99,16 +102,18 @@ class Connection(_Connection):
auth_pass = self._play_context.become_pass
self._terminal.on_authorize(passwd=auth_pass)
display.vvvv('shell successfully opened', self._play_context.remote_addr)
return (0, 'ok', '')
def close(self):
display.vvv('closing connection', host=self._play_context.remote_addr)
display.vvvv('closing connection', self._play_context.remote_addr)
self.close_shell()
super(Connection, self).close()
self._connected = False
def close_shell(self):
"""Closes the vty shell if the device supports multiplexing"""
display.vvvv('closing shell on device', self._play_context.remote_addr)
if self._shell:
self._terminal.on_close_shell()
@ -204,7 +209,7 @@ class Connection(_Connection):
def alarm_handler(self, signum, frame):
"""Alarm handler raised in case of command timeout """
display.debug('alarm_handler fired!')
display.vvvv('closing shell due to sigalarm', self._play_context.remote_addr)
self.close_shell()
def exec_command(self, cmd):
@ -217,7 +222,7 @@ class Connection(_Connection):
Keywords supported for cmd:
* command - the command string to execute
* prompt - the expected prompt generated by executing command
* response - the string to respond to the prompt with
* answer - the string to respond to the prompt with
* sendonly - bool to disable waiting for response
:arg cmd: the string that represents the command to be executed
@ -225,7 +230,6 @@ class Connection(_Connection):
:returns: a tuple of (return code, stdout, stderr). The return
code is an integer and stdout and stderr are strings
"""
display.vvv('cmd: %s' % cmd)
try:
obj = json.loads(cmd)
except (ValueError, TypeError):