første xml update
[virt-orchestrator.git] / vFLOWER / content / Actions / com.vmware.library.vc.basic / WaitTaskEndOrVMQuestion.action.xml
1 <?xml version="1.0" encoding="UTF-8"?>
2 <dunes-script-module name="WaitTaskEndOrVMQuestion" result-type="Any" api-version="3.1.0" id="a5bffcea-58d8-4b12-b40e-0e3f15dee82d" version="0.1.0" allowed-operations="fv">
3     <description>
4 Wait for a VC Task to end or for the VM to ask a question.
5 Return the task result or the question asked.
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     <param n="vm" t="VC:VirtualMachine"/>
15
16     <script encoded="false">
17 if (task == null) {
18         throw "VC Task is null";
19 }
20 if (vm == null) {
21         throw "VM is null";
22 }
23
24 var taskEnd = false;
25 var error;
26
27 while (task != null) {
28         if (task.info == null) {
29                 throw "VC Task info is null";
30         }
31         if (task.info.state == null) {
32                 throw "VC Task state is null";
33         }       
34
35         var state = task.info.state.value;
36         if (state == "success") {
37                 break;
38         }
39         else if (state == "error") {
40                 if (task.info.error.localizedMessage == null) {
41                         throw "Task '" + task.info.name + "' has encountered an unknown error";
42                 }
43                 else {
44                         throw "Task '" + task.info.name + "' error: "+task.info.error.localizedMessage;
45                 }
46         }
47         else if ((progress) &amp;&amp; (state == "running")) {
48                 if (task.info.progress == null) {
49                         System.log(task.info.name+" Queued or In Progress...");
50                 }
51                 else {
52                         System.log(task.info.name+" "+task.info.progress+" %");
53                 }
54         }
55                 // VM question
56         if (vm &amp;&amp; vm.runtime.question){
57                 System.log("The VM requires an answer to a question");
58                 return vm.runtime.question;
59         }
60         System.sleep(pollRate*1000);
61 }
62
63 if (task == null) {
64         throw "VIM Task is null";
65 }
66 else if (progress) {
67         System.log(task.info.name+" end");
68 }
69
70 // Return the Task Result
71 if (task != null &amp;&amp; task.info != null &amp;&amp; task.info.result != null) {
72         return VcPlugin.convertToVimManagedObject(task , task.info.result);
73 }
74 else {
75         return null;
76 }
77     </script>
78 </dunes-script-module>