bug fixes and updates for eos connections (#21534)

* refactors supports_sessions to a property
* exposes supports_sessions as a toplevel function
* adds open_shell() to network_cli
* implements open_shell() in eos action plugin
This commit is contained in:
Peter Sprygada 2017-02-16 20:26:48 -05:00 committed by GitHub
parent a01288859d
commit 9d4a3599b8
3 changed files with 48 additions and 17 deletions

View file

@ -31,20 +31,28 @@ from ansible.module_utils.eos import eos_argument_spec
from ansible.module_utils.basic import AnsibleFallbackNotFound
from ansible.module_utils._text import to_bytes
try:
from __main__ import display
except ImportError:
from ansible.utils.display import Display
display = Display()
class ActionModule(_ActionModule):
def run(self, tmp=None, task_vars=None):
if self._play_context.connection != 'local':
return dict(
fail=True,
failed=True,
msg='invalid connection specified, expected connection=local, '
'got %s' % self._play_context.connection
)
provider = self.load_provider()
transport = provider['transport']
transport = provider['transport'] or 'cli'
if not transport or 'cli' in transport:
display.vvv('transport is %s' % transport, self._play_context.remote_addr)
if transport == 'cli':
pc = copy.deepcopy(self._play_context)
pc.connection = 'network_cli'
pc.network_os = 'eos'
@ -53,12 +61,14 @@ class ActionModule(_ActionModule):
pc.become = provider['authorize'] or False
pc.become_pass = provider['auth_pass']
connection = self._shared_loader_obj.connection_loader.get('persistent', pc, sys.stdin)
socket_path = self._get_socket_path(pc)
if not os.path.exists(socket_path):
# start the connection if it isn't started
connection = self._shared_loader_obj.connection_loader.get('persistent', pc, sys.stdin)
connection.exec_command('EXEC: show version')
rc, out, err = connection.exec_command('open_shell()')
if not rc == 0:
return {'failed': True, 'msg': 'unable to open shell', 'rc': rc}
task_vars['ansible_socket'] = socket_path
@ -80,7 +90,13 @@ class ActionModule(_ActionModule):
self._play_context.become = False
self._play_context.become_method = None
return super(ActionModule, self).run(tmp, task_vars)
result = super(ActionModule, self).run(tmp, task_vars)
if transport == 'cli':
display.vvv('closing cli shell connection', self._play_context.remote_addr)
rc, out, err = connection.exec_command('close_shell()')
return result
def _get_socket_path(self, play_context):
ssh = connection_loader.get('ssh', class_only=True)