Missing Method

Mar 4, 2011 at 5:17 PM

Hi

I was able to use your sample code

When I step thru code the PowerOn works but the code hangs there and times out

And in the source code I cannot access this method - virtualMachine.WaitForToolsInGuest(); it is not available in intellisense

using Vestris.VMWareLib;

....

// declare a virtual host
            VMWareVirtualHost virtualHost = new VMWareVirtualHost();
            // connect to a remote (VMWare ESX) virtual machine
            virtualHost.ConnectToVMWareVIServer("xxx.xxx.x.xx", "userid", "password");
            // open an existing virtual machine
            VMWareVirtualMachine virtualMachine = virtualHost.Open("[Storage1-wfdvmh01] some.vmx");


           // power on this virtual machine
           virtualMachine.PowerOn();

           // wait for VMWare Tools
           //virtualMachine.WaitForToolsInGuest();

           // power off
           virtualMachine.PowerOff();

Coordinator
Mar 5, 2011 at 11:31 AM

You mean this only happens under a debugger or when you run it without a debugger? Make sure to use the using { } pattern around that virtualmachine object, it could be having issues when leaving this function, not inside powerOn, powerOff.

Mar 5, 2011 at 1:35 PM

Hi

Could of questions

1)Should I be using this method
// wait for VMWare Tools
virtualMachine.WaitForToolsInGuest();

As you can see below - I don't have option to call from intellisense





2) This is how I am calling is this correct ??

using Vestris.VMWareLib;


