def ssh_shell(self, cmd=None, cd=True, popen=False, **kwargs):
"""
Create an interactive ssh shell on the remote VM
:return: subprocess32.Popen
"""
call_args = [
'ssh', self.ip(), '-t', '-A',
'-l', 'vagrant',
'-i', self.ssh_key()]
if cmd:
if isinstance(cmd, tuple) or isinstance(cmd, list):
cmd = ' '.join(map(quote, cmd))
if cd:
cmd = '[ ! -d "{0}" ] && exit {1}; cd "{0}"; {2}'.format(
self.project.name(),
self.NO_PROJECT_DIR,
cmd
)
call_args.append(cmd)
self._logger.debug('calling %s', ' '.join(call_args))
if popen:
return Popen(call_args, start_new_session=True, **kwargs)
return call(call_args, **kwargs)
评论列表
文章目录