Hi,
Environment:
VI Toolkit for Windows Version 1.0 (Released 2008/09/04 | Build: 113525)
VMware VirtualCenter Version 2.5.0 | Build 64192
ESX Server Version 3.5.0 | Build 64607
Visual Studio 2005 | C#
I have written a C# application using the VI toolkit for windows that tries to deploy a template to a virtual machine. The code, however, fails with the following error:
The operation is not supported on the object.
Having gone through earlier posts about this issue, I gathered that this error is thrown if you are running against an ESX server instead of a VC server. In my case, I am connecting to a VC server. Also, I would like to mention that I can do the exact same operation using the VI Client (again running against the VC Server). I am using the same credentials to login both with the VI Client and the API program. I am able to do other stuff with my program like browse through virtual machines, datacenters etc. Even mark a template as a virtual machine. Just the CloneVM_Task wont work.
Also, I would like to mention that I used the GPS application posted by LucD in this forum. This application is written in powershell and is meant to exactly the same thing I am trying to accomplish, deploy VMs from templates. I get the exact same error when I run this application "Operation is not supported on the object"
So my guess is, this has something to do with my Virtual Center Server settings maybe.
All VMware services are running on the VirtualCenter Server
I am completely stumped. Please help.
CODE:
using VMware.Vim;
namespace VMAutomation
{
class Program
{
static void Main(string[] args)
{
VimClient vimClient = new VimClient();
try
{
// Connect and Login
vimClient.Connect("https://10.2.3.10/sdk");
vimClient.Login("administrator", "<adminpassword>");
// Set up Virtual Machine Clone Spec
VirtualMachineCloneSpec virtualMachineCloneSpec = new VirtualMachineCloneSpec();
// Get Datastore
IList<EntityViewBase> dataCenterList = vimClient.FindEntityViews(typeof(Datacenter), null, null, null);
ManagedObjectReference chosenDataStore = ((Datacenter)dataCenterList[0]).Datastore[0];
// Get Resource Pool
NameValueCollection nvc = new NameValueCollection();
nvc.Add("Name", "AutomatedDeployment");
ResourcePool resourcePool = (ResourcePool)vimClient.FindEntityView(typeof(ResourcePool), null,
nvc, new string[] { "Name" });
Console.WriteLine("Resource Pool Name = ", resourcePool.Name);
// Set up Clone Spec.
virtualMachineCloneSpec.Location = new VirtualMachineRelocateSpec();
virtualMachineCloneSpec.Location.Datastore = chosenDataStore;
virtualMachineCloneSpec.Location.Pool = resourcePool.MoRef;
virtualMachineCloneSpec.PowerOn = false;
virtualMachineCloneSpec.Template = false;
// Get Template that needs to be deployed to a VM
NameValueCollection filterForBaseTemplate = new NameValueCollection();
filterForBaseTemplate.Add("Name", "Win2003R2SP2ESX01");
VirtualMachine baseTemplate = (VirtualMachine)vimClient.FindEntityView(typeof(VirtualMachine), null,
filterForBaseTemplate, null);
// get Folder for the datacenter
IList<EntityViewBase> datacenterlist = vimClient.FindEntityViews(typeof(Datacenter), null, null, null);
ManagedObjectReference folder = ((Datacenter)datacenterlist[0]).HostFolder;
// Deploy Template.
ManagedObjectReference taskMor
= baseTemplate.CloneVM_Task(folder, "VM-37-EID", virtualMachineCloneSpec);
Task task = (Task)vimClient.GetView(taskMor, null);
while (task.Info.State != TaskInfoState.success && task.Info.State != TaskInfoState.error)
{
Console.WriteLine("Waiting...");
}
}
catch (Exception exp)
{
Console.WriteLine(exp.ToString());
}
finally
{
vimClient.Disconnect();
}
}
}
}
I'm not sure that's the right folder. I would have guessed it needed to go into the folder named "vm" (or a subfolder of it) rather than the host folder.
Thanks. That worked!
Indeed it is true that I was passing in the HostFolder which I believe cannot have Virtual Machines. I wasnt very clear on the concept of folders but after reading the documentation it is much clearer now.
Folders that have hosts can only have hosts and their subfolders can only have hosts too.
I do wish that the exception was a bit more descriptive
"operation not supported by the object" didnt provide me much.
Also, on that note, is there a way to turn up debugging (verbose logging) on the web service log and where is the web service log located.
On the client side I know I can add a trace listener to the VITrace class that gives me more logs I guess.
Again, thanks for your help with this.
Vishal.
Your best bet is the logs under /var/log/vmware on the ESX server. I don't know how to increase the level or whether it's necessary as they tend to be very verbose.
Thanks for info on the log location. About the verbose logging, I only wanted to know so I could turn it on when I needed to debug something. I am only working against a test ESX server. This is not a production server.
Any other pointers you may have regarding debugging the web service would be helpful too. I am novice at java web services running on tomcat.
Thanks,
Vishal.