første xml update
[virt-orchestrator.git] / vFLOWER / content / Workflows / uio / lib / tools / get_template.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="bb56f2b9-97b8-4c32-829f-b92a9a0fd53e" version="1.0.2" api-version="3.1.0" allowed-operations="fve" restartMode="1" resumeFromFailedMode="0">
3     <display-name>get_template</display-name>
4
5     <description>Search the VM foldes for the correct template for our new VM</description>
6
7     <position x="100.0" y="50.0"/>
8
9     <input>
10         <param name="vmName" type="string"/>
11         <param name="vmHost" type="VC:HostSystem"/>
12         <param name="currState" type="number"/>
13     </input>
14
15     <output>
16         <param name="autoFolder" type="VC:VmFolder"/>
17         <param name="template" type="VC:VirtualMachine"/>
18         <param name="osname" type="string"/>
19     </output>
20
21     <workflow-item name="item0" type="end" end-mode="0">
22         <position x="384.5" y="45.40909090909091"/>
23     </workflow-item>
24
25     <workflow-item name="item1" out-name="item0" type="task">
26         <display-name>Scriptable task</display-name>
27
28         <script encoded="false">
29 var dc;
30 if (vmHost.parent instanceof VcClusterComputeResource) {
31         var cluster=vmHost.parent;
32         if (cluster.parent instanceof VcFolder) {
33                 var dcfolder=cluster.parent;
34                 if (dcfolder.parent instanceof VcDatacenter) {
35                         dc=dcfolder.parent;
36                                 
37                 }
38         } else if (cluster.parent instanceof VcDataCenter) {
39                 dc=cluster.parent;
40         }
41 } else {
42         throw ('['+vmHost.name+'] is not defined in a cluster');
43 }
44
45 var vmFolder=dc.vmFolder;
46
47 /*
48         We need to find our template in the correct datacenter 
49 */
50
51 for each (var folder in vmFolder.childEntity) {
52         
53         if (folder instanceof VcFolder) {
54                 if (folder.name == 'autoprovisioned') {
55                         autoFolder=folder;
56                         for each (var sFolder in autoFolder.childEntity) {
57                                 if (sFolder instanceof VcFolder) {
58                                         if (sFolder.name == 'status') {
59                                                 for each (var state in sFolder.childEntity) {
60                                                         if (state.name == currState.toString()) {
61                                                                 autoFolder=state;
62                                                         }
63                                                 }
64                                         }
65                                 }
66                         }
67                 }
68                 if (folder.name == 'maler') {
69                         var maler = folder;
70                         for each (var mfolder in maler.childEntity) {
71                                 if (mfolder instanceof VcFolder) {
72                                         if (mfolder.name == 'Ovc') {
73                                                 var OvcMaler=mfolder;
74                                                 for each (var vm in OvcMaler.childEntity) {
75                                                         // Look for Ovc ready templates
76                                                         if (vm instanceof VcVirtualMachine) {
77                                                                 if (vm.name == vmName) {
78                                                                         template=vm;
79                                                                         osname=template.summary.guest.guestId;
80                                                                 }
81                                                         }
82                                                 }
83                                         }
84                                 }
85                         }
86                 }
87         }
88 }
89         </script>
90
91         <in-binding>
92             <bind name="vmHost" type="VC:HostSystem" export-name="vmHost"/>
93             <bind name="vmName" type="string" export-name="vmName"/>
94             <bind name="currState" type="number" export-name="currState"/>
95         </in-binding>
96
97         <out-binding>
98             <bind name="template" type="VC:VirtualMachine" export-name="template"/>
99             <bind name="autoFolder" type="VC:VmFolder" export-name="autoFolder"/>
100             <bind name="osname" type="string" export-name="osname"/>
101         </out-binding>
102
103         <position x="204.5" y="55.40909090909091"/>
104     </workflow-item>
105
106     <presentation>
107         <p-param name="vmName">
108             <desc>vmName</desc>
109         </p-param>
110         <p-param name="vmHost">
111             <desc>vmHost</desc>
112         </p-param>
113         <p-param name="currState">
114             <desc>currState</desc>
115         </p-param>
116     </presentation>
117 </workflow>