namespace VmWareClient
{
class VmWareClient
{
static void Main(string[] args)
{
VmWareClient vm = new VmWareClient();
vm.CreateDir();

}



void CreateDir()
{


// declare a virtual host
using ( VMWareVirtualHost virtualHost = new VMWareVirtualHost())
{


// connect to a remote (VMWare ESX) virtual machine
virtualHost.ConnectToVMWareVIServer("143.122.8.38", "us294255", "tester01!");
// open an existing virtual machine
VMWareVirtualMachine virtualMachine =
virtualHost.Open("[Storage1-wfdvmh01] wfdvmh01dw71_1/wfdvmh01dw71.vmx");


// power on this virtual machine
virtualMachine.PowerOn();

// wait for VMWare Tools
//virtualMachine.WaitForToolsInGuest();

// power off
virtualMachine.PowerOff();
}




}
}


The PowerOn will Start the VM because I can see it on the VMServer Dashboard - but my console app times out
Not sure if I should be calling virtualMachine.WaitForToolsInGuest(); after PowerON buy like I said - it is not a recognized Method


Unhandled Exception: System.TimeoutException: The operation has timed out.
at Vestris.VMWareLib.VMWareJobCallback.WaitForCompletion(Int32 timeoutInMilli
seconds)
at Vestris.VMWareLib.VMWareJob.Wait(Int32 timeoutInSeconds)
at Vestris.VMWareLib.VMWareVirtualMachine.PowerOn(Int32 powerOnOptions, Int32
timeoutInSeconds)
at Vestris.VMWareLib.VMWareVirtualMachine.PowerOn(Int32 timeoutInSeconds)
at Vestris.VMWareLib.VMWareVirtualMachine.PowerOn()
at VmWareClient.VmWareClient.CreateDir() in C:\Data\DotNet\CSharp\VMWare\VmWa
reClient\Program.cs:line 88
at VmWareClient.VmWareClient.Main(String[] args) in C:\Data\DotNet\CSharp\VMW
are\VmWareClient\Program.cs:line 16
Press any key to continue . . .




Steve J. Siperas | Software Specialist
3M Health Information Systems Div
100 Barnes Road, Wallingford,CT 06492 | 06492
Office: +1 203 949 6408 | Fax: 203 949 6331 | Triminet: 340 6408

sjsiperas@mmm.com | www.3M.com


Privileged/Confidential Information may be contained in this message. If you are not the addressee indicated in this message (or responsible for delivery of the message to such person), you may not copy or deliver this message to anyone. In such case, you should destroy this message, and notify us immediately. If your employer does not consent to Internet e-mail messages of this kind, please advise us immediately. Opinions, conclusions and other information expressed it this message are not given or endorsed by my firm or employer unless otherwise indicated by an authorized representative independent of this message

Coordinator
Mar 11, 2011 at 2:02 PM

Yes, you should be using this method and yes, it's there. I am not sure what's going on. I suggest you build a clean repro, I'd be happy to try it.

Mar 11, 2011 at 3:18 PM


Is there a way I can send you my solution ?
Coordinator
Mar 12, 2011 at 11:10 AM

File a bug and attach it.

Coordinator
Mar 14, 2011 at 10:22 AM

You have VMWareTasks 1.1 in the references from CodeProject. We're at version 1.5. Please update. I had to make one more change: the Login method was long deprecated, it's called LoginInGuest to mirror VMWare API.

Jan 5, 2012 at 4:34 PM

Has anyone figured this out?

I almost pull my hair from my head since i work on my problem for a week

I have ESXi4.1 and vSphere 4.1

I also installed Vix 1.6.2 since this is the only free API

I've also downloaded the VMware Tasks 1.5 and tried also previous versions...

imported to my project all of the VMWare Tasks dlls

I do the following:

static void Main(string[] args)        {

{

using ( VMWareVirtualHost virtualHost = new VMWareVirtualHost()) 
{ 


// connect to a remote (VMWare ESX) virtual machine 
virtualHost.ConnectToVMWareVIServer(ESXi IP, Username, Password);  //OK CONNECTED GOOD
// open an existing virtual machine 
VMWareVirtualMachine virtualMachine = 
virtualHost.Open("[datastore1]  somevm/somevm.vmx");  // OK OPENED GOOD


// power on this virtual machine 
virtualMachine.PowerOn();   ////////////HERE I GET AN EXCEPTION OF TIMEOUT EXCEPTION EVEN IF I GIVE IT A BIG NUMBER LIKE 300000 SECONDS

// wait for VMWare Tools 
//virtualMachine.WaitForToolsInGuest(); 

// power off 
virtualMachine.PowerOff(); 
} 

}

 

I can't find anything in forums except here that someone got something similar and he didnt get any answer

Is it connected to that i have free license?? since i don't want to buy license unless i need it

it is very simple commend, only to power up so it is strange not to work on free version

i dont know if its he VMWare tasks bug or Vix bugs....

moreover when the VM is up manually and i try to runprogram without doing the PowerOn method before which does not work, it says that "virtual machine needs to be powered on"... BUT IT IS POWERED ON

Why such simple actions does not work?!?!?

PLLLLLEEAAAASSEEE help i work on somethiong huge in my company and i really can use some help

thanks alot

Jan 5, 2012 at 5:24 PM

You only need the VMwareTasks referenced in your program. Then write a method like I did below. The code below works with vCenter, ESXi or ESX server directly.

using Vestris.VMWareLib;

public static string vmOpen(string vcServer, string vcUserName, string vcPassword, string vmxFilePath)
            {
                string vmReturn = string.Empty;
                vmxFilePath = vmxFilePath.Trim('"');
                using (VMWareVirtualHost virtualHost = new VMWareVirtualHost())
                {

                    virtualHost.ConnectToVMWareVIServer(vcServer, vcUserName, vcPassword);
                    using (VMWareVirtualMachine virtualMachine = virtualHost.Open(vmxFilePath))
                    {
                        try
                        {
                            if (virtualMachine.IsRunning == false)
                            {
                                virtualMachine.PowerOn();
                                virtualMachine.WaitForToolsInGuest();
                                vmReturn = "Guest VM Powered On...";
                                virtualMachine.WaitForToolsInGuest(600);
                            }
                            else if (virtualMachine.IsSuspended)
                            {
                                virtualMachine.PowerOn();
                                virtualMachine.WaitForToolsInGuest();
                                vmReturn = "Guest VM Powered On...";
                                virtualMachine.WaitForToolsInGuest(600);
                            }
                            else
                            {
                                vmReturn = vmStateMsg.Running.ToString();
                                vmReturn = "Guest VM already Running...";
                                virtualMachine.WaitForToolsInGuest(600);
                            }
                        }
                        catch (COMException comExec)
                        {
                            vmReturn = comExec.Message;
                        }
                        return vmReturn;
                    }
                }
            }
Try this code and see if it helps.

Jan 5, 2012 at 7:17 PM

Thanks for the quick answer !!!

However, I've tried your code and that is not different from what I've done. Unfourtenatly, Even when my VirtualMachine is poweredOn, the API thinks in the code that the machine is not powered on for some reason...and more issues like this. I wanted to attach image to explain the situation but i cant seem hot to do it her so i'll explain


When the code asks if (virtualMachine.IsRunning == false) , then it return true even though I've powered on the machine manually before

When it enters the if block then when it tries to powerOn the machine then the code pass it and in the vSphere Console i see the log the statues:

" The attempted operation cannot be performed in the current state"

Therefore it tried to "WaitForToolsInGuest" and then VMwareException is thrown saying "the virtual machine needs to be powered on" even though it is on!

Moreover, if the machine is turened off then it is the same as before that the machine starts however the code throws "TimeoutException".

Is it familier to you, any alternatives? im really frustrated .... :(

Thanks alot!