første xml update
[virt-orchestrator.git] / vFLOWER / content / Actions / com.vmware.library.vc.datastore / getAllDatastoreOnVimHost.action.xml
1 <?xml version="1.0" encoding="UTF-8"?>
2 <dunes-script-module name="getAllDatastoreOnVimHost" result-type="Array/VC:Datastore" api-version="3.1.0" id="c968b77a-b583-4a43-bcbc-4452e5a84b8f" version="0.3.0" allowed-operations="fv">
3     <description>Return all datastores on an ESX host</description>
4
5     <param n="vimHost" t="VC:SdkConnection"/>
6
7     <script encoded="false">
8 var keys = new Properties();
9 var result = new Array();
10 try {
11         searchInFolder(vimHost.rootFolder);
12         //System.log(result.length + " datastores found");
13         return result;
14 }
15 catch (ex) {
16         if (vimHost != null)
17                 throw "Error getting datastore on " + vimHost.name + ". " + ex;
18         else
19                 throw "Error getting datastore on null vimHost. " + ex;
20 }
21
22
23
24 function searchInFolder(folder) {
25         //System.log("searchInFolder(" + folder.name + ")");
26         if (folder.datacenter != null) {
27                 var childs = folder.childEntity;
28                 for (var i in childs) {
29                         if (childs[i] instanceof VcFolder) {
30                                 System.log("a folder: " + childs[i].name);
31                                 searchInFolder(childs[i]);
32                         }
33                         if (childs[i] instanceof VcDatacenter) {
34                                 System.log("a datacenter: " + childs[i].name);
35                                 addDatastore(childs[i]);
36                         }
37                 }
38         }       
39 }
40
41 function addDatastore(datacenter) {
42         var allDS = datacenter.datastore;
43         for (var i in allDS) {
44                 if (keys.get(allDS[i].sdkId) == null) { 
45                         System.log(allDS[i].name + " found!");
46                         result.push(allDS[i]);
47                         keys.put(allDS[i].sdkId, allDS[i].sdkId);
48                 }
49         }
50 }
51     </script>
52 </dunes-script-module>