mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
roll up of fixes in junos action plugin (#21624)
* calls open_shell() or open_session() depending on connection type * closes shell after module completion * adds open_session() to netconf
This commit is contained in:
parent
c68d81fe4f
commit
2f10bdf0c7
2 changed files with 20 additions and 11 deletions
|
@ -65,25 +65,31 @@ class ActionModule(_ActionModule):
|
|||
pc.remote_user = provider['username'] or self._play_context.connection_user
|
||||
pc.password = provider['password'] or self._play_context.password
|
||||
pc.private_key_file = provider['ssh_keyfile'] or self._play_context.private_key_file
|
||||
pc.timeout = provider['timeout'] or self._play_context.timeout
|
||||
|
||||
display.vvv('using connection plugin %s' % pc.connection)
|
||||
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)
|
||||
|
||||
if pc.connection == 'network_cli':
|
||||
rc, out, err = connection.exec_command('show version')
|
||||
display.vvv('%s %s %s' % (rc, out, err))
|
||||
|
||||
if pc.connection == 'netconf':
|
||||
# <get-software-information />
|
||||
req = new_ele('get-software-information')
|
||||
connection.exec_command(to_xml(req))
|
||||
rc, out, err = connection.exec_command('open_session()')
|
||||
else:
|
||||
rc, out, err = connection.exec_command('open_shell()')
|
||||
|
||||
if rc != 0:
|
||||
return {'failed': True, 'msg': 'unable to connect to control socket'}
|
||||
|
||||
task_vars['ansible_socket'] = socket_path
|
||||
|
||||
return super(ActionModule, self).run(tmp, task_vars)
|
||||
result = super(ActionModule, self).run(tmp, task_vars)
|
||||
|
||||
if pc.connection == 'network_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)
|
||||
|
|
|
@ -101,6 +101,9 @@ class Connection(ConnectionBase):
|
|||
def exec_command(self, request):
|
||||
"""Sends the request to the node and returns the reply
|
||||
"""
|
||||
if request == 'open_session()':
|
||||
return (0, 'ok', '')
|
||||
|
||||
req = to_ele(request)
|
||||
if req is None:
|
||||
return (1, '', 'unable to parse request')
|
||||
|
|
Loading…
Reference in a new issue