Пример #1
0
    def ssh_download(self,
                     remote_path,
                     local_path,
                     use_sudo=False,
                     quiet=False,
                     **kwargs):
        """
        Download a file or directory from the virtual machine
        :param remote_path: The remote location
        :param local_path: The local local
        :param use_sudo: If True, it runs as sudo
        :param quiet: Whether to hide the stdout/stderr output or not

        :return: The list of downloaded files

        :raise: DownloadError: If the task 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 quiet:
                    with hide('everything'):
                        result = get(remote_path,
                                     local_path,
                                     use_sudo=use_sudo)
                else:
                    result = get(remote_path, local_path, use_sudo=use_sudo)
                if result.failed:
                    raise DownloadError(local_path=local_path,
                                        remote_path=remote_path)
                else:
                    return result
Пример #2
0
    def upload(self, remote_path, local_path, use_sudo=False, **kwargs):
        """
        Upload a file or directory to the virtual machine
        :param remote_path: The remote location
        :param local_path: The local local
        :param use_sudo: If True, it runs as sudo

        :return: The list of uploaded files

        :raise: UploadError: If the task 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']
            ):
                result = put(
                    remote_path=remote_path,
                    local_path=local_path,
                    use_sudo=use_sudo
                )
                if result.failed:
                    raise UploadError(
                        local_path=local_path,
                        remote_path=remote_path
                    )
                else:
                    return result
Пример #3
0
    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
Пример #4
0
    def ssh(self, command, use_sudo=False, **kwargs):
        """
        Executes a shell command through ssh
        :param command: The command to be executed
        :param use_sudo: If True, it runs as sudo

        :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:
                    result = sudo(command)
                else:
                    result = run(command)
                if result.failed:
                    raise SshError(command, result.return_code)
                return result