]> git.uio.no Git - virt-orchestrator.git/blob - vFLOWER/content/Workflows/uio/VirtProv/ clone VM from DB 1000101010 linux 2.0.workflow.xml
første xml update
[virt-orchestrator.git] / vFLOWER / content / Workflows / uio / VirtProv / clone VM from DB 1000101010 linux 2.0.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="item7" object-name="Workflow:name=generic" id="13f152b9-bdfe-43ca-9399-47e61cb74022" version="2.0.22" api-version="3.1.0" allowed-operations="fve" restartMode="1" resumeFromFailedMode="0">
3     <display-name>clone VM from DB + linux 2.0</display-name>
4
5     <description>
6 This workflow is suposed to be scheduled to run every 5 minutes. It will look for new requests where provisioning type is defined as clone. (!= pxe).
7
8 As its possible to run more than one instance of this workflow, we will look for the first row with a distincts search. When the flow returns from builing an vm it will look in the db for aditional requests. If none exists it will terminate.
9
10
11 Look for DB entries with status = 5.
12 - Crate new VM
13 - Add inn BOFH
14 - Boot VM
15 - and more
16     </description>
17
18     <position x="25.0" y="209.04545454545453"/>
19
20     <attrib name="allVMs" type="Array/SQL:ActiveRecord" read-only="false">
21         <value encoded="n">__NULL__</value>
22         <description>Array of virtual machines</description>
23     </attrib>
24     <attrib name="vmCount" type="number" read-only="false">
25         <value encoded="n">0</value>
26         <description>Number of virtual machines in the resource pool</description>
27     </attrib>
28     <attrib name="currentVM" type="number" read-only="false">
29         <value encoded="n">0</value>
30         <description>Index of the virtual machine in the array of virtual machines</description>
31     </attrib>
32     <attrib name="activeVM" type="string" read-only="false">
33         <value encoded="n"/>
34         <description>Virtual machine currently being processed</description>
35     </attrib>
36     <attrib name="errorCode" type="string" read-only="false">
37         <value encoded="n"/>
38         <description>Error code</description>
39     </attrib>
40     <attrib name="status" type="number" read-only="false">
41         <value encoded="n">5.0</value>
42         <description>Status in database. Staus 5 = bulk</description>
43     </attrib>
44     <attrib name="vmGuestOs" type="VC:VirtualMachineGuestOsIdentifier" read-only="false">
45         <value encoded="n">__NULL__</value>
46         <description>Guest operating system to use with the virtual machine</description>
47     </attrib>
48     <attrib name="vmFolder" type="VC:VmFolder" read-only="false">
49         <value encoded="n">dunes://service.dunes.ch/CustomSDKObject?id='vcsa-test01.uio.no/group-v22'&amp;dunesName='VC:VmFolder'</value>
50         <description>Virtual machine folder</description>
51     </attrib>
52     <attrib name="vmResourcePool" type="VC:ResourcePool" read-only="false">
53         <value encoded="n">__NULL__</value>
54         <description>Resource pool in which to create the virtual machine</description>
55     </attrib>
56     <attrib name="vmHost" type="VC:HostSystem" read-only="false">
57         <value encoded="n">__NULL__</value>
58         <description>Host on which to create the virtual machine</description>
59     </attrib>
60     <attrib name="vmDiskSize" type="number" read-only="false">
61         <value encoded="n">60.0</value>
62         <description>Size of virtual disk in GB</description>
63     </attrib>
64     <attrib name="vmMemorySize" type="number" read-only="false">
65         <value encoded="n">4096.0</value>
66         <description>Virtual machine's memory size in MB</description>
67     </attrib>
68     <attrib name="vmNbOfCpus" type="number" read-only="false">
69         <value encoded="n">1.0</value>
70         <description>Number of virtual processors</description>
71     </attrib>
72     <attrib name="vmNetwork" type="VC:DistributedVirtualPortgroup" read-only="false">
73         <value encoded="n">dunes://service.dunes.ch/CustomSDKObject?id='vcsa-test01.uio.no/dvportgroup-37'&amp;dunesName='VC:DistributedVirtualPortgroup'</value>
74         <description>The network to connect to</description>
75     </attrib>
76     <attrib name="kort_beskrivelse" type="string" read-only="false">
77         <value encoded="n"/>
78         <description>Kort beskrivelse av ny VM</description>
79     </attrib>
80     <attrib name="epostliste" type="string" read-only="false">
81         <value encoded="n"/>
82         <description>Mail alias for ny VM</description>
83     </attrib>
84     <attrib name="database" type="SQL:Database" read-only="false">
85         <value encoded="n">__NULL__</value>
86         <description>Pointer to database</description>
87     </attrib>
88     <attrib name="mailto1" type="string" read-only="false">
89         <value encoded="n"/>
90         <description>Default mailto parameter</description>
91     </attrib>
92     <attrib name="smtp_server1" type="string" read-only="false">
93         <value encoded="n"/>
94         <description>Default SMTP server</description>
95     </attrib>
96     <attrib name="smtp_port1" type="string" read-only="false">
97         <value encoded="n"/>
98         <description>Default SMTP port</description>
99     </attrib>
100     <attrib name="viktighet" type="number" read-only="false">
101         <value encoded="n">__NULL__</value>
102         <description>Resource group to add VM into</description>
103     </attrib>
104     <attrib name="folder" type="string" read-only="false">
105         <value encoded="n"/>
106         <description>Folder to store the new VM</description>
107     </attrib>
108     <attrib name="VIM" type="VC:SdkConnection" read-only="false">
109         <value encoded="n">dunes://service.dunes.ch/CustomSDKObject?id='vcsa-test01.uio.no'&amp;dunesName='VC:SdkConnection'</value>
110         <description>Pointer to Vcenter object</description>
111     </attrib>
112     <attrib name="template" type="VC:VirtualMachine" read-only="false">
113         <value encoded="n">dunes://service.dunes.ch/CustomSDKObject?id='vcsa-test01.uio.no/vm-125'&amp;dunesName='VC:VirtualMachine'</value>
114         <description>Virtual machine to clone</description>
115     </attrib>
116     <attrib name="datastore" type="VC:Datastore" read-only="false">
117         <value encoded="n">__NULL__</value>
118         <description>Datastore in which to store the virtual machine. If not specified, the current datastore is used</description>
119     </attrib>
120     <attrib name="dnsServerList" type="Array/string" read-only="false">
121         <value encoded="n">#{#string#129.240.2.27#;#string#129.240.2.40#;#string#129.240.2.3#}#</value>
122         <description>(Optional) List of DNS servers for a virtual network adapter with a static IP address</description>
123     </attrib>
124     <attrib name="dnsDomain" type="string" read-only="false">
125         <value encoded="n">uio.no</value>
126         <description>(Optional) DNS domain suffix such as vmware.com</description>
127     </attrib>
128     <attrib name="gateway" type="Array/string" read-only="false">
129         <value encoded="n">#{#string#129.240.255.193#}#</value>
130         <description>(Optional) List of gateways, in order of preference</description>
131     </attrib>
132     <attrib name="ipAddress" type="string" read-only="false">
133         <value encoded="n">129.240.255.215</value>
134         <description>Fixed valid IP address</description>
135     </attrib>
136     <attrib name="subnetMask" type="string" read-only="false">
137         <value encoded="n">255.255.255.224</value>
138         <description>(Optional) Subnet mask for this virtual network adapter</description>
139     </attrib>
140     <attrib name="fullName" type="string" read-only="false">
141         <value encoded="n">Universitetet i Oslo</value>
142         <description>User's full name</description>
143     </attrib>
144     <attrib name="orgName" type="string" read-only="false">
145         <value encoded="n">UiO</value>
146         <description>Organization name</description>
147     </attrib>
148     <attrib name="computerName" type="string" read-only="false">
149         <value encoded="n"/>
150         <description>Name of the new VM</description>
151     </attrib>
152     <attrib name="macAddress" type="string" read-only="false">
153         <value encoded="n">false</value>
154         <description>Dersom undef, så defineres ikke macAddress</description>
155     </attrib>
156     <attrib name="osname" type="string" read-only="false">
157         <value encoded="n"/>
158         <description>Navn på OS</description>
159     </attrib>
160     <attrib name="environment" type="Array/string" read-only="false">
161         <value encoded="n">__NULL__</value>
162         <description>An array of environment variables, specified in the guest OS notation (eg PATH=c:\bin;c:\windows\system32 or LD_LIBRARY_PATH=/usr/lib:/lib), to be set for the program being run. Note that these are not additions to the default environment variables; they define the complete set available to the program. If none are specified the values are guest dependent.</description>
163     </attrib>
164     <attrib name="windows_roles" type="Array/string" read-only="false">
165         <value encoded="n">__NULL__</value>
166         <description>Windows roles. Other workflow fetches roles from database</description>
167     </attrib>
168     <attrib name="vlan_name" type="string" read-only="false">
169         <value encoded="n"/>
170         <description>Vlan descriptive name</description>
171     </attrib>
172     <attrib name="ad_domain_id" type="number" read-only="false">
173         <value encoded="n">__NULL__</value>
174         <description>Ad omain id from database. If &gt; 0 add vm in AD</description>
175     </attrib>
176     <attrib name="ad_domain_name" type="string" read-only="false">
177         <value encoded="n"/>
178         <description>Ad domain to join</description>
179     </attrib>
180     <attrib name="vlan_id" type="number" read-only="false">
181         <value encoded="n">__NULL__</value>
182         <description>vlanid</description>
183     </attrib>
184     <attrib name="cluster" type="string" read-only="false">
185         <value encoded="n"/>
186     </attrib>
187     <attrib name="errorStatus" type="number" read-only="false">
188         <value encoded="n">13.0</value>
189         <description>VM status. Default 4 or 999 for deleted</description>
190     </attrib>
191     <attrib name="newVM" type="VC:VirtualMachine" read-only="false">
192         <value encoded="n">__NULL__</value>
193         <description>The newly created virtual machine</description>
194     </attrib>
195     <attrib name="datacenter" type="string" read-only="false">
196         <value encoded="n"/>
197     </attrib>
198     <attrib name="os_full_name" type="string" read-only="false">
199         <value encoded="n"/>
200     </attrib>
201     <attrib name="status_start_cloning" type="number" read-only="false">
202         <value encoded="n">10.0</value>
203         <description>VM status. Default 4 or 999 for deleted</description>
204     </attrib>
205     <attrib name="message_start_cloning" type="string" read-only="false">
206         <value encoded="n">Starting to clone VM</value>
207         <description>Message to log to info or error</description>
208     </attrib>
209     <attrib name="template_name" type="string" read-only="false">
210         <value encoded="n"/>
211     </attrib>
212     <attrib name="status_finished" type="number" read-only="false">
213         <value encoded="n">4.0</value>
214         <description>VM status. Default 4 or 999 for deleted</description>
215     </attrib>
216     <attrib name="vmPassword" type="SecureString" read-only="false">
217         <value encoded="n">12AE4ED65E7787216FD6F074931532633734F3534A85DE3EBD93C7671CDC2A140DF056C8810B8C79FD2C985F605987495D9</value>
218     </attrib>
219     <attrib name="powerOn" type="boolean" read-only="false">
220         <value encoded="n">true</value>
221         <description>Specifies whether or not the new virtual machine should be powered on after creation</description>
222     </attrib>
223     <attrib name="doSysprep" type="boolean" read-only="false">
224         <value encoded="n">true</value>
225         <description>Run the Sysprep operations and wait for the task to complete. Not used if the virtual machine is marked as template</description>
226     </attrib>
227     <attrib name="dhcp" type="boolean" read-only="false">
228         <value encoded="n">false</value>
229         <description>Use a DHCP server to configure the virtual network adapter</description>
230     </attrib>
231     <attrib name="macAddress1" type="string" read-only="false">
232         <value encoded="n"/>
233         <description>(Optional) The MAC address of a network adapter being customized. If it is not included, the customization process maps the settings from the virtual machine's network adapters, in PCI slot order</description>
234     </attrib>
235     <attrib name="diskIndex" type="number" read-only="false">
236         <value encoded="n">1.0</value>
237         <description>Disk index</description>
238     </attrib>
239     <attrib name="diskMode" type="VC:VirtualDiskMode" read-only="false">
240         <value encoded="n">dunes://service.dunes.ch/CustomSDKObject?id='persistent'&amp;dunesName='VC:VirtualDiskMode'</value>
241         <description>Disk persistence mode</description>
242     </attrib>
243     <attrib name="scsiBusNumber" type="number" read-only="false">
244         <value encoded="n">0.0</value>
245         <description>SCSI controller bus number</description>
246     </attrib>
247     <attrib name="thinProvisioned" type="boolean" read-only="false">
248         <value encoded="n">false</value>
249         <description>Use thin provisioning?</description>
250     </attrib>
251     <attrib name="allocate_disk_space" type="number" read-only="false">
252         <value encoded="n">__NULL__</value>
253         <description>Size of virtual disk in GB</description>
254     </attrib>
255     <attrib name="linux_roles" type="Array/string" read-only="false">
256         <value encoded="n">__NULL__</value>
257     </attrib>
258     <attrib name="project_folder" type="string" read-only="false">
259         <value encoded="n"/>
260     </attrib>
261     <attrib name="ipv6gateway" type="string" read-only="false">
262         <value encoded="n"/>
263     </attrib>
264     <attrib name="ipv6dnsServerList" type="Array/string" read-only="false">
265         <value encoded="n">__NULL__</value>
266     </attrib>
267     <attrib name="ipv6address" type="string" read-only="false">
268         <value encoded="n"/>
269     </attrib>
270     <attrib name="ipv6Prefixlen" type="number" read-only="false">
271         <value encoded="n">__NULL__</value>
272     </attrib>
273     <attrib name="vimCL" type="VC:ClusterComputeResource" read-only="false">
274         <value encoded="n">__NULL__</value>
275     </attrib>
276     <attrib name="vimDC" type="VC:Datacenter" read-only="false">
277         <value encoded="n">__NULL__</value>
278     </attrib>
279     <attrib name="vm" type="SQL:ActiveRecord" read-only="false">
280         <value encoded="n">__NULL__</value>
281     </attrib>
282     <attrib name="vmProperties" type="Properties" read-only="false">
283         <value encoded="n">__NULL__</value>
284     </attrib>
285     <attrib name="pxe" type="boolean" read-only="false">
286         <value encoded="n">false</value>
287     </attrib>
288     <attrib name="test" type="Array/string" read-only="false">
289         <value encoded="n">__NULL__</value>
290     </attrib>
291
292     <workflow-item name="item0" out-name="item1" type="task">
293         <display-name>Initialize</display-name>
294
295         <script encoded="false">
296 System.log('select * from server_view where statusid = 5;');
297 allVMs = database.readCustomQuery('select distinct on (status) * from server_view where statusid = 5;');
298
299
300 vmCount = allVMs.length;
301 currentVM = 0;
302         </script>
303
304         <in-binding>
305             <bind name="database" type="SQL:Database" export-name="database"/>
306             <bind name="status" type="number" export-name="status">
307                 <description>Status in database. Staus 5 = bulk</description>
308             </bind>
309             <bind name="VIM" type="VC:SdkConnection" export-name="VIM"/>
310         </in-binding>
311
312         <out-binding>
313             <bind name="vmCount" type="number" export-name="vmCount"/>
314             <bind name="currentVM" type="number" export-name="currentVM"/>
315             <bind name="allVMs" type="Array/SQL:ActiveRecord" export-name="allVMs">
316                 <description>Array of virtual machines</description>
317             </bind>
318             <bind name="newVM" type="VC:VirtualMachine" export-name="newVM">
319                 <description>The newly created virtual machine</description>
320             </bind>
321             <bind name="vlan_id" type="number" export-name="vlan_id">
322                 <description>vlanid</description>
323             </bind>
324             <bind name="template" type="VC:VirtualMachine" export-name="template">
325                 <description>Virtual machine to clone</description>
326             </bind>
327             <bind name="cluster" type="string" export-name="cluster"/>
328             <bind name="ad_domain_name" type="string" export-name="ad_domain_name">
329                 <description>Ad domain to join</description>
330             </bind>
331             <bind name="datacenter" type="string" export-name="datacenter"/>
332             <bind name="vlan_name" type="string" export-name="vlan_name">
333                 <description>Vlan descriptive name</description>
334             </bind>
335             <bind name="ad_domain_id" type="number" export-name="ad_domain_id">
336                 <description>Ad omain id from database. If &gt; 0 add vm in AD</description>
337             </bind>
338             <bind name="vmNetwork" type="VC:DistributedVirtualPortgroup" export-name="vmNetwork">
339                 <description>The network to connect to</description>
340             </bind>
341             <bind name="status" type="number" export-name="status">
342                 <description>Status in database. Staus 5 = bulk</description>
343             </bind>
344         </out-binding>
345
346         <position x="124.5" y="155.4090909090909"/>
347     </workflow-item>
348
349     <workflow-item name="item1" out-name="item17" type="custom-condition" alt-out-name="item2">
350         <display-name>VMs to Process?</display-name>
351
352         <script encoded="false">
353 if(allVMs.length &gt; 0){
354         return true;
355 }else{
356         return false;
357 }
358         </script>
359
360         <in-binding>
361             <bind name="allVMs" type="Array/SQL:ActiveRecord" export-name="allVMs"/>
362         </in-binding>
363
364         <position x="124.5" y="318.1363636363636"/>
365     </workflow-item>
366
367     <workflow-item name="item2" out-name="item3" type="task">
368         <display-name>Scriptable task</display-name>
369
370         <script encoded="false">
371 System.log("No VM's to process at the moment");
372         </script>
373
374         <in-binding/>
375
376         <out-binding/>
377
378         <position x="124.5" y="400.8636363636363"/>
379     </workflow-item>
380
381     <workflow-item name="item3" type="end" end-mode="0">
382         <position x="164.5" y="454.49999999999994"/>
383     </workflow-item>
384
385     <workflow-item name="item6" out-name="item5" catch-name="item10" throw-bind-name="errorCode" type="task">
386         <display-name>Get resources</display-name>
387
388         <script encoded="false">
389 System.log("VM = &gt; "+activeVM);
390
391
392 if (vmDiskSize == -1) {
393         allocate_disk_space=60;
394 }
395
396 for each (vmHost in vimCL.host) {
397         System.log("HOSTNAME "+vmHost.name);
398         for each (vlan in vmHost.network) {
399                 
400                 try {
401                 if(vlan.config.defaultPortConfig.vlan instanceof VcVmwareDistributedVirtualSwitchVlanIdSpec){
402                         //System.log('NAME =&gt; '+vlan.config.name);
403                         //System.log('VLAN Ting '+vlan.config.defaultPortConfig.vlan.vlanId);
404                         if (vlan_name == vlan.config.name) {
405                                 vmNetwork=vlan;
406                                 var pools = System.getModule("com.vmware.library.vc.resourcePool").getValidResourcePoolForNetwork(vmNetwork);
407                                 for each (pool in pools) {
408                                         if (pool.name == "sydr-kat"+viktighet) {
409                                                 vmResourcePool=pool;
410                                                 System.log("Ressurs poool = "+pool.name);
411                                                 break;
412                                         }
413                                 }
414                                 break;
415                         }
416                 }
417                 }
418                 catch (err){
419                 }
420         }
421 }
422         </script>
423
424         <in-binding>
425             <bind name="activeVM" type="string" export-name="activeVM">
426                 <description>Virtual machine currently being processed</description>
427             </bind>
428             <bind name="allVMs" type="Array/SQL:ActiveRecord" export-name="allVMs"/>
429             <bind name="VIM" type="VC:SdkConnection" export-name="VIM">
430                 <description>Virtual Senter Server</description>
431             </bind>
432             <bind name="vlan_id" type="number" export-name="vlan_id"/>
433             <bind name="vmResourcePool" type="VC:ResourcePool" export-name="vmResourcePool">
434                 <description>Resource pool in which to create the virtual machine</description>
435             </bind>
436             <bind name="vlan_name" type="string" export-name="vlan_name">
437                 <description>Vlan descriptive name</description>
438             </bind>
439             <bind name="vimCL" type="VC:ClusterComputeResource" export-name="vimCL"/>
440             <bind name="viktighet" type="number" export-name="viktighet"/>
441             <bind name="vmDiskSize" type="number" export-name="vmDiskSize"/>
442         </in-binding>
443
444         <out-binding>
445             <bind name="vmGuestOs" type="VC:VirtualMachineGuestOsIdentifier" export-name="vmGuestOs">
446                 <description>Guest operating system to use with the virtual machine</description>
447             </bind>
448             <bind name="vmFolder" type="VC:VmFolder" export-name="vmFolder">
449                 <description>Virtual machine folder</description>
450             </bind>
451             <bind name="allocate_disk_space" type="number" export-name="allocate_disk_space"/>
452             <bind name="vmResourcePool" type="VC:ResourcePool" export-name="vmResourcePool">
453                 <description>Resource pool in which to create the virtual machine</description>
454             </bind>
455             <bind name="vmNetwork" type="VC:DistributedVirtualPortgroup" export-name="vmNetwork">
456                 <description>The network to connect to</description>
457             </bind>
458             <bind name="vmHost" type="VC:HostSystem" export-name="vmHost">
459                 <description>Host on which to create the virtual machine</description>
460             </bind>
461         </out-binding>
462
463         <description>Get and find resources for our new VM</description>
464
465         <position x="964.5" y="328.1363636363636"/>
466     </workflow-item>
467
468     <workflow-item name="item7" out-name="item0" type="link" linked-workflow-id="1f0fc470-006c-4c15-a3b9-95e2e7540f22">
469         <display-name>global_parameters</display-name>
470
471         <in-binding/>
472
473         <out-binding>
474             <bind name="mailto" type="string" export-name="mailto1"/>
475             <bind name="smtp_server" type="string" export-name="smtp_server1"/>
476             <bind name="smtp_port" type="string" export-name="smtp_port1"/>
477             <bind name="database" type="SQL:Database" export-name="database"/>
478             <bind name="vmPassword" type="SecureString" export-name="vmPassword"/>
479         </out-binding>
480
481         <position x="65.0" y="219.04545454545453"/>
482     </workflow-item>
483
484     <workflow-item name="item11" out-name="item18" catch-name="item10" throw-bind-name="activeVM" type="task">
485         <display-name>GetVmAttrfromDB</display-name>
486
487         <script encoded="false">
488 /*
489  * Get variables from Database
490  *
491  */
492
493 var guestid = vm.getProperty("guestid");
494
495 System.log("Active VM =&gt; "+activeVM);
496
497 var computer=activeVM.split(".");
498 computerName=computer[0];
499 vlan_id = vm.getProperty("vlanid");
500 vlan_name = vm.getProperty("vlan");
501 var date = new Date();
502
503
504
505
506 viktighet = vm.getProperty("viktighet");
507 folder = vm.getProperty("folder");
508 vlanName = vm.getProperty("vlanid");
509
510 System.log("VLAN = "+vlanName);
511
512 vmGuestOs = VcVirtualMachineGuestOsIdentifier.fromString(vm.getProperty("guestid"));
513 vmDiskSize = vm.getProperty("disksize");
514 vmMemorySize = vm.getProperty("memory")*1024;
515 vmNbOfCpus = vm.getProperty("num_cpus");
516 epostliste = vm.getProperty("epostliste");
517 kort_beskrivelse = vm.getProperty("kort_beskrivelse");
518 osname = vm.getProperty("guestid");
519 ad_domain_id=vm.getProperty("ad_domain_id");
520 ad_domain_name=vm.getProperty("ad_domain_name");
521 cluster=vm.getProperty("cluster");
522 datacenter=vm.getProperty("datacenter");
523 os_full_name=vm.getProperty("os");
524 template_name=vm.getProperty("template");
525
526 if (template_name == "pxe") {
527         pxe = true;
528
529 /*
530     Get Windows roles from DB
531 */
532 var serverid = vm.getProperty("serverid");
533 var db_roles=database.readCustomQuery(""
534     +"select windows_roles.info from windows_roles, win_server_roles "
535     +"where windows_roles.id = win_server_roles.id and serverid = "+serverid+";");
536
537 windows_roles=[];
538 for each (role in db_roles) {
539     System.log(role.getProperty("info"));
540     var rname=role.getProperty("info");
541     windows_roles.push(rname);
542 }
543
544 /*
545     Get Linux Roles from DB
546 */
547
548 var db_cfroles=database.readCustomQuery(""
549     +"select cf_roles.name from cf_server_roles, cf_roles "
550     +"where cf_roles.cfid = cf_server_roles.cfid and cf_server_roles.serverid=" + serverid + ";");
551
552
553 linux_roles=[];
554 for each (cfrole in db_cfroles) {
555     System.log(cfrole.getProperty("name"));
556     var rname=cfrole.getProperty("name");
557     linux_roles.push(rname);
558 }
559
560 /*
561 vmProperties =
562 {
563         guestid                 :       vm.getProperty("guestid"),
564         computerName    :       activeVM.split(".")[0],
565         vlan_id                 :       vm.getProperty("vlanid"),
566         vlan_name               :       vm.getProperty("vlan"),
567         viktighet               :       vm.getProperty("viktighet"),
568         folder                  :       vm.getProperty("folder"),
569         vlanName                :       vm.getProperty("vlanid"),
570         vmGuestOs               :       VcVirtualMachineGuestOsIdentifier.fromString(vm.getProperty("guestid")),
571         vmDiskSize              :       vm.getProperty("disksize"),
572         vmMemorySize    :       vm.getProperty("memory"),
573         vmNbOfCpus              :       vm.getProperty("num_cpus"),
574         epostliste              :       vm.getProperty("epostliste"),
575         kort_beskrivelse:       vm.getProperty("kort_beskrivelse"),
576         osname                  :       vm.getProperty("guestid"),
577         ad_domain_id    :       vm.getProperty("ad_domain_id"),
578         ad_domain_name  :       vm.getProperty("ad_domain_name"),
579         cluster                 :       vm.getProperty("cluster"),
580         datacenter              :       vm.getProperty("datacenter"),
581         os_full_name    :       vm.getProperty("os"),
582         template_name   :       vm.getProperty("template"),
583         serverid                :       vm.getProperty("serverid"),
584         windows_roles   :       windows_roles,
585         linux_roles             :       linux_roles,
586         pxe                             :       pxe,
587 };
588 */
589
590 //vmCount = allVMs.length;
591 //currentVM = 0;
592         </script>
593
594         <in-binding>
595             <bind name="currentVM" type="number" export-name="currentVM">
596                 <description>Index of the virtual machine in the array of virtual machines</description>
597             </bind>
598             <bind name="database" type="SQL:Database" export-name="database"/>
599             <bind name="activeVM" type="string" export-name="activeVM"/>
600             <bind name="vm" type="SQL:ActiveRecord" export-name="vm"/>
601         </in-binding>
602
603         <out-binding>
604             <bind name="viktighet" type="number" export-name="viktighet"/>
605             <bind name="folder" type="string" export-name="folder"/>
606             <bind name="vmGuestOs" type="VC:VirtualMachineGuestOsIdentifier" export-name="vmGuestOs"/>
607             <bind name="vmDiskSize" type="number" export-name="vmDiskSize"/>
608             <bind name="vmMemorySize" type="number" export-name="vmMemorySize"/>
609             <bind name="vmNbOfCpus" type="number" export-name="vmNbOfCpus"/>
610             <bind name="epostliste" type="string" export-name="epostliste"/>
611             <bind name="kort_beskrivelse" type="string" export-name="kort_beskrivelse"/>
612             <bind name="osname" type="string" export-name="osname">
613                 <description>Navn på OS</description>
614             </bind>
615             <bind name="environment" type="Array/string" export-name="environment">
616                 <description>An array of environment variables, specified in the guest OS notation (eg PATH=c:\bin;c:\windows\system32 or LD_LIBRARY_PATH=/usr/lib:/lib), to be set for the program being run. Note that these are not additions to the default environment variables; they define the complete set available to the program. If none are specified the values are guest dependent.</description>
617             </bind>
618             <bind name="windows_roles" type="Array/string" export-name="windows_roles">
619                 <description>Windows roles. Other workflow fetches roles from database</description>
620             </bind>
621             <bind name="ad_domain_id" type="number" export-name="ad_domain_id"/>
622             <bind name="ad_domain_name" type="string" export-name="ad_domain_name"/>
623             <bind name="computerName" type="string" export-name="computerName"/>
624             <bind name="activeVM" type="string" export-name="activeVM">
625                 <description>Virtual machine currently being processed</description>
626             </bind>
627             <bind name="vlan_id" type="number" export-name="vlan_id"/>
628             <bind name="vlan_name" type="string" export-name="vlan_name"/>
629             <bind name="cluster" type="string" export-name="cluster"/>
630             <bind name="datacenter" type="string" export-name="datacenter"/>
631             <bind name="os_full_name" type="string" export-name="os_full_name"/>
632             <bind name="template_name" type="string" export-name="template_name"/>
633             <bind name="linux_roles" type="Array/string" export-name="linux_roles"/>
634             <bind name="vmProperties" type="Properties" export-name="vmProperties"/>
635             <bind name="pxe" type="boolean" export-name="pxe"/>
636         </out-binding>
637
638         <description>Get VM attributes from database</description>
639
640         <position x="544.5" y="328.1363636363636"/>
641     </workflow-item>
642
643     <workflow-item name="item8" out-name="item12" catch-name="item10" throw-bind-name="errorCode" type="link" linked-workflow-id="d37cd9f5-2d4a-4ec1-ae1f-d2df8496c5b4">
644         <display-name>host_add_nonvm</display-name>
645
646         <in-binding>
647             <bind name="vm" type="string" export-name="activeVM">
648                 <description>Virtual Machine</description>
649             </bind>
650             <bind name="kort_beskrivelse" type="string" export-name="kort_beskrivelse">
651                 <description>Kort beskrivelse av ny VM</description>
652             </bind>
653             <bind name="epostliste" type="string" export-name="epostliste">
654                 <description>Mail alias for ny VM</description>
655             </bind>
656             <bind name="osname" type="string" export-name="osname">
657                 <description>Navn på OS</description>
658             </bind>
659             <bind name="macAddress" type="string" export-name="macAddress">
660                 <description>Dersom undef, så defineres ikke macAddress</description>
661             </bind>
662             <bind name="vlanName" type="number" export-name="vlan_id"/>
663         </in-binding>
664
665         <out-binding>
666             <bind name="gateway" type="Array/string" export-name="gateway"/>
667             <bind name="netmask" type="string" export-name="subnetMask"/>
668             <bind name="ipAddress" type="string" export-name="ipAddress"/>
669         </out-binding>
670
671         <description>Registrer en ny enhet i bofh før opprettelse av VM</description>
672
673         <position x="964.5" y="155.4090909090909"/>
674     </workflow-item>
675
676     <workflow-item name="item14" out-name="item8" catch-name="item10" throw-bind-name="errorCode" type="link" linked-workflow-id="1f459776-8603-4336-ae18-85672d369909">
677         <display-name>get_optimal_datastore</display-name>
678
679         <in-binding>
680             <bind name="vmNetwork" type="VC:DistributedVirtualPortgroup" export-name="vmNetwork"/>
681             <bind name="diskspace" type="number" export-name="allocate_disk_space"/>
682         </in-binding>
683
684         <out-binding>
685             <bind name="datastore1" type="VC:Datastore" export-name="datastore"/>
686         </out-binding>
687
688         <description>
689 Find datastore with most free disk, and space for the VMs disk
690
691 Input parameter is network object, and GB of required space
692         </description>
693
694         <position x="964.5" y="200.86363636363635"/>
695     </workflow-item>
696
697     <workflow-item name="item10" out-name="item0" type="link" linked-workflow-id="fac19258-528f-4e75-a341-6242a16246b6">
698         <display-name>set_db_state</display-name>
699
700         <in-binding>
701             <bind name="vm" type="string" export-name="activeVM">
702                 <description>Navn på vm som skal ha oppdatert status</description>
703             </bind>
704             <bind name="status" type="number" export-name="errorStatus">
705                 <description>VM status. Default 4 or 999 for deleted</description>
706             </bind>
707             <bind name="message" type="string" export-name="errorCode">
708                 <description>Message to log to info or error</description>
709             </bind>
710             <bind name="virtualMachine" type="VC:VirtualMachine" export-name="newVM"/>
711             <bind name="project_folder" type="string" export-name="project_folder"/>
712             <bind name="datacenter" type="VC:Datacenter" export-name="vimDC"/>
713         </in-binding>
714
715         <out-binding/>
716
717         <description>Set a new state for VM in database</description>
718
719         <position x="504.5" y="155.4090909090909"/>
720     </workflow-item>
721
722     <workflow-item name="item15" out-name="item0" type="link" linked-workflow-id="e8ecbc5e-964e-4811-84d6-76ff12d69d72">
723         <display-name>vm_ready_email</display-name>
724
725         <in-binding>
726             <bind name="vm" type="VC:VirtualMachine" export-name="newVM"/>
727             <bind name="viktighet" type="number" export-name="viktighet"/>
728             <bind name="datacenter" type="string" export-name="datacenter"/>
729             <bind name="cluster" type="string" export-name="cluster"/>
730             <bind name="disksize" type="number" export-name="vmDiskSize"/>
731             <bind name="num_cpus" type="number" export-name="vmNbOfCpus"/>
732             <bind name="memory" type="number" export-name="vmMemorySize"/>
733             <bind name="osname" type="string" export-name="os_full_name"/>
734             <bind name="epostliste" type="string" export-name="epostliste"/>
735             <bind name="datacenter1" type="VC:Datacenter" export-name="vimDC"/>
736         </in-binding>
737
738         <out-binding/>
739
740         <description>Logger hendelser som skjer til databasen. Også mulig å logge til email dersom variablen enable_mail settes til true</description>
741
742         <position x="124.5" y="28.136363636363633"/>
743     </workflow-item>
744
745     <workflow-item name="item16" out-name="item6" type="link" linked-workflow-id="fac19258-528f-4e75-a341-6242a16246b6">
746         <display-name>Set status = 10</display-name>
747
748         <in-binding>
749             <bind name="vm" type="string" export-name="activeVM">
750                 <description>Navn på vm som skal ha oppdatert status</description>
751             </bind>
752             <bind name="status" type="number" export-name="status_start_cloning">
753                 <description>VM status. Default 4 or 999 for deleted</description>
754             </bind>
755             <bind name="message" type="string" export-name="message_start_cloning">
756                 <description>Message to log to info or error</description>
757             </bind>
758             <bind name="virtualMachine" type="VC:VirtualMachine" export-name="newVM"/>
759             <bind name="project_folder" type="string" export-name="project_folder"/>
760             <bind name="datacenter" type="VC:Datacenter" export-name="vimDC"/>
761         </in-binding>
762
763         <out-binding/>
764
765         <description>Set a new state for VM in database</description>
766
767         <position x="824.5" y="328.1363636363636"/>
768     </workflow-item>
769
770     <workflow-item name="item4" out-name="item15" type="link" linked-workflow-id="fac19258-528f-4e75-a341-6242a16246b6">
771         <display-name>Set status = 4</display-name>
772
773         <in-binding>
774             <bind name="vm" type="string" export-name="activeVM">
775                 <description>Navn på vm som skal ha oppdatert status</description>
776             </bind>
777             <bind name="status" type="number" export-name="status_finished">
778                 <description>VM status. Default 4 or 999 for deleted</description>
779             </bind>
780             <bind name="message" type="string" export-name="message_start_cloning">
781                 <description>Message to log to info or error</description>
782             </bind>
783             <bind name="virtualMachine" type="VC:VirtualMachine" export-name="newVM"/>
784             <bind name="project_folder" type="string" export-name="epostliste"/>
785             <bind name="datacenter" type="VC:Datacenter" export-name="vimDC"/>
786         </in-binding>
787
788         <out-binding/>
789
790         <description>Set a new state for VM in database</description>
791
792         <position x="404.5" y="28.136363636363633"/>
793     </workflow-item>
794
795     <workflow-item name="item5" out-name="item14" type="link" linked-workflow-id="bb56f2b9-97b8-4c32-829f-b92a9a0fd53e">
796         <display-name>get_template</display-name>
797
798         <in-binding>
799             <bind name="vmName" type="string" export-name="template_name"/>
800             <bind name="vmHost" type="VC:HostSystem" export-name="vmHost"/>
801             <bind name="currState" type="number" export-name="status_start_cloning"/>
802         </in-binding>
803
804         <out-binding>
805             <bind name="autoFolder" type="VC:VmFolder" export-name="vmFolder"/>
806             <bind name="template" type="VC:VirtualMachine" export-name="template"/>
807             <bind name="osname" type="string" explicitly-not-bound="true"/>
808         </out-binding>
809
810         <position x="964.5" y="264.5"/>
811     </workflow-item>
812
813     <workflow-item name="item9" out-name="item4" catch-name="item10" throw-bind-name="errorCode" type="link" linked-workflow-id="eb00c75d-3403-4fb9-a3ae-a07e45c20bf0">
814         <display-name>clone_lin_win</display-name>
815
816         <in-binding>
817             <bind name="folder" type="VC:VmFolder" export-name="vmFolder">
818                 <description>Virtual machine folder</description>
819             </bind>
820             <bind name="name" type="string" export-name="activeVM">
821                 <description>New virtual machine name</description>
822             </bind>
823             <bind name="vm" type="VC:VirtualMachine" export-name="template">
824                 <description>Virtual machine to clone</description>
825             </bind>
826             <bind name="powerOn" type="boolean" export-name="powerOn">
827                 <description>Specifies whether or not the new virtual machine should be powered on after creation</description>
828             </bind>
829             <bind name="datastore" type="VC:Datastore" export-name="datastore">
830                 <description>Datastore in which to store the virtual machine. If not specified, the current datastore is used</description>
831             </bind>
832             <bind name="host" type="VC:HostSystem" export-name="vmHost">
833                 <description>(Optional) Host on which to create the virtual machine</description>
834             </bind>
835             <bind name="pool" type="VC:ResourcePool" export-name="vmResourcePool">
836                 <description>(Optional) Resource pool in which to create the virtual machine</description>
837             </bind>
838             <bind name="doSysprep" type="boolean" export-name="doSysprep">
839                 <description>Run the Sysprep operations and wait for the task to complete. Not used if the virtual machine is marked as template</description>
840             </bind>
841             <bind name="clientName" type="string" export-name="computerName">
842                 <description>Name or prefix name of the Linux client</description>
843             </bind>
844             <bind name="network" type="VC:DistributedVirtualPortgroup" export-name="vmNetwork">
845                 <description>Network on which to attach the virtual network interface</description>
846             </bind>
847             <bind name="dnsServerList" type="Array/string" export-name="dnsServerList">
848                 <description>(Optional) List of DNS servers for a virtual network adapter with a static IP address</description>
849             </bind>
850             <bind name="dnsDomain" type="string" export-name="dnsDomain">
851                 <description>(Optional) DNS domain suffix such as vmware.com</description>
852             </bind>
853             <bind name="dhcp" type="boolean" export-name="dhcp">
854                 <description>Use a DHCP server to configure the virtual network adapter</description>
855             </bind>
856             <bind name="gateway" type="Array/string" export-name="gateway">
857                 <description>(Optional) List of gateways, in order of preference</description>
858             </bind>
859             <bind name="ipAddress" type="string" export-name="ipAddress">
860                 <description>Fixed, valid IP address</description>
861             </bind>
862             <bind name="macAddress" type="string" export-name="macAddress1">
863                 <description>(Optional) The MAC address of a network adapter being customized. If it is not included, the customization process maps the settings from the virtual machine's network adapters, in PCI slot order</description>
864             </bind>
865             <bind name="subnetMask" type="string" export-name="subnetMask">
866                 <description>[Optional] Subnet mask for this virtual network adapter</description>
867             </bind>
868             <bind name="diskIndex" type="number" export-name="diskIndex">
869                 <description>Disk index</description>
870             </bind>
871             <bind name="diskSize" type="number" export-name="vmDiskSize">
872                 <description>Disk size (in GB)</description>
873             </bind>
874             <bind name="diskMode" type="VC:VirtualDiskMode" export-name="diskMode">
875                 <description>Disk persistence mode</description>
876             </bind>
877             <bind name="scsiBusNumber" type="number" export-name="scsiBusNumber">
878                 <description>SCSI controller bus number</description>
879             </bind>
880             <bind name="thinProvisioned" type="boolean" export-name="thinProvisioned">
881                 <description>Use thin provisioning?</description>
882             </bind>
883             <bind name="fullName" type="string" export-name="fullName">
884                 <description>User's full name</description>
885             </bind>
886             <bind name="orgName" type="string" export-name="orgName">
887                 <description>Organization name</description>
888             </bind>
889             <bind name="windows_roles" type="Array/string" export-name="windows_roles">
890                 <description>Windows roles. Other workflow fetches roles from database</description>
891             </bind>
892             <bind name="vlan_name" type="string" export-name="vlan_name">
893                 <description>Vlan descriptive name</description>
894             </bind>
895             <bind name="ad_domain_id" type="number" export-name="ad_domain_id"/>
896             <bind name="ad_domain_name" type="string" export-name="ad_domain_name"/>
897             <bind name="vmPassword" type="SecureString" export-name="vmPassword"/>
898             <bind name="osname" type="string" export-name="osname"/>
899             <bind name="ipv6gateway" type="string" export-name="ipv6gateway"/>
900             <bind name="ipv6dnsServerList" type="Array/string" export-name="ipv6dnsServerList"/>
901             <bind name="memory" type="number" export-name="vmMemorySize"/>
902             <bind name="vcpu" type="number" export-name="vmNbOfCpus"/>
903             <bind name="ipv6address" type="string" export-name="ipv6address"/>
904             <bind name="ipv6Prefixlen" type="number" export-name="ipv6Prefixlen"/>
905             <bind name="pxe" type="boolean" export-name="pxe"/>
906             <bind name="epostliste" type="string" export-name="epostliste"/>
907             <bind name="kort_beskrivelse" type="string" export-name="kort_beskrivelse"/>
908         </in-binding>
909
910         <out-binding>
911             <bind name="newVM1" type="VC:VirtualMachine" export-name="newVM"/>
912         </out-binding>
913
914         <position x="964.5" y="28.136363636363633"/>
915     </workflow-item>
916
917     <workflow-item name="item12" out-name="item9" type="link" linked-workflow-id="1877a3a5-e5cc-45fe-b752-677bf91a6e7f">
918         <display-name>host_roles</display-name>
919
920         <in-binding>
921             <bind name="vm" type="string" export-name="activeVM">
922                 <description>Virtual Machine</description>
923             </bind>
924             <bind name="osname" type="string" export-name="osname">
925                 <description>Navn på OS</description>
926             </bind>
927             <bind name="linux_roles" type="Array/string" export-name="linux_roles"/>
928             <bind name="vmobject" type="VC:VirtualMachine" explicitly-not-bound="true"/>
929         </in-binding>
930
931         <out-binding/>
932
933         <description>Add cfengine roles to bofh</description>
934
935         <position x="964.5" y="91.77272727272727"/>
936     </workflow-item>
937
938     <workflow-item name="item13" out-name="item11" type="custom-condition" alt-out-name="item10">
939         <display-name>Finnes vm fra før ?</display-name>
940
941         <script encoded="false">
942 var VMs = System.getModule("com.vmware.library.vc.vm").getAllVMsMatchingRegexp(activeVM);
943
944 if (status == 13) {
945         return false;
946 }
947 if (VMs.length &gt; 0) {
948         System.log("Det finnes allerde en VM med navn "+activeVM);
949         return false;
950 } else {
951         return true;
952 }
953         </script>
954
955         <in-binding>
956             <bind name="activeVM" type="string" export-name="activeVM"/>
957             <bind name="vimCL" type="VC:ClusterComputeResource" export-name="vimCL"/>
958             <bind name="status" type="number" export-name="status"/>
959         </in-binding>
960
961         <position x="404.5" y="318.1363636363636"/>
962     </workflow-item>
963
964     <workflow-item name="item17" out-name="item13" catch-name="item10" throw-bind-name="errorCode" type="task">
965         <display-name>Get VIM, datacenter and cluster</display-name>
966
967         <script encoded="false">
968 vm = allVMs[currentVM];
969 activeVM=vm.name;
970
971 var url = vm.getProperty('url');
972 var cluster = vm.getProperty('cluster');
973 var datacenter = vm.getProperty('datacenter');
974
975 for each (var vim in VcPlugin.allSdkConnections) {
976         var vimname=vim.name.replace(":443","");
977         if (url == vimname+"/vimService") {
978                 System.log("VIMNAME = "+vim.name);
979                 VIM=vim;
980         }
981
982 try  {
983         var dcsearch = "xpath:name[matches(.,'"  + datacenter +"')]"; 
984         var datacenters = VIM.getAllDatacenters(['name'],dcsearch);
985         
986         for each (var dcid in datacenters) {
987                 vimDC=dcid;
988                 System.log("Datacenter  "+dcid.name);
989         }
990         
991         var search = "xpath:name[matches(.,'"  + cluster +"')]"; 
992         var clusters = VIM.getAllClusterComputeResources(['name'],search);
993         for each (var c in clusters) {
994                 var dcname=System.getModule("com.vmware.library.vc.basic").getDatacenterForVimObject(c).name;
995                 if (datacenter == dcname) {
996                         vimCL=c;
997                         System.log("Cluster  "+c.name);
998                 }
999         }
1000 }
1001
1002 catch (err) {
1003         System.error("Not able to find datacenter"+activeVM);
1004         status=13;
1005 }
1006         </script>
1007
1008         <in-binding>
1009             <bind name="currentVM" type="number" export-name="currentVM"/>
1010             <bind name="allVMs" type="Array/SQL:ActiveRecord" export-name="allVMs"/>
1011             <bind name="vmPassword" type="SecureString" export-name="vmPassword"/>
1012         </in-binding>
1013
1014         <out-binding>
1015             <bind name="activeVM" type="string" export-name="activeVM"/>
1016             <bind name="VIM" type="VC:SdkConnection" export-name="VIM">
1017                 <description>Pointer to Vcenter object</description>
1018             </bind>
1019             <bind name="vimCL" type="VC:ClusterComputeResource" export-name="vimCL"/>
1020             <bind name="vimDC" type="VC:Datacenter" export-name="vimDC"/>
1021             <bind name="vm" type="SQL:ActiveRecord" export-name="vm"/>
1022             <bind name="status" type="number" export-name="status"/>
1023         </out-binding>
1024
1025         <position x="264.5" y="328.1363636363636"/>
1026     </workflow-item>
1027
1028     <workflow-item name="item18" out-name="item16" type="task">
1029         <display-name>Test params</display-name>
1030
1031         <script encoded="false">
1032 //var ff = vmProperties.g()
1033 //var f = vmProperties.get("osname");
1034 //ystem.log(ff.name);
1035
1036 /*
1037 for each (var r in f) {
1038         System.log("role = "+r);
1039 }
1040 */
1041         </script>
1042
1043         <in-binding>
1044             <bind name="vmProperties" type="Properties" export-name="vmProperties"/>
1045             <bind name="test" type="Array/string" export-name="test"/>
1046         </in-binding>
1047
1048         <out-binding/>
1049
1050         <position x="685.0" y="328.1363636363636"/>
1051     </workflow-item>
1052
1053     <presentation/>
1054 </workflow>