1

I created an serviceInstance of vCenter 6.0 using vijava5.5

When i try to fetch the properties of Datastore using SerachManagedEntity am getting null response even for available datastore

Datastore ds = (Datastore) new InventoryNavigator(rootFolder).searchManagedEntity("Datastore", "scsi_10_3");

ds is null http://prntscr.com/6izkxi

But the datastore is availabe in vCenter http://prntscr.com/6izl1b

What could be the issue, its working properly in vCenter 5.5

asvignesh
  • 787
  • 2
  • 6
  • 32

4 Answers4

4

The problem is due to the fact that what youre doing uses the InventoryNavigator + VIJAVA + vSphere 6.0. If youre using vijava 5.5 beta or any version released prior to that it is hard coded to look for version 4 or 5 of the API to load the proper inventory path for InventoryNavigator. I suggest using YAVIJAVA it is a fork of VIJAVA I created and maintain. I fixed that bug in version 5.5.10 and it is currently available in GitHub and has been released to public Maven as of today.

If you use the GitHub version you will need to

gradle build

If you want to use Maven it will may take several hours before it syncs into the central repos.

Just an FYI but the version of vijava youre using also has another bug where it only ever throws RemoteException. I have fixed that too in YAVIJAVA. Ive also added logging to it as well. Official 6.0 support is also actively being worked on if you check out the 6.0 branch.

Michael Rice
  • 7,974
  • 1
  • 15
  • 18
1

If you have to get DataStore and StoragePod from vSphere 6.0 thru vijava 5.1 but without InventoryNavigator then you can get is get thru' Datacenter object.

       ManagedEntity[] meArr = rootFolder.getChildEntity();
       for (ManagedEntity me : meArr) {
            if (me instanceof Datacenter) {
                Datacenter dc = (Datacenter) me;
                // All datastores related to the Datacenter
                Datastore[] dsArr = dc.getDatastores();
                // You can also get StoragePod  
                StoragePod sp = (StoragePod) ds.getParent();
                }
            }

Of course, this is very unoptimized way and only to be used if you do not want to use yavijava for some reason. Otherwise yavijava is better for sure, makes your life easy.

Dipak
  • 11
  • 1
0

You can get the datastore in the following way from the InventoryNavigator.

snippet :

ServiceInstance si = new ServiceInstance(new URL("https://" + hostname + "/sdk/"), username, password, true);
InventoryNavigator invNav = new InventoryNavigator(si.getRootFolder());
ManagedEntity[] mes = invNav.searchManagedEntities("HostSystem");
HostSystem hostSystem = (HostSystem)mes[0];
HostDatastoreSystem hds = hostSystem.getHostDatastoreSystem();
datastores = hds.getDatastores();

Check this out.

ArunK
  • 3
  • 5
-1

I hope you cannot get "DataStore" from inventory. It can be fetch from HostSystem only. From HostSystem, you can get all DataStores. From that you can iterate and get it.

Selvaraj
  • 9
  • 9
  • yes... actually its not best practice, should have to get form the HostSystem but earlier it was working – asvignesh Mar 20 '15 at 18:44
  • You should delete the comment. Its 100% incorrect. You can get a Datastore from the Inventory. It is a Managed Object just like a HostSystem is. Its part of a Datacenter just like a HostSystem. – Michael Rice Mar 22 '15 at 15:32
  • Michael Rice correct me if am wrong, my vCenter can have multiple datastore with same name on different datacenters, if i get from rootFolder it may not give the exact result what i need... – asvignesh Mar 22 '15 at 16:47
  • Thats correct. Names for Datastore and VirtualMachine and a few other objects are only unique inside a Datacenter. HostSystem are unique in the vCenter because thats how vCenter connects to them to add them to the inventory. If you are trying to find a specific Datastore and you know what Datacenter it is in you should use that Datacenter where you use rootFolder, or use a findByInventoryPath – Michael Rice Mar 22 '15 at 16:56
  • 1
    Also please note that when using the InventoryNavigator like you have it is using a property collector to find ALL the Datastore objects in the inventory then returns the 1 that you wanted based on a name match. If you have a large inventory with 1000's of objects this can be a really bad way to find what you are looking for. – Michael Rice Mar 22 '15 at 16:59
  • @MichaelRice hi.. I have one little different case here.. I have one java console application with vijava 5.5 and vcentre 6.0.. In that I am able to get datacentre and hostsystem from "InventoryNavigator" class. But i copied same code in my vsphere plugin and deployed in vcentre 6.0.. That time, this code returns "null".. I dont know why its working in java console application but not in vsphere plugin.. Can you please suggest me? – Selvaraj Jun 01 '15 at 10:03
  • 1
    @Selvaraj switch to yavijava. I have 6.0 beta support done. http://www.errr-online.com/index.php/2015/05/26/yavijava-6-0-beta-release-ready-for-vsphere-6-0/ If you want to stick to vijava you will need to reach out to the creator for support. – Michael Rice Jun 01 '15 at 18:09