Exemplo n.º 1
0
 def upload_file_to_guest(self, local_file_path, guest_file_path):
     job_handle = vixlib.VixVM_CopyFileFromHostToGuest(
         self._vm_handle,
         local_file_path,
         guest_file_path,
         0,  # options
         vixlib.VIX_INVALID_HANDLE,  # prop list
         None,  # callback
         None)  # client data
     err = vixlib.VixJob_Wait(job_handle, vixlib.VIX_PROPERTY_NONE)
     vixlib.Vix_ReleaseHandle(job_handle)
     _check_job_err_code(err)
Exemplo n.º 2
0
    def power_on(self, show_gui=True):
        if show_gui:
            options = vixlib.VIX_VMPOWEROP_LAUNCH_GUI
        else:
            options = vixlib.VIX_VMPOWEROP_NORMAL

        job_handle = vixlib.VixVM_PowerOn(self._vm_handle, options,
                                          vixlib.VIX_INVALID_HANDLE, None,
                                          None)
        err = vixlib.VixJob_Wait(job_handle, vixlib.VIX_PROPERTY_NONE)
        vixlib.Vix_ReleaseHandle(job_handle)
        _check_job_err_code(err)
Exemplo n.º 3
0
    def delete(self, delete_disk_files=True):
        if delete_disk_files:
            delete_options = vixlib.VIX_VMDELETE_DISK_FILES
        else:
            delete_options = 0

        job_handle = vixlib.VixVM_Delete(self._vm_handle, delete_options, None,
                                         None)
        err = vixlib.VixJob_Wait(job_handle, vixlib.VIX_PROPERTY_NONE)
        vixlib.Vix_ReleaseHandle(job_handle)
        _check_job_err_code(err)

        self.close()
Exemplo n.º 4
0
    def write_guest_variable_str(self,
                                 variable_name,
                                 variable_value,
                                 variable_type=vixlib.VIX_VM_GUEST_VARIABLE,
                                 timeout=30):
        if variable_type in (vixlib.VIX_VM_GUEST_VARIABLE,
                             vixlib.VIX_GUEST_ENVIRONMENT_VARIABLE):
            self.wait_for_tools_in_guest(timeout)

        job_handle = vixlib.VixVM_WriteVariable(
            self._vm_handle, variable_type, variable_name,
            ctypes.c_char_p(variable_value), 0, None, None)
        err = vixlib.VixJob_Wait(job_handle, vixlib.VIX_PROPERTY_NONE)
        _check_job_err_code(err)
Exemplo n.º 5
0
    def is_folder_exists_in_guest(self, guest_folder_path):
        is_exists = ctypes.c_bool()

        job_handle = vixlib.VixVM_DirectoryExistsInGuest(
            self._vm_handle,
            guest_folder_path,
            None,  # callback
            None)  # client data
        err = vixlib.VixJob_Wait(
            job_handle, vixlib.VIX_PROPERTY_JOB_RESULT_GUEST_OBJECT_EXISTS,
            ctypes.byref(is_exists), vixlib.VIX_PROPERTY_NONE)
        vixlib.Vix_ReleaseHandle(job_handle)
        _check_job_err_code(err)

        return is_exists.value
