intripoon
Contributor
Contributor

How to detect if a datastore is vmfs or nfs or etc.?

Afaik I'm only allowed to call QueryChangedDiskAreas with a "*" on files residing on vmfs datastores. How do I determine the filesystem of the datastore programatically?

0 Kudos
6 Replies
RubyIvy
Enthusiast
Enthusiast

In the vsphere Client if you slect the ESxi Host -> configuration -> storage > their is a field called "Type" , it will tell you if datastore is vmfs or nfs.

If you find this or any other answer useful please consider awarding points by marking the answer correct or helpful.
0 Kudos
vThinkBeyondVM
VMware Employee
VMware Employee

You can get file system details@datastore from vSphere API data object " DatastoreSummary". This data object has one property called "type". Once you retrieve this property you can know what is the type of file system that datastore is created of.

DatastoreSummary.png

Refer: vSphere 5.5 Documentation Center

If it is useful, plz mark answer as correct or helpful.
----------------------------------------------------------------
Thanks & Regards
Vikas, VCP50, MCTS on AD, SCJP6.0.
http://vThinkBeyondVM.com
-----------------------------------------------------------------
Disclaimer: Any views or opinions expressed here are strictly my own. I am solely responsible for all content published here. Content published here is not read, reviewed or approved in advance by VMware and does not necessarily represent or reflect the views or opinions of VMware.

0 Kudos
intripoon
Contributor
Contributor

I read about the DataStoreSummary before. In this thread https://communities.vmware.com/thread/486158 , togtog says I can access it programmatically by

    VirtualDisk.backing(VirtualDeviceFileBackingInfo).datastore.summary.type = vmfs | nfs | cifs | vfat

   

But looking at my backinginfo values, I don't have a datastore.summary. I have a datastore value and a type. Bu ttype is only "Datastore" all the time. Where do I get this summary from programmatically ?

backinginfo.png

0 Kudos
vThinkBeyondVM
VMware Employee
VMware Employee

You will have to play with Managed object "Datastore". Once you create instance of Datastore managed object, "datastoreSummary is one of properties of "Datastore".

Here is one code snippet which can solve your problem: (Refereed from VIJAVA project)


package com.vmware.vim25.mo.samples.storage;

import java.net.URL;

import com.vmware.vim25.ArrayOfHostDatastoreBrowserSearchResults;

import com.vmware.vim25.DatastoreInfo;

import com.vmware.vim25.FileInfo;

import com.vmware.vim25.FileQuery;

import com.vmware.vim25.FileQueryFlags;

import com.vmware.vim25.HostDatastoreBrowserSearchResults;

import com.vmware.vim25.HostDatastoreBrowserSearchSpec;

import com.vmware.vim25.VmDiskFileInfo;

import com.vmware.vim25.VmDiskFileQuery;

import com.vmware.vim25.mo.Datastore;

import com.vmware.vim25.mo.Folder;

import com.vmware.vim25.mo.HostDatastoreBrowser;

import com.vmware.vim25.mo.HostSystem;

import com.vmware.vim25.mo.InventoryNavigator;

import com.vmware.vim25.mo.ServiceInstance;

import com.vmware.vim25.mo.Task;

public class SearchDatastore

{

  public static void main(String[] args) throws Exception

  {

   if(args.length != 3)

   {

   System.out.println("Usage: java SearchDatastore <url> "

   + "<username> <password>");

   return;

   }

  

   ServiceInstance si = new ServiceInstance(

   new URL(args[0]), args[1], args[2], true);

   // you need to send 3 parameters, vcip/username/password

   String hostname = "<HOST IP>";

  

   Folder rootFolder = si.getRootFolder();

   HostSystem host = null;

   host = (HostSystem) new InventoryNavigator(

   rootFolder).searchManagedEntity("HostSystem", hostname);

   if(host==null)

   {

   System.out.println("Host not found");

   si.getServerConnection().logout();

   return;

   }

  

   HostDatastoreBrowser hdb = host.getDatastoreBrowser();

 

   System.out.println("print out the names of the datastores");

   Datastore[] ds = hdb.getDatastores();

//From above line, you got all the datastore those can be browsed from a particular host

//Below loop, you can get all the properties from all datastores.

   for(int i=0; ds!=null && i<ds.length; i++)

   {

   System.out.println("datastore["+i+"]:");

String datastoreType = ds.getDatastoreSummary().getDatastoreType();

   }

  

   }

Notes:

1. String datastoreType = ds.getDatastoreSummary().getDatastoreType(); can give you whatever you want.

2. This code snippet I have not tested, plz make changes as per your requirement.

3. Refer complete code snippet here: http://sourceforge.net/p/vijava/code/HEAD/tree/v5.1/src/com/vmware/vim25/mo/samples/storage/SearchDa...

4. VIJAVA getting started : Get Started Tutorial

On Monday, I will test this code in my environment. Let me know if you need any help on this.

If it is useful, plz mark answer as correct or helpful.
----------------------------------------------------------------
Thanks & Regards
Vikas, VCP50, MCTS on AD, SCJP6.0.
http://vThinkBeyondVM.com
-----------------------------------------------------------------
Disclaimer: Any views or opinions expressed here are strictly my own. I am solely responsible for all content published here. Content published here is not read, reviewed or approved in advance by VMware and does not necessarily represent or reflect the views or opinions of VMware.

0 Kudos
intripoon
Contributor
Contributor

Is this available in .net as well somehow? My datastores don't seem to have a getDatastoreType() . They only have a Value and a type.

0 Kudos
vThinkBeyondVM
VMware Employee
VMware Employee

As per https://www.vmware.com/support/developer/windowstoolkit/wintk40/doc/viwin_devg.pdf this Dev guide on .Net. vSphere APIs can be leveraged by using .Net.

If you could convert above code snippet in .Net as it is, it should work fine.  Above code is totally based on java. If you are OK, I will help you on setting up java VIJAVA environment in eclipse.  As I completely work on Java/PowerCLI, I do not have experience on .Net.

Here are some other links for self-service support:

„ Product information—http://www.vmware.com/products/

„ Developer Center—http://www.vmware.com/communities/content/developer

„ Documentation—http://www.vmware.com/support/pubs

„ Knowledge Base—http://kb.vmware.com

„ User groups—http://www.vmware.com/communities/content/vmug/index.html

„ Developer Community—http://communities.vmware.com/community/developer

If it is useful, plz mark answer as correct or helpful.
----------------------------------------------------------------
Thanks & Regards
Vikas, VCP50, MCTS on AD, SCJP6.0.
http://vThinkBeyondVM.com
-----------------------------------------------------------------
Disclaimer: Any views or opinions expressed here are strictly my own. I am solely responsible for all content published here. Content published here is not read, reviewed or approved in advance by VMware and does not necessarily represent or reflect the views or opinions of VMware.

0 Kudos