første xml update
[virt-orchestrator.git] / vFLOWER / content / Actions / com.vmware.library.vc.basic / vim3WaitTaskEnd.action.xml
1 <?xml version="1.0" encoding="UTF-8"?>
2 <dunes-script-module name="vim3WaitTaskEnd" result-type="Any" api-version="3.1.0" id="83cc409d-547b-4c8c-9ba4-29c886b1b3ba" version="0.3.0" allowed-operations="fv">
3     <description>
4 Wait for a VC Task to end.
5 When task ended, return the task result if any.
6     </description>
7
8     <param n="task" t="VC:Task">Task to Wait for</param>
9
10     <param n="progress" t="boolean">Log progess while waiting for the task</param>
11
12     <param n="pollRate" t="number">Polling rate for the task state [seconds]</param>
13
14     <script encoded="false">
15 var taskEnd = false;
16 var error;
17
18 while (task != null) {
19         if (task.info == null) {
20                 throw "VIM Task info is null";
21         }
22         if (task.info.state == null) {
23                 throw "VIM Task state is null";
24         }       
25
26         var state = task.info.state.value;
27         if (state == "success") {
28                 break;
29         }
30         else if (state == "error") {
31                 if (task.info.error.localizedMessage == null) {
32                         throw "Task '" + task.info.name + "' has encountered an unknown error";
33                 }
34                 else {
35                         throw "Task '" + task.info.name + "' error: "+task.info.error.localizedMessage;
36                 }
37         }
38         else if ((progress) &amp;&amp; (state == "running")) {
39                 if (task.info.progress == null) {
40                         System.log(task.info.name+" Queued or In Progress...");
41                         }
42                 else {
43                         System.log(task.info.name+" "+task.info.progress+" %");
44                 }
45         }
46         System.sleep(pollRate*1000);
47 }
48
49 if (task == null) {
50         throw "VIM Task is null";
51 }
52 else if (progress) {
53         System.log(task.info.name+" end");
54 }
55
56 // Return the Task Result
57 if (task != null &amp;&amp; task.info != null &amp;&amp; task.info.result != null) {
58         return VcPlugin.convertToVimManagedObject(task , task.info.result);
59 }
60 else {
61         return null;
62 }
63     </script>
64 </dunes-script-module>