vm.py 文件源码

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

项目:vcdriver 作者: Lantero 项目源码 文件源码
def winrm(self, script, winrm_kwargs=dict(), quiet=False, **kwargs):
        """
        Executes a remote windows powershell script
        :param script: A string with the powershell script
        :param winrm_kwargs: The pywinrm Protocol class kwargs
        :param quiet: Whether to hide the stdout/stderr output or not

        :return: A tuple with the status code, the stdout and the stderr

        :raise: WinRmError: If the command fails
        """
        if self._vm_object:
            self._wait_for_winrm_service(
                kwargs['vcdriver_vm_winrm_username'],
                kwargs['vcdriver_vm_winrm_password'],
                **winrm_kwargs
            )
            winrm_session = self._open_winrm_session(
                kwargs['vcdriver_vm_winrm_username'],
                kwargs['vcdriver_vm_winrm_password'],
                winrm_kwargs
            )
            if not quiet:
                print('Executing remotely on {} ...'.format(self.ip()))
                styled_print(Style.DIM)(script)
            status, stdout, stderr = self._run_winrm_ps(winrm_session, script)
            if not quiet:
                styled_print(Style.BRIGHT)('CODE: {}'.format(status))
                styled_print(Fore.GREEN)(stdout)
            if status != 0:
                if not quiet:
                    styled_print(Fore.RED)(stderr)
                raise WinRmError(script, status, stdout, stderr)
            else:
                return status, stdout, stderr
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号