første xml update
[virt-orchestrator.git] / vFLOWER / content / Workflows / uio / lib / log / set_db_state.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="item5" object-name="workflow:name=generic" id="fac19258-528f-4e75-a341-6242a16246b6" version="1.0.6" api-version="3.1.0" allowed-operations="fve" restartMode="1" resumeFromFailedMode="0">
3     <display-name>set_db_state</display-name>
4
5     <description>
6 Set a new state for VM in database, and move VM to folder with same state. 
7
8 We are using status codes, as this is not somthing which should be hidden from the user. 
9
10 Current status codes can be listed inside the database: select * from status;
11
12 │   1  │ Request for ny virt server         
13 │   2  │ Godkjent                           
14 │   3  │ Kickstart                          
15 │   4  │ Tilgjengelig                      
16 │  13 │ error                             
17 │   5  │ Bulk                               
18 │  10 │ booting                            
19 │  20 │ manuell                           
20 │ 999│ slettet                            
21 │ 998│ Initial registration            
22 │ 996│ Finnes i BOFH, svarer ikke på ping 
23 │ 997│ Cluster type må verifiseres
24     </description>
25
26     <position x="85.0" y="127.72727272727272"/>
27
28     <input>
29         <param name="vm" type="string">
30             <description>Navn på vm som skal ha oppdatert status</description>
31         </param>
32         <param name="status" type="number">
33             <description>VM status. Default 4 or 999 for deleted</description>
34         </param>
35         <param name="message" type="string">
36             <description>Message to log to info or error</description>
37         </param>
38         <param name="virtualMachine" type="VC:VirtualMachine"/>
39         <param name="project_folder" type="string">
40             <description>VM is moved to the project folder when its confirmed ok</description>
41         </param>
42         <param name="datacenter" type="VC:Datacenter"/>
43     </input>
44
45     <attrib name="errorCode" type="string" read-only="false">
46         <value encoded="n"/>
47     </attrib>
48     <attrib name="mailto" type="string" read-only="false">
49         <value encoded="n"/>
50         <description>Default mailto parameter</description>
51     </attrib>
52     <attrib name="smtp_server" type="string" read-only="false">
53         <value encoded="n"/>
54         <description>Default SMTP server</description>
55     </attrib>
56     <attrib name="smtp_port" type="string" read-only="false">
57         <value encoded="n"/>
58         <description>Default SMTP port</description>
59     </attrib>
60     <attrib name="database" type="SQL:Database" read-only="false">
61         <value encoded="n">__NULL__</value>
62         <description>Default database</description>
63     </attrib>
64     <attrib name="message_out" type="string" read-only="false">
65         <value encoded="n"/>
66     </attrib>
67     <attrib name="vmPassword" type="SecureString" read-only="false">
68         <value encoded="n"/>
69     </attrib>
70     <attrib name="projects" type="string" read-only="false">
71         <value encoded="n">autoprovisoned</value>
72     </attrib>
73
74     <workflow-item name="item0" type="end" end-mode="0">
75         <position x="1064.5" y="181.77272727272725"/>
76     </workflow-item>
77
78     <workflow-item name="item1" out-name="item0" 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="message_out"/>
83         </in-binding>
84
85         <out-binding/>
86
87         <description>Looger error melding til email og database</description>
88
89         <position x="1024.5" y="137.22727272727272"/>
90     </workflow-item>
91
92     <workflow-item name="item4" out-name="item3" type="custom-condition" alt-out-name="item1">
93         <display-name>Custom decision</display-name>
94
95         <script encoded="false">
96 if (status == 13){
97         return false;
98 }else{
99         return true;
100 }
101         </script>
102
103         <in-binding>
104             <bind name="status" type="number" export-name="status"/>
105         </in-binding>
106
107         <position x="744.5" y="127.22727272727272"/>
108     </workflow-item>
109
110     <workflow-item name="item3" out-name="item0" throw-bind-name="errorCode" type="link" linked-workflow-id="25832524-da3e-407e-a64a-d4418bcb3174">
111         <display-name>info</display-name>
112
113         <in-binding>
114             <bind name="message" type="string" export-name="message_out"/>
115         </in-binding>
116
117         <out-binding/>
118
119         <description>Logger hendelser som skjer til databasen. Også mulig å logge til email dersom variablen enable_mail settes til true</description>
120
121         <position x="744.5" y="191.77272727272725"/>
122     </workflow-item>
123
124     <workflow-item name="item2" out-name="item7" type="task">
125         <display-name>Scriptable task</display-name>
126
127         <script encoded="false">
128 var query = "update server set "
129         +"status = "+status
130         +" where name = '" + vm + "';";
131
132
133 /*
134  * Execute insert or update into database
135  */
136 if (database) {
137         System.log("Updating DATABASE :"+query);
138         var rowsAffected = database.executeCustomQuery(query);
139 }
140 message_out="[ "+vm+" ] "+message;
141         </script>
142
143         <in-binding>
144             <bind name="database" type="SQL:Database" export-name="database">
145                 <description>Default database</description>
146             </bind>
147             <bind name="message" type="string" export-name="message">
148                 <description>Message to log to info or error</description>
149             </bind>
150             <bind name="status" type="number" export-name="status">
151                 <description>VM status. Default 4 or 999 for deleted</description>
152             </bind>
153             <bind name="vm" type="string" export-name="vm">
154                 <description>Navn på vm som skal ha oppdatert status</description>
155             </bind>
156         </in-binding>
157
158         <out-binding>
159             <bind name="message_out" type="string" export-name="message_out"/>
160         </out-binding>
161
162         <position x="324.5" y="137.22727272727272"/>
163     </workflow-item>
164
165     <workflow-item name="item5" out-name="item2" type="link" linked-workflow-id="1f0fc470-006c-4c15-a3b9-95e2e7540f22">
166         <display-name>global_parameters</display-name>
167
168         <in-binding/>
169
170         <out-binding>
171             <bind name="mailto" type="string" export-name="mailto"/>
172             <bind name="smtp_server" type="string" export-name="smtp_server"/>
173             <bind name="smtp_port" type="string" export-name="smtp_port"/>
174             <bind name="database" type="SQL:Database" export-name="database"/>
175             <bind name="vmPassword" type="SecureString" export-name="vmPassword"/>
176         </out-binding>
177
178         <position x="184.5" y="137.22727272727272"/>
179     </workflow-item>
180
181     <workflow-item name="item7" out-name="item9" type="custom-condition" alt-out-name="item4">
182         <display-name>Custom decision</display-name>
183
184         <script encoded="false">
185 if (virtualMachine) {
186         return true;
187 } else {
188         return false;
189 }
190         </script>
191
192         <in-binding>
193             <bind name="virtualMachine" type="VC:VirtualMachine" export-name="virtualMachine"/>
194         </in-binding>
195
196         <position x="464.5" y="127.22727272727272"/>
197     </workflow-item>
198
199     <workflow-item name="item9" out-name="item4" type="task">
200         <display-name>Scriptable task</display-name>
201
202         <script encoded="false">
203 var vms = new Array();
204 vms.push(virtualMachine);
205 var state ;
206
207 // Find root folder in current VIM
208 var folder = datacenter.vmFolder;
209
210 function getFolder (myfolder, folderName){
211         if (myfolder instanceof VcFolder) {     
212                 for each (var s in myfolder.childEntity) {
213                         if (s.name == folderName) {
214                                 return s;
215                         }
216                 }
217         }
218 }
219
220 // Find /autoprovisioned
221 var autoFolder=getFolder(folder, 'autoprovisioned');
222 if (!autoFolder) {
223         autoFolder=folder.createFolder('autoprovisioned');
224 }
225
226 // Find /autoprovisioned/status
227 var statusFolder=getFolder(autoFolder, 'status');
228 if (!statusFolder) {
229         statusFolder=autoFolder.createFolder('status');
230 }
231
232 // Find /autoprovisioned/status/$state
233 if (status != 4) {
234         var stateFolder=getFolder(statusFolder, status);
235         if (!stateFolder) {
236                 stateFolder=statusFolder.createFolder(status);
237         }
238         state=stateFolder;
239 }
240
241 // Store new VM in project folder
242 if (status == 4) {
243         if (database) { // We are in UiO, use autoprovisioned/groups
244                 var groups=getFolder(autoFolder, 'incoming-groups');
245                 if (!groups) {
246                         groups = autoFolder.createFolder('incoming-groups');
247                 }
248                 if (! project_folder) {
249                         project_folder='unsorted';
250                 }
251                 var proj_name=project_folder.split("@",1).toString();
252                 
253                 System.log (proj_name);
254                 var proj=getFolder(groups, proj_name);
255                 if (!proj) {
256                         System.log("Dette er merksnodig");
257                         try {
258                                 proj = groups.createFolder(proj_name);
259                         }
260                         catch (err) {
261                         }       
262                 }
263                 
264         } else {
265                 var projects=getFolder(folder, 'projects');
266                 if (!projects) {
267                         projects = folder.createFolder('projects');
268                 }
269                 if (! project_folder) {
270                         project_folder='p00-unsorted';
271                 }
272                 var proj=getFolder(groups,project_folder);
273                 if (!proj) {
274                         proj = projects.createFolder(project_folder);
275                 }
276                 
277         }
278         state=proj;
279 }
280
281
282
283 var task = state.moveIntoFolder_Task(vms);
284         </script>
285
286         <in-binding>
287             <bind name="status" type="number" export-name="status">
288                 <description>VM status. Default 4 or 999 for deleted</description>
289             </bind>
290             <bind name="virtualMachine" type="VC:VirtualMachine" export-name="virtualMachine"/>
291             <bind name="project_folder" type="string" export-name="project_folder">
292                 <description>VM is moved to the project folder when its confirmed ok</description>
293             </bind>
294             <bind name="datacenter" type="VC:Datacenter" export-name="datacenter"/>
295             <bind name="projects" type="string" export-name="projects"/>
296             <bind name="database" type="SQL:Database" export-name="database">
297                 <description>Default database</description>
298             </bind>
299         </in-binding>
300
301         <out-binding/>
302
303         <position x="584.5" y="91.77272727272727"/>
304     </workflow-item>
305
306     <presentation>
307         <p-param name="vm">
308             <desc>Gammelt navn (Kun i bruk dersom kjørt via annen workflow)</desc>
309         </p-param>
310         <p-param name="status">
311             <desc>VM status. Default 4 or 999 for deleted</desc>
312         </p-param>
313         <p-param name="message">
314             <desc>Message to log to info or error</desc>
315         </p-param>
316         <p-param name="virtualMachine">
317             <desc>virtualMachine</desc>
318         </p-param>
319         <p-param name="project_folder">
320             <desc>VM is moved to the project folder when its confirmed ok</desc>
321         </p-param>
322         <p-param name="datacenter">
323             <desc>datacenter</desc>
324         </p-param>
325     </presentation>
326 </workflow>