1

Orchestrator Function: Get All Files in a Datastores

by Simon Sparks · 1 October 2013

To use this function add it to the class library file named vCenterServerService.ts

GitHub Repository: https://github.com/SimonSparksUK/Orchestrator

Filename: vCenterServerService.ts

Description: The following script gets all files in a datastore

Function: getAllDatastoreFiles

public getAllDatastoreFiles(strVcHostSystemFQDN:string, strVcDataStoreName:string): Propertie {

  let objProperties:Properties = new Properties();
  
  let arrVcSdkConnection:VcSdkConnection[] = VcPlugin.allSdkConnections;
  
  let objVcVmDiskFileQuery:VcVmDiskFileQuery = new VcVmDiskFileQuery();
  let objVcVmSnapshotFileQuery:VcVmSnapshotFileQuery = new VcVmSnapshotFileQuery();
  let objVcVmLogFileQuery:VcVmLogFileQuery = new VcVmLogFileQuery();
  let objVcVmConfigFileQuery:VcVmConfigFileQuery = new VcVmConfigFileQuery();
  let objVcIsoImageFileQuery:VcIsoImageFileQuery = new VcIsoImageFileQuery();
  
  let arrVcFileQuery:VcFileQuery[] = [];
  arrVcFileQuery.push(objVcVmDiskFileQuery);
  arrVcFileQuery.push(objVcVmSnapshotFileQuery);
  arrVcFileQuery.push(objVcVmLogFileQuery);
  arrVcFileQuery.push(objVcVmConfigFileQuery);
  arrVcFileQuery.push(objVcIsoImageFileQuery);
  
  let objVcHostDatastoreBrowserSearchSpec:VcHostDatastoreBrowserSearchSpec = new VcHostDatastoreBrowserSearchSpec();
  objVcHostDatastoreBrowserSearchSpec.query = arrVcFileQuery;		
  
  
  arrVcSdkConnection.forEach((objVcSdkConnection:VcSdkConnection): void => {
  
    let arrVcHostSystem:VcHostSystem[] = objVcSdkConnection.getAllHostSystems()
  
    let objVcHostSystem:VcHostSystem = arrVCHostSystem.find((objVcHostSystem:VcHostSystem): void => {
      return objVCHostSystem.name === strVcHostSystemFQDN;
    });
    
    let arrVcDataStore:VcDataStore[] = objVCHostSystem.datastore;
    
    let objVcDataStore:VcDataStore= arrVcDataStore.find((objVcDataStore:VcDataStore): void => {
      return objVcDataStore.name === strVcDataStoreName;
    });
    
    System.log(`vCenter Data Store Name: ${objVcDataStore.info.name}.`);
  
    let objVcHostDatastoreBrowser:VcHostDatastoreBrowser = objVcDataStore.browser;
  
    let objVcTask:VcTask = objVcHostDatastoreBrowser.searchDatastoreSubFolders_Task("[" + objVcDataStore.name + "]", objVcHostDatastoreBrowserSearchSpec);
  
    let arrVcHostDatastoreBrowserSearchResults:VcHostDatastoreBrowserSearchResults[] = this.WaitForVcTaskEnd(objVcTask, 1);
  
    arrVcHostDatastoreBrowserSearchResults.forEach((objVcHostDatastoreBrowserSearchResults :VcHostDatastoreBrowserSearchResults): void=> {
   
      System.log("vCenter Folder Path: " + objVcHostDatastoreBrowserSearchResults.folderPath);
  
      let arrVcFileInfo:VcFileInfo[] = objVcHostDatastoreBrowserSearchResults.file;
  
      arrVcFileInfo.forEach((objVcFileInfo:VcFileInfo): void => {
      
        objProperties.put(objVcHostDatastoreBrowserSearchResults.folderPath + objVcFileInfo.path, "");
      
      });
        
    });
        
  });

  return objProperties;
}


Discover more from Cloud Build Tools

Subscribe to get the latest posts sent to your email.

You may also like