Hi,
When I receive VmCreatedEvent I receive new vm ref. While retrieving new VMs property, I would like to find "Datacenter name". I am not able to traverse from VM to Datacenter. Can someone help me with this?
I am trying following traversal (vSphere SDK for Java):
PropertySpec dcSpec = new PropertySpec();
dcSpec.setType("Datacenter");
dcSpec.setPathSet(new String[] {"name"});
hostPropSpec.setAll(false);
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
pfSpec.setPropSet(new PropertySpec[] {dcSpec});
pfSpec.setObjectSet(new ObjectSpec[] {oSpec });
return getService().retrieveProperties(getContent().getPropertyCollector(), new PropertyFilterSpec[] {pfSpec });
this is not working.
Thanks in advance.
Hi,
I have c# code for getting datacenter name from vm ref. Here i have explained how i got datacenter using vm ref in c#. I think it may helpful u to get equivalent in java.
steps:
1) get vm ref using findbyip method by sending datacenter name as null.
ManagedObjectReference VMObject = _service.FindByIp(_sic.searchIndex, null, clientIp, true);
2) get the vmparent as moref using getdynamicprop
ManagedObjectReference vmParent = (ManagedObjectReference)GetDynamicProp(VMObject, "parent");
3) get datacenter name as moref using getdynamicprop
ManagedObjectReference dataCenter = (ManagedObjectReference)GetDynamicProp(vmParent, "parent");
let me know if u need getdynamicprop function explanation. I think it will be in vijava src.
Thanks,
Vijaya
You may want to try VMware sponsored open source project vijava API here: http://vijava.sf.net. With the API, you don't get the VirtualMachine instance from its moref with the MorUtil utility class. Once you have that say vm, you can simple code like this:
String datacenterName = vm.getParent().getParent().getName();
Before you use the API, read the 5 minute get started tutorial: http://vijava.sourceforge.net/doc/getstarted/tutorial.htm
For more details on the inventory structure, check here: http://www.doublecloud.org/2010/03/vsphere-inventory-structure-deep-dive/
Good luck!
Steve, author of VMware VI and vSphere SDK by Prentice Hall
Hi,
I have c# code for getting datacenter name from vm ref. Here i have explained how i got datacenter using vm ref in c#. I think it may helpful u to get equivalent in java.
steps:
1) get vm ref using findbyip method by sending datacenter name as null.
ManagedObjectReference VMObject = _service.FindByIp(_sic.searchIndex, null, clientIp, true);
2) get the vmparent as moref using getdynamicprop
ManagedObjectReference vmParent = (ManagedObjectReference)GetDynamicProp(VMObject, "parent");
3) get datacenter name as moref using getdynamicprop
ManagedObjectReference dataCenter = (ManagedObjectReference)GetDynamicProp(vmParent, "parent");
let me know if u need getdynamicprop function explanation. I think it will be in vijava src.
Thanks,
Vijaya