VirtualMachine::VirtualMachine(QString vmFilePath, QObject *parent) : QObject(parent)
{

    VixHandle hostHandle = VIX_INVALID_HANDLE;
    VixHandle jobHandle = VIX_INVALID_HANDLE;
    VixError err;

    // Connect to specified host.
    jobHandle = VixHost_Connect(VIX_API_VERSION,
                                VIX_SERVICEPROVIDER_VMWARE_PLAYER,
                                0, // hostName
                                0, // hostPort
                                0, // userName
                                0, // password,
                                0, // options
                                VIX_INVALID_HANDLE, // propertyListHandle
                                NULL, // callbackProc
                                NULL); // clientData
    err = VixJob_Wait(jobHandle,
                      VIX_PROPERTY_JOB_RESULT_HANDLE,
                      &hostHandle,
                      VIX_PROPERTY_NONE);
    if (VIX_OK != err) {
       // Handle the error...
       VixHost_Disconnect(hostHandle);
    }
    Vix_ReleaseHandle(jobHandle);



    VixHandle vmHandle = VIX_INVALID_HANDLE;
    Q_ASSERT(vmFilePath.isEmpty());

    // Open virtual machine and get a handle.
    char *filePath = vmFilePath.toLatin1().data();
    jobHandle = VixVM_Open(hostHandle,
                           filePath,
                           NULL, // callbackProc
                           NULL); // clientData
    err = VixJob_Wait(jobHandle,
                      VIX_PROPERTY_JOB_RESULT_HANDLE,
                      &vmHandle,
                      VIX_PROPERTY_NONE);
    if (VIX_OK != err) {
       // Handle the error...
       VixHost_Disconnect(hostHandle);
    }

    Vix_ReleaseHandle(jobHandle);
    jobHandle = VIX_INVALID_HANDLE;
    // ...Use vmHandle in subsequent code...
}
Exemplo n.º 2
0
Arquivo: vm.c Projeto: billpeng93/vixr
VALUE
_read_var(VALUE self, VALUE rvm, VALUE rvartype, VALUE rname)
{
	VixHandle vm = NUM2INT(rb_iv_get(rvm,"@handle"));
	VixHandle job;
	VixError err;

	VALUE retval;

	int vartype = NUM2INT(rvartype);
	char *name = StringValueCStr(rname);
	int opts = 0;
	char *var = NULL;

	job = VixVM_ReadVariable(vm,vartype,name,opts,NULL,NULL);
	err = VixJob_Wait(job, VIX_PROPERTY_JOB_RESULT_VM_VARIABLE_STRING, &var, VIX_PROPERTY_NONE);
	Vix_ReleaseHandle(job);

	if(VIX_FAILED(err))
	{
		fprintf(stderr,"Failed to read variable virtual machine:%s\n",Vix_GetErrorText(err,NULL));
		return Qnil;
	}

	fprintf(stderr,"Read var \"%s\", got (%s)\n",name,var);

	retval = rb_str_new2(var);
	Vix_FreeBuffer(var);
	return retval;
}
Exemplo n.º 3
0
Arquivo: vm.c Projeto: billpeng93/vixr
VALUE 
_unpause(VALUE self, VALUE rvm)
{
	VixHandle vm = NUM2INT(rb_iv_get(rvm,"@handle"));
	VixHandle job;
	VixError err; 

	job = VixVM_Unpause(vm,0,VIX_INVALID_HANDLE,NULL,NULL);
	err = VixJob_Wait(job, VIX_PROPERTY_NONE);
	Vix_ReleaseHandle(job);

	if(VIX_FAILED(err)) 
	{
		fprintf(stderr,"Failed to unpause virtual machine: %s\n", Vix_GetErrorText(err,NULL));
		return Qnil;
	}

	return Qtrue;
}
Exemplo n.º 4
0
Arquivo: vm.c Projeto: billpeng93/vixr
VALUE
_upgrade_vhardware(VALUE self, VALUE rvm)
{
	VixHandle vm = NUM2INT(rb_iv_get(rvm,"@handle"));
	VixHandle job;
	VixError err;

	job = VixVM_UpgradeVirtualHardware(vm,0,NULL,NULL);
	err = VixJob_Wait(job, VIX_PROPERTY_NONE);
	Vix_ReleaseHandle(job);
		
	if(VIX_FAILED(err))
	{
		fprintf(stderr,"Failed to upgrade the virtual hardware: %s\n",Vix_GetErrorText(err,NULL));
		return Qnil;
	}
	
	return Qtrue;
}
Exemplo n.º 5
0
Arquivo: vm.c Projeto: billpeng93/vixr
VALUE 
_power_off(VALUE self, VALUE rvm, VALUE ropt)
{
	VixHandle vm = NUM2INT(rb_iv_get(rvm,"@handle"));
	VixHandle job;
	VixError err; 

	int opt = NUM2INT(ropt);

	job = VixVM_PowerOff(vm,opt,NULL,NULL);
	err = VixJob_Wait(job, VIX_PROPERTY_NONE);
	Vix_ReleaseHandle(job);
	
	if(VIX_FAILED(err)) 
	{
		fprintf(stderr,"Failed to power off virtual machine: %s\n", Vix_GetErrorText(err,NULL));
		return Qnil;
	}

	return Qtrue;
}
Exemplo n.º 6
0
Arquivo: vm.c Projeto: billpeng93/vixr
VALUE
_write_var(VALUE self, VALUE rvm, VALUE rtype, VALUE rname, VALUE rval)
{
	VixHandle vm = NUM2INT(rb_iv_get(rvm,"@handle"));
	VixHandle job;
	VixError err;
	
	int type = NUM2INT(rtype);
	char *name = StringValueCStr(rname);
	char *val = StringValueCStr(rval);

	job = VixVM_WriteVariable(vm,type,name,val,0,NULL,NULL);
	err = VixJob_Wait(job, VIX_PROPERTY_NONE);
	Vix_ReleaseHandle(job);

	if(VIX_FAILED(err))
	{
		fprintf(stderr,"Failed to write variable (%s) val=(%s): %s\n",name,val,Vix_GetErrorText(err,NULL));
		return Qnil;
	}

	return rval;
}