I've searched everywhere for an answer to this before posting here. I found at least one similar post but it had no answer.
I can successfully clone a VirtualMachine to another VirtualMachine with my code, but if I attempt to clone a template to a VirtualMachine, I get a com.vmware.vim25.InvalidArgument exception, with this stacktrace:
com.vmware.vim25.InvalidArgument
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at java.lang.Class.newInstance(Class.java:433)
at com.vmware.vim25.ws.XmlGenDom.fromXml(XmlGenDom.java:205)
at com.vmware.vim25.ws.XmlGenDom.fromXml(XmlGenDom.java:341)
at com.vmware.vim25.ws.XmlGenDom.fromXml(XmlGenDom.java:341)
at com.vmware.vim25.ws.XmlGenDom.fromXml(XmlGenDom.java:341)
at com.vmware.vim25.ws.XmlGenDom.fromXml(XmlGenDom.java:333)
at com.vmware.vim25.ws.XmlGenDom.fromXML(XmlGenDom.java:190)
at com.vmware.vim25.ws.XmlGenDom.fromXML(XmlGenDom.java:104)
at com.vmware.vim25.ws.WSClient.invoke(WSClient.java:118)
at com.vmware.vim25.ws.VimStub.retrieveProperties(VimStub.java:72)
at com.vmware.vim25.mo.PropertyCollector.retrieveProperties(PropertyCollector.java:107)
at com.vmware.vim25.mo.ManagedObject.retrieveObjectProperties(ManagedObject.java:155)
at com.vmware.vim25.mo.ManagedObject.getCurrentProperty(ManagedObject.java:179)
at com.vmware.vim25.mo.Task.waitForMe(Task.java:121)
(...and then my stuff that called waitForMe)
The account I'm performing this from has full administrator rights, so I should have all permissions (I'm aware of the different permissions required for cloning from (template|VM) to (template|VM)).
The code I'm running that does the clone is essentially:
void clone(ServiceInstance serviceInstance, String origVMName, String destVMName)
throws Exception {
Folder rootFolder = serviceInstance.getRootFolder();
VirtualMachine vm = (VirtualMachine) new InventoryNavigator(rootFolder).searchManagedEntity("VirtualMachine", origVMName);
if (vm==null) {
// Fail
return;
}
if (vm.getSummary().getConfig().template) {
System.out.println("Warning - original VM is a template - this will fail");
}
VirtualMachineCloneSpec vmCloneSpec = new VirtualMachineCloneSpec();
vmCloneSpec.setLocation(new VirtualMachineRelocateSpec());
vmCloneSpec.setPowerOn(true);
vmCloneSpec.setTemplate(false);
Folder parentFolder = (Folder) vm.getParent();
Task cloneTask = vm.cloneVM_Task(parentFolder, destVMName, vmCloneSpec);
if (cloneTask.waitForMe() == Task.SUCCESS) { // <-- This throws exception if Template
// ...
}
}
Ideally I'd like to be able to support cloning either a template or a VM into a VM, so I'd really like to nail this down.
Any ideas?
Thanks for your time,
..Jeff Keegan
jkeegan@keegan.org
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm thinking maybe I have an idea about my own problem, but I'm not sure.
First, I looked through the vijava source code to see where the exception was happening. It was right before grabbing the Info property on the Task object.
That brought up a browsable web page showing me the Task managed object in question.
The "description" field looked suspicious - it's key was com.vmware.vim.vpxd.vpx.vmprov.SelectDestination.. Maybe I need to specify which Host a clone should go on when it's from a template?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
void clone(ServiceInstance serviceInstance, String origVMName, String destVMName, String destHost)
throws Exception {
Folder rootFolder = serviceInstance.getRootFolder();
VirtualMachine vm = (VirtualMachine) new InventoryNavigator(rootFolder).searchManagedEntity("VirtualMachine", origVMName);
if (vm==null) {
// Fail
return;
}
HostSystem host = null;
if ((destHost != null) && (!(destHost.equals("")))) {
host = (HostSystem) new InventoryNavigator(rootFolder).searchManagedEntity("HostSystem", destHost);
if (host == null) {
System.out.println("host \"" + destHost + "\" was specified but could not be found. Aborting.");
return;
}
}
if (vm.getSummary().getConfig().template) {
System.out.println("Warning - original VM is a template - this will fail");
}
VirtualMachineCloneSpec vmCloneSpec = new VirtualMachineCloneSpec();
VirtualMachineRelocateSpec vmrs = new VirtualMachineRelocateSpec();
if (host != null) {
vmrs.setHost(host.getMOR());
}
vmCloneSpec.setLocation(vmrs);
vmCloneSpec.setPowerOn(true);
vmCloneSpec.setTemplate(false);
Folder parentFolder = (Folder) vm.getParent();
Task cloneTask = vm.cloneVM_Task(parentFolder, destVMName, vmCloneSpec);
if (cloneTask.waitForMe() == Task.SUCCESS) { // <-- This throws exception if Template
// ...
}
}
That doesn't work. It generates this:
com.vmware.vim25.InvalidArgument
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at java.lang.Class.newInstance(Class.java:383)
at com.vmware.vim25.ws.XmlGenDom.fromXml(XmlGenDom.java:205)
at com.vmware.vim25.ws.XmlGenDom.fromXml(XmlGenDom.java:341)
at com.vmware.vim25.ws.XmlGenDom.fromXml(XmlGenDom.java:341)
at com.vmware.vim25.ws.XmlGenDom.fromXml(XmlGenDom.java:341)
at com.vmware.vim25.ws.XmlGenDom.fromXml(XmlGenDom.java:333)
at com.vmware.vim25.ws.XmlGenDom.fromXML(XmlGenDom.java:190)
at com.vmware.vim25.ws.XmlGenDom.fromXML(XmlGenDom.java:104)
at com.vmware.vim25.ws.WSClient.invoke(WSClient.java:118)
at com.vmware.vim25.ws.VimStub.retrieveProperties(VimStub.java:72)
at com.vmware.vim25.mo.PropertyCollector.retrieveProperties(PropertyCollector.java:107)
at com.vmware.vim25.mo.ManagedObject.retrieveObjectProperties(ManagedObject.java:155)
at com.vmware.vim25.mo.ManagedObject.getCurrentProperty(ManagedObject.java:179)
at com.vmware.vim25.mo.Task.waitForMe(Task.java:121)
(...and then my stuff that called waitForMe)
So I've hit a wall again. I welcome any/all help and or suggestions. Thanks.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I've searched everywhere for an answer to this before posting here. I found at least one similar post but it had no answer.
I can successfully clone a VirtualMachine to another VirtualMachine with my code, but if I attempt to clone a template to a VirtualMachine, I get a com.vmware.vim25.InvalidArgument exception, with this stacktrace:
The account I'm performing this from has full administrator rights, so I should have all permissions (I'm aware of the different permissions required for cloning from (template|VM) to (template|VM)).
The code I'm running that does the clone is essentially:
Ideally I'd like to be able to support cloning either a template or a VM into a VM, so I'd really like to nail this down.
Any ideas?
Thanks for your time,
..Jeff Keegan
jkeegan@keegan.org
I'm thinking maybe I have an idea about my own problem, but I'm not sure.
First, I looked through the vijava source code to see where the exception was happening. It was right before grabbing the Info property on the Task object.
So then I used this trick I'd learned about when reading the threads:
https://x.x.x.x/mob/?moid=task-698
That brought up a browsable web page showing me the Task managed object in question.
The "description" field looked suspicious - it's key was com.vmware.vim.vpxd.vpx.vmprov.SelectDestination.. Maybe I need to specify which Host a clone should go on when it's from a template?
Nope. I tried changing the code to this:
That doesn't work. It generates this:
So I've hit a wall again. I welcome any/all help and or suggestions. Thanks.