Exemplo n.º 6
0
    def list_guest_processes(self):
        job_handle = vixlib.VixVM_ListProcessesInGuest(self._vm_handle, 0,
                                                       None, None)
        err = vixlib.VixJob_Wait(job_handle, vixlib.VIX_PROPERTY_NONE)

        try:
            _check_job_err_code(err)

            process_count = vixlib.VixJob_GetNumProperties(
                job_handle, vixlib.VIX_PROPERTY_JOB_RESULT_ITEM_NAME)
            processes = []
            for i in range(process_count):
                process_name = ctypes.c_char_p()
                owner = ctypes.c_char_p()
                cmdline = ctypes.c_char_p()
                pid = ctypes.c_uint64()
                is_debugged = ctypes.c_bool()
                start_time = ctypes.c_int()

                err = vixlib.VixJob_GetNthProperties(
                    job_handle, i, vixlib.VIX_PROPERTY_JOB_RESULT_ITEM_NAME,
                    ctypes.byref(process_name),
                    vixlib.VIX_PROPERTY_JOB_RESULT_PROCESS_ID,
                    ctypes.byref(pid),
                    vixlib.VIX_PROPERTY_JOB_RESULT_PROCESS_OWNER,
                    ctypes.byref(owner),
                    vixlib.VIX_PROPERTY_JOB_RESULT_PROCESS_COMMAND,
                    ctypes.byref(cmdline),
                    vixlib.VIX_PROPERTY_JOB_RESULT_PROCESS_BEING_DEBUGGED,
                    ctypes.byref(is_debugged),
                    vixlib.VIX_PROPERTY_JOB_RESULT_PROCESS_START_TIME,
                    ctypes.byref(start_time), vixlib.VIX_PROPERTY_NONE)

                processes.append(
                    dict(pid=pid.value,
                         name=process_name.value,
                         owner=owner.value,
                         cmdline=cmdline.value,
                         is_debugged=is_debugged.value,
                         start_time=start_time.value))

                vixlib.Vix_FreeBuffer(process_name)
                vixlib.Vix_FreeBuffer(owner)
                vixlib.Vix_FreeBuffer(cmdline)
        finally:
            vixlib.Vix_ReleaseHandle(job_handle)

        return processes
Exemplo n.º 7
0
    def read_guest_variable_str(self,
                                variable_name,
                                variable_type=vixlib.VIX_VM_GUEST_VARIABLE,
                                timeout=30):
        if variable_type in (vixlib.VIX_VM_GUEST_VARIABLE,
                             vixlib.VIX_GUEST_ENVIRONMENT_VARIABLE):
            self.wait_for_tools_in_guest(timeout)

        job_handle = vixlib.VixVM_ReadVariable(self._vm_handle, variable_type,
                                               variable_name, 0, None, None)
        read_value = ctypes.c_char_p()
        err = vixlib.VixJob_Wait(
            job_handle, vixlib.VIX_PROPERTY_JOB_RESULT_VM_VARIABLE_STRING,
            ctypes.byref(read_value), vixlib.VIX_PROPERTY_NONE)
        vixlib.Vix_ReleaseHandle(job_handle)
        _check_job_err_code(err)

        value = read_value.value
        vixlib.Vix_FreeBuffer(read_value)

        return value
Exemplo n.º 8
0
    def create_snapshot(self,
                        include_memory=False,
                        name=None,
                        description=None):
        if include_memory:
            options = vixlib.VIX_SNAPSHOT_INCLUDE_MEMORY
        else:
            options = 0

        job_handle = vixlib.VixVM_CreateSnapshot(self._vm_handle, name,
                                                 description, options,
                                                 vixlib.VIX_INVALID_HANDLE,
                                                 None, None)
        snapshot_handle = vixlib.VixHandle()
        err = vixlib.VixJob_Wait(job_handle,
                                 vixlib.VIX_PROPERTY_JOB_RESULT_HANDLE,
                                 ctypes.byref(snapshot_handle),
                                 vixlib.VIX_PROPERTY_NONE)
        vixlib.Vix_ReleaseHandle(job_handle)
        _check_job_err_code(err)

        return VixSnapshot(snapshot_handle)
Exemplo n.º 9
0
 def login_guest(self, username, password, options):
     job_handle = vixlib.VixVM_LoginInGuest(self._vm_handle, username,
                                            password, options, None, None)
     err = vixlib.VixJob_Wait(job_handle, vixlib.VIX_PROPERTY_NONE)
     _check_job_err_code(err)
Exemplo n.º 10
0
 def suspend(self):
     job_handle = vixlib.VixVM_Suspend(self._vm_handle, 0, None, None)
     err = vixlib.VixJob_Wait(job_handle, vixlib.VIX_PROPERTY_NONE)
     vixlib.Vix_ReleaseHandle(job_handle)
     _check_job_err_code(err)
Exemplo n.º 11
0
 def pause(self):
     job_handle = vixlib.VixVM_Pause(self._vm_handle, 0,
                                     vixlib.VIX_INVALID_HANDLE, None, None)
     err = vixlib.VixJob_Wait(job_handle, vixlib.VIX_PROPERTY_NONE)
     vixlib.Vix_ReleaseHandle(job_handle)
     _check_job_err_code(err)