vm.py 文件源码

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

项目:vcdriver 作者: Lantero 项目源码 文件源码
def ssh(self, command, use_sudo=False, quiet=False, **kwargs):
        """
        Executes a shell command through ssh
        :param command: The command to be executed
        :param use_sudo: If True, it runs as sudo
        :param quiet: Whether to hide the stdout/stderr output or not

        :return: The fabric equivalent of run and sudo

        :raise: SshError: If the command fails
        """
        if self._vm_object:
            self._wait_for_ssh_service(
                kwargs['vcdriver_vm_ssh_username'],
                kwargs['vcdriver_vm_ssh_password']
            )
            with fabric_context(
                    self.ip(),
                    kwargs['vcdriver_vm_ssh_username'],
                    kwargs['vcdriver_vm_ssh_password']
            ):
                if use_sudo:
                    runner = sudo
                else:
                    runner = run
                if quiet:
                    with hide('everything'):
                        result = runner(command)
                else:
                    result = runner(command)
                if result.failed:
                    raise SshError(command, result.return_code, result.stdout)
                return result
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号