box.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:AerisCloud 作者: AerisCloud 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号