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

publicgetAllDatastoreFiles(strVcHostSystemFQDN:string,strVcDataStoreName:string):Propertie{

letobjProperties:Properties=newProperties();

letarrVcSdkConnection:VcSdkConnection[]=VcPlugin.allSdkConnections;

letobjVcVmDiskFileQuery:VcVmDiskFileQuery=newVcVmDiskFileQuery();
letobjVcVmSnapshotFileQuery:VcVmSnapshotFileQuery=newVcVmSnapshotFileQuery();
letobjVcVmLogFileQuery:VcVmLogFileQuery=newVcVmLogFileQuery();
letobjVcVmConfigFileQuery:VcVmConfigFileQuery=newVcVmConfigFileQuery();
letobjVcIsoImageFileQuery:VcIsoImageFileQuery=newVcIsoImageFileQuery();

letarrVcFileQuery:VcFileQuery[]= [];
arrVcFileQuery.push(objVcVmDiskFileQuery);
arrVcFileQuery.push(objVcVmSnapshotFileQuery);
arrVcFileQuery.push(objVcVmLogFileQuery);
arrVcFileQuery.push(objVcVmConfigFileQuery);
arrVcFileQuery.push(objVcIsoImageFileQuery);

letobjVcHostDatastoreBrowserSearchSpec:VcHostDatastoreBrowserSearchSpec=newVcHostDatastoreBrowserSearchSpec();
objVcHostDatastoreBrowserSearchSpec.query=arrVcFileQuery;


arrVcSdkConnection.forEach((objVcSdkConnection:VcSdkConnection):void=>{

letarrVcHostSystem:VcHostSystem[]=objVcSdkConnection.getAllHostSystems()

letobjVcHostSystem:VcHostSystem=arrVCHostSystem.find((objVcHostSystem:VcHostSystem):void=>{
returnobjVCHostSystem.name===strVcHostSystemFQDN;
});

letarrVcDataStore:VcDataStore[]=objVCHostSystem.datastore;

letobjVcDataStore:VcDataStore=arrVcDataStore.find((objVcDataStore:VcDataStore):void=>{
returnobjVcDataStore.name===strVcDataStoreName;
});

System.log(`vCenter Data Store Name:${objVcDataStore.info.name}.`);

letobjVcHostDatastoreBrowser:VcHostDatastoreBrowser=objVcDataStore.browser;

letobjVcTask:VcTask=objVcHostDatastoreBrowser.searchDatastoreSubFolders_Task("["+objVcDataStore.name+"]",objVcHostDatastoreBrowserSearchSpec);

letarrVcHostDatastoreBrowserSearchResults:VcHostDatastoreBrowserSearchResults[]=this.WaitForVcTaskEnd(objVcTask,1);

arrVcHostDatastoreBrowserSearchResults.forEach((objVcHostDatastoreBrowserSearchResults:VcHostDatastoreBrowserSearchResults):void=>{

System.log("vCenter Folder Path:"+objVcHostDatastoreBrowserSearchResults.folderPath);

letarrVcFileInfo:VcFileInfo[]=objVcHostDatastoreBrowserSearchResults.file;

arrVcFileInfo.forEach((objVcFileInfo:VcFileInfo):void=>{

objProperties.put(objVcHostDatastoreBrowserSearchResults.folderPath+objVcFileInfo.path,"");

});

});

});

returnobjProperties;
}


Discover more from Cloud Build Tools

Subscribe to get the latest posts sent to your email.

You may also like