VMware Cloud Community
Yassir_bout
Enthusiast
Enthusiast
Jump to solution

How to browse a content of Datatsore

Hi,

I want to browse a Datastore and return all files  in Array variable.

I found vcHostDatastoreBrowser, VcHostDatastoreBrowserSearchResults

But I'v no idea how to use them.

Can you please give me an exemple to use this object or other exemple to browse my datastore .

Thanks

0 Kudos
1 Solution

Accepted Solutions
iiliev
VMware Employee
VMware Employee
Jump to solution

Hi,

Check the scripting actions in the module com.vmware.library.vc.datastore.files, for example com.vmware.library.vc.datastore.files/getAllConfigFile

Here is a slightly modified code of the above action that enumerates all VMDK files in the datastore and returns their names in the variable result (the input parameter is the datastore object in variable datastore😞

var result = new Array();

var querySpec = new VcHostDatastoreBrowserSearchSpec();

querySpec.query = null;

querySpec.matchPattern = ["*.vmdk"];

var task = datastore.browser.searchDatastoreSubFolders_Task("[" + datastore.name + "]", querySpec);

var searchResults = System.getModule("com.vmware.library.vc.basic").vim3WaitTaskEnd(task,false,5);

if (searchResults != null) {

  for (var i in searchResults) {

    if (searchResults[i].file != null) {

      for (var j in searchResults[i].file) {

        result.push(searchResults[i].folderPath + searchResults[i].file[j].path);

      }

    }

  }

}

System.log(result);

View solution in original post

0 Kudos
6 Replies
iiliev
VMware Employee
VMware Employee
Jump to solution

Hi,

Check the scripting actions in the module com.vmware.library.vc.datastore.files, for example com.vmware.library.vc.datastore.files/getAllConfigFile

Here is a slightly modified code of the above action that enumerates all VMDK files in the datastore and returns their names in the variable result (the input parameter is the datastore object in variable datastore😞

var result = new Array();

var querySpec = new VcHostDatastoreBrowserSearchSpec();

querySpec.query = null;

querySpec.matchPattern = ["*.vmdk"];

var task = datastore.browser.searchDatastoreSubFolders_Task("[" + datastore.name + "]", querySpec);

var searchResults = System.getModule("com.vmware.library.vc.basic").vim3WaitTaskEnd(task,false,5);

if (searchResults != null) {

  for (var i in searchResults) {

    if (searchResults[i].file != null) {

      for (var j in searchResults[i].file) {

        result.push(searchResults[i].folderPath + searchResults[i].file[j].path);

      }

    }

  }

}

System.log(result);

0 Kudos
Yassir_bout
Enthusiast
Enthusiast
Jump to solution

Hi Ilian,

Thank for your help.

Based on the Chinese proverb:

Do not give me a fish, but teach me how to fish.

I would like to learn the basics of using the vRO orchestrator.

Do you have internet links, youtube, blog, book that I can buy.

I want to learn the advanced use of the orchestrator with examples and others.

thank you in advance

0 Kudos
iiliev
VMware Employee
VMware Employee
Jump to solution

A good place to start would be https://www.vcoteam.info/ - it contains a lot of links to useful resources, blogs, etc.

On YouTube, just do a search for vcenter orchestrator or vrealize orchestrator, and you should get a lot of relevant videos.

As for books - there are few, like https://www.oreilly.com/library/view/vmware-vrealize-orchestrator/9781785884245/ or https://www.packtpub.com/networking-and-servers/vmware-vrealize-orchestrator-cookbook . I haven't read them, but you should be able to find reviews with some googling.

0 Kudos
Yassir_bout
Enthusiast
Enthusiast
Jump to solution

Thanks a lot for your reply.

I buy the too docs in PDF format for just 5$ each

VMWARE_VREALIZE_ORCHESTRATOR_COOKBOOK

VMWARE_VREALIZE_ORCHESTRATOR_ESSENTIALS

web site : Packt Publishing | Technology Books, eBooks & Videos

Thanks Smiley Happy

0 Kudos
Yassir_bout
Enthusiast
Enthusiast
Jump to solution

Hi

I try to use datastore.browser. searchDatastore_Task() to list only the repository in a datastore.

When i run this code

===========================Begin=============================================

1- querySpec.query = null; 

2- querySpec.sortFoldersFirst = true; 

3- var taskFolder = datastore.browser. searchDatastore_Task("[" + datastore.name + "]" , querySpec);

4- var searchResults = System.getModule("com.vmware.library.vc.basic").vim3WaitTaskEnd(taskFolder,false,5); 

5-  System.log("Task folder " + searchResults );

6- for each (var result in searchResults)

7- {

8- System.log(result.folderPath);

9- }

===========================End=================================================

The code in line 5 return this :

=====================================================================================

[2018-12-25 12:01:00.574] [I] Task folder DynamicWrapper (Instance) : [VcHostDatastoreBrowserSearchResults]-[class com.vmware.o11n.plugin.vsphere_gen.SearchResults_Wrapper] -- VALUE : (vim.host.SearchResults) {

   dynamicType = null,

   dynamicProperty = null,

   datastore = Stub: moRef = (ManagedObjectReference: type = Datastore, value = datastore-4095, serverGuid = null), binding = https://vSpherelab.itplab.extra:443/sdk,

   folderPath = [L001VRT4_LAB_ISO_0038],

   file = (vim.host.FileInfo) [

      (vim.host.FileInfo) {

         dynamicType = null,

         dynamicProperty = null,

       path = ISO,

         friendlyName = null,

         fileSize = null,

         modification = null,

         owner = null

      },

      (vim.host.FileInfo) {

         dynamicType = null,

         dynamicProperty = null,

       path = Template_Windows2000,

         friendlyName = null,

         fileSize = null,

         modification = null,

         owner = null

      },

========================================================

When I wannt to a acced to path with the code in line 6 to 9 I had this error :

Error in (Workflow:SNG.TestMountISO_Folder / Scriptable task (item1)#20) TypeError: Invalid iterator value

The idea is to return only the list of repository in my Datastore.

Any help Smiley Sad 

0 Kudos
Yassir_bout
Enthusiast
Enthusiast
Jump to solution

See the correct answer in this post

Workflow Script to Get only repertory in a Datastore

Thanks Ilian

0 Kudos