første xml update
[virt-orchestrator.git] / vFLOWER / content / Actions / com.vmware.library.vc.vm.tools / vim3WaitDnsNameInTools.action.xml
1 <?xml version="1.0" encoding="UTF-8"?>
2 <dunes-script-module name="vim3WaitDnsNameInTools" result-type="void" api-version="3.1.0" id="32dec77f-76bd-438d-b6e4-3ea01296ca0b" version="0.2.0" allowed-operations="fv">
3     <description>
4 Wait for a given name in the DNS guest informations (VMware tools).
5
6 Exception:
7 - Timeout: When timeout is reached
8     </description>
9
10     <param n="vm" t="VC:VirtualMachine">VM in which the action look to get the new DNS Name</param>
11
12     <param n="pollingRate" t="number">Time between all request information on the tools [seconds]</param>
13
14     <param n="dnsNameToWait" t="string">Define a specific DNS name to wait for (either in compute.dunes.ch or compute form)</param>
15
16     <param n="timeout" t="number">Timeout before throwing a timeout exception [minutes]</param>
17
18     <param n="addNumberToName" t="boolean">Specify if the DNS name has an automatically number added at end (not known at clone time)</param>
19
20     <script encoded="false">
21 if (vm == null) throw "ReferenceError: vm is not defined for waiting for the DNS name";
22 if (vm.name == null) throw "ReferenceError: vm is not initialized for waiting for the DNS name";
23
24 timeout = timeout * 60;
25
26 while (true) {
27         if (vm.guest != null) {
28                 if (vm.guest.toolsStatus == VcVirtualMachineToolsStatus.toolsOk || vm.guest.toolsStatus == VcVirtualMachineToolsStatus.toolsOld) {
29                         if (vm.guest.guestState == "running") {
30                                 hostname = vm.guest.hostName;
31                                 if (hostname.indexOf(".") &gt; 0) {
32                                         if (dnsNameToWait.indexOf(".") &gt; 0 &amp;&amp; hostname.toLowerCase() == dnsNameToWait.toLowerCase()) {
33                                                 break;
34                                         }
35                                         if (dnsNameToWait.indexOf(".") &lt; 0) {
36                                                 if (hostname.substring(0, hostname.indexOf(".")).toLowerCase() == dnsNameToWait.toLowerCase()) {
37                                                         break;
38                                                 }
39                                         }
40                                 }
41                                 else {
42                                         if (dnsNameToWait.indexOf(".") &gt; 0 ) {
43                                                 if (dnsNameToWait.substring(0, dnsNameToWait.indexOf(".")).toLowerCase() == hostname.toLowerCase()) {
44                                                         break;
45                                                 }
46                                         }
47                                         if (dnsNameToWait.indexOf(".") &lt; 0 &amp;&amp; hostname.toLowerCase() == dnsNameToWait.toLowerCase()) {
48                                                 break;
49                                         }
50                                 }
51                         }
52                 }
53         }
54         // wait the poolingRate
55         System.sleep(pollingRate * 1000);
56         // test timeout
57         timeout -= pollingRate;
58         if (timeout &lt;= 0) {
59                 throw "Timeout: Unable to get a DNS name for the VM before reaching the Timeout";
60         }
61 }
62
63 System.log("Found name '" + hostname + "' for VM '" + vm.name + "'");
64     </script>
65 </dunes-script-module>