- if node.get('host_port') is not None:
- ssh_node = dict()
- ssh_node['host'] = '127.0.0.1'
- ssh_node['port'] = node['port']
- ssh_node['username'] = node['username']
- ssh_node['password'] = node['password']
- import pexpect
- options = '-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'
- tnl = '-L {port}:127.0.0.1:{port}'.format(port=node['port'])
- ssh_cmd = 'ssh {tnl} {op} {user}@{host} -p {host_port}'.\
- format(tnl=tnl, op=options, user=node['host_username'],
- host=node['host'], host_port=node['host_port'])
- logger.trace('Initializing local port forwarding:\n{ssh_cmd}'.
- format(ssh_cmd=ssh_cmd))
- child = pexpect.spawn(ssh_cmd)
- child.expect('.* password: ')
- logger.trace(child.after)
- child.sendline(node['host_password'])
- child.expect('Welcome .*')
- logger.trace(child.after)
- logger.trace('Local port forwarding finished.')
- else:
- ssh_node = node
-