første xml update
[virt-orchestrator.git] / vFLOWER / content / Workflows / uio / lib / tools / get_optimal_datastore.workflow.xml
1 <?xml version="1.0" encoding="UTF-8"?>
2 <workflow xmlns="http://vmware.com/vco/workflow" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://vmware.com/vco/workflow http://vmware.com/vco/workflow/Workflow-v4.xsd" root-name="item1" object-name="workflow:name=generic" id="1f459776-8603-4336-ae18-85672d369909" version="1.0.0" api-version="3.1.0" allowed-operations="fve" restartMode="1" resumeFromFailedMode="0">
3     <display-name>get_optimal_datastore</display-name>
4
5     <description>
6 Find datastore with most free disk, and space for the VMs disk
7
8 Input parameter is network object, and GB of required space
9     </description>
10
11     <position x="100.0" y="50.0"/>
12
13     <input>
14         <param name="vmNetwork" type="VC:DistributedVirtualPortgroup"/>
15         <param name="diskspace" type="number"/>
16     </input>
17
18     <output>
19         <param name="datastore1" type="VC:Datastore"/>
20     </output>
21
22     <attrib name="errorCode" type="string" read-only="false">
23         <value encoded="n"/>
24     </attrib>
25     <attrib name="datastores" type="Array/VC:Datastore" read-only="false">
26         <value encoded="n">__NULL__</value>
27     </attrib>
28
29     <workflow-item name="item0" type="end" end-mode="0">
30         <position x="524.5" y="45.40909090909091"/>
31     </workflow-item>
32
33     <workflow-item name="item1" out-name="item0" catch-name="item2" throw-bind-name="errorCode" type="task">
34         <display-name>Scriptable task</display-name>
35
36         <script encoded="false">
37 /*
38         Find the shared datastore with most free space 
39 */
40 //datastores=System.getModule("com.vmware.library.vc.datastore").getAllDatastores();
41 var datastores_old = System.getModule("com.vmware.library.vc.datastore").getValidDatastoreForNetwork(vmNetwork);
42 var bestSize=0;
43 for each (var dc in datastores_old) {
44         dc.refreshDatastore();
45         // dc.refreshDatastoreStorageInfo();
46         
47         if (dc.summary.multipleHostAccess == 0) {
48                 continue;
49         }
50         if (dc.info.freeSpace &gt; bestSize) {
51                 if (dc.info.freeSpace &gt; diskspace*1024*1024*1024) {
52                         datastore=dc;
53                         bestSize=dc.info.freeSpace;
54                 }
55         }
56 }
57
58 if (datastore) {
59         System.log("Allocated diskspace on "+datastore.name);
60 } else {
61         throw "Not able to allocate datastore with "+diskspace+" GB of free space";
62 }
63         </script>
64
65         <in-binding>
66             <bind name="diskspace" type="number" export-name="diskspace"/>
67             <bind name="vmNetwork" type="VC:DistributedVirtualPortgroup" export-name="vmNetwork"/>
68         </in-binding>
69
70         <out-binding>
71             <bind name="datastore" type="VC:Datastore" export-name="datastore1"/>
72             <bind name="datastores" type="Array/VC:Datastore" export-name="datastores"/>
73         </out-binding>
74
75         <position x="344.5" y="55.40909090909091"/>
76     </workflow-item>
77
78     <workflow-item name="item2" out-name="item3" type="link" linked-workflow-id="2cdac1c6-1c4b-4fd4-aa62-a2736a71f7e7">
79         <display-name>error</display-name>
80
81         <in-binding>
82             <bind name="message" type="string" export-name="errorCode"/>
83         </in-binding>
84
85         <out-binding/>
86
87         <description>Looger error melding til email og database</description>
88
89         <position x="344.5" y="119.04545454545453"/>
90     </workflow-item>
91
92     <workflow-item name="item3" throw-bind-name="errorCode" type="end" end-mode="1">
93         <position x="524.5" y="109.04545454545453"/>
94     </workflow-item>
95
96     <presentation>
97         <p-param name="vmNetwork">
98             <desc>vmNetwork</desc>
99         </p-param>
100         <p-param name="diskspace">
101             <desc>diskspace</desc>
102         </p-param>
103     </presentation>
104 </workflow>