første xml update
[virt-orchestrator.git] / vFLOWER / content / Workflows / uio / lib / bofh / host_add_nonvm.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="item9" object-name="workflow:name=generic" id="d37cd9f5-2d4a-4ec1-ae1f-d2df8496c5b4" version="1.0.7" api-version="3.1.0" allowed-operations="fve" icon-id="419c9a2c-8915-4c26-8b59-fbb5931eb502" restartMode="1" resumeFromFailedMode="0">
3     <display-name>host_add_nonvm</display-name>
4
5     <description>
6 Registrer en ny enhet i bofh før opprettelse av VM
7
8 virtprov@esx-mgmt:/site/lib/Ovc/host_add
9     </description>
10
11     <position x="245.0" y="0.45454545454545325"/>
12
13     <input>
14         <param name="vm" type="string">
15             <description>Virtual Machine</description>
16         </param>
17         <param name="kort_beskrivelse" type="string">
18             <description>Kort beskrivelse av ny VM</description>
19         </param>
20         <param name="epostliste" type="string">
21             <description>Mail alias for ny VM</description>
22         </param>
23         <param name="vlanName" type="number">
24             <description>Vlan nummer</description>
25         </param>
26         <param name="osname" type="string">
27             <description>Navn på OS</description>
28         </param>
29         <param name="macAddress" type="string">
30             <description>Dersom undef, så defineres ikke macAddress</description>
31         </param>
32     </input>
33
34     <output>
35         <param name="gateway" type="Array/string"/>
36         <param name="netmask" type="string"/>
37         <param name="ipAddress" type="string"/>
38     </output>
39
40     <attrib name="hostNameOrIP" type="string" read-only="false">
41         <value encoded="n"/>
42         <description>Hostname or IP address of the SSH host</description>
43     </attrib>
44     <attrib name="cmd" type="string" read-only="false">
45         <value encoded="n">uptime</value>
46         <description>The SSH command to run</description>
47     </attrib>
48     <attrib name="outputText" type="string" read-only="false">
49         <value encoded="n"/>
50         <description>Result of running the SSH command</description>
51     </attrib>
52     <attrib name="errorText" type="string" read-only="false">
53         <value encoded="n"/>
54         <description>Error text, if any</description>
55     </attrib>
56     <attrib name="database" type="SQL:Database" read-only="false">
57         <value encoded="n">__NULL__</value>
58         <description>The database to use for the query</description>
59     </attrib>
60     <attrib name="query_vlan" type="string" read-only="false">
61         <value encoded="n"/>
62         <description>The query to execute</description>
63     </attrib>
64     <attrib name="networkName" type="Array/SQL:ActiveRecord" read-only="false">
65         <value encoded="n">__NULL__</value>
66         <description>An array of ActiveRecord objects corresponding to the query.</description>
67     </attrib>
68
69     <workflow-item name="item3" out-name="item6" type="task">
70         <display-name>Get VLAN id</display-name>
71
72         <script encoded="false">
73 System.log("VLAN ID in BOFH "+vlanName);
74
75 query_vlan="select network from all_networks where vlanid = " + vlanName + ";";
76         </script>
77
78         <in-binding>
79             <bind name="vlanName" type="number" export-name="vlanName"/>
80         </in-binding>
81
82         <out-binding>
83             <bind name="query_vlan" type="string" export-name="query_vlan">
84                 <description>The query to execute</description>
85             </bind>
86         </out-binding>
87
88         <position x="304.5" y="55.40909090909091"/>
89     </workflow-item>
90
91     <workflow-item name="item6" out-name="item7" type="link" linked-workflow-id="048080808080808080808080808080808F808080013264596926189e8150e1493">
92         <display-name>Network name from SQL</display-name>
93
94         <in-binding>
95             <bind name="database" type="SQL:Database" export-name="database">
96                 <description>The database to use for the query</description>
97             </bind>
98             <bind name="query" type="string" export-name="query_vlan">
99                 <description>The query to execute</description>
100             </bind>
101         </in-binding>
102
103         <out-binding>
104             <bind name="resultRecords" type="Array/SQL:ActiveRecord" export-name="networkName">
105                 <description>An array of ActiveRecord objects corresponding to the query.</description>
106             </bind>
107         </out-binding>
108
109         <description>Do a select network from all_networks where vlanid = vlan of current VM</description>
110
111         <position x="404.5" y="55.40909090909091"/>
112     </workflow-item>
113
114     <workflow-item name="item7" out-name="item1" catch-name="item5" throw-bind-name="errorText" type="task">
115         <display-name>preapare bofh cmd</display-name>
116
117         <script encoded="false">
118 var netName=networkName[0].getProperty("network");
119 System.log("Network name =&gt; " + netName);
120
121
122 System.log("OS = "+osname);
123
124 if (osname.search(/linux/i) != -1 || osname.search(/rhel/i) != -1 || osname.search(/fedora/i) != -1 ) {
125         var os = 'linux';
126 } else if (osname.search(/windows/i) != -1) {
127         var os = 'win';
128 } else {
129         
130         throw("The VM "+vm+" is defined with an unsupported OS");
131                 
132 }
133 if (! macAddress) {
134         macAddress='00:00:00:00';
135 }
136
137 cmd="/site/lib/Ovc/host_add "+vm+" "+netName+" "+macAddress+" "+os+" "+epostliste+' "'+kort_beskrivelse+'"';
138
139
140 try {
141         var ssh = new SSHSession(hostNameOrIP,'virtprov');
142         ssh.connectWithIdentity('../conf/vco_key','');
143         
144         System.log("Executing '"+cmd+"'");
145         ssh.executeCommand(cmd,true) ;
146                 
147         var output = ssh.getOutput();
148         errorText = ssh.getError();
149         var exitCode = ssh.exitCode;
150         
151         System.log("Output: '"+output+"'");
152         System.log("Error: '"+errorText+"'");
153         System.log("Exit code: '"+exitCode+"'");
154
155         ssh.disconnect();
156         
157         if (exitCode == 1) {
158                 trow (errorText);
159         }
160         
161         
162         var IP = output.split(',');
163         
164         ipAddress=IP[0];
165         netmask=IP[1];
166         gateway=[IP[2]];
167 }
168
169 catch (e) {
170         throw "Unable to execute command " + e;
171 }
172         </script>
173
174         <in-binding>
175             <bind name="epostliste" type="string" export-name="epostliste"/>
176             <bind name="kort_beskrivelse" type="string" export-name="kort_beskrivelse"/>
177             <bind name="macAddress" type="string" export-name="macAddress"/>
178             <bind name="networkName" type="Array/SQL:ActiveRecord" export-name="networkName">
179                 <description>An array of ActiveRecord objects corresponding to the query.</description>
180             </bind>
181             <bind name="vm" type="string" export-name="vm"/>
182             <bind name="osname" type="string" export-name="osname"/>
183             <bind name="hostNameOrIP" type="string" export-name="hostNameOrIP">
184                 <description>Hostname or IP address of the SSH host</description>
185             </bind>
186             <bind name="database" type="SQL:Database" export-name="database">
187                 <description>The database to use for the query</description>
188             </bind>
189         </in-binding>
190
191         <out-binding>
192             <bind name="cmd" type="string" export-name="cmd">
193                 <description>The SSH command to run</description>
194             </bind>
195             <bind name="errorText" type="string" export-name="errorText">
196                 <description>Error text, if any</description>
197             </bind>
198             <bind name="gateway" type="Array/string" export-name="gateway"/>
199             <bind name="netmask" type="string" export-name="netmask"/>
200             <bind name="ipAddress" type="string" export-name="ipAddress"/>
201         </out-binding>
202
203         <description>Prepare a BOFH add_host commandline for sending to esx-mgmt</description>
204
205         <position x="524.5" y="55.40909090909091"/>
206     </workflow-item>
207
208     <workflow-item name="item0" throw-bind-name="errorText" type="end" end-mode="0">
209         <position x="924.5" y="45.40909090909091"/>
210     </workflow-item>
211
212     <workflow-item name="item4" out-name="item0" type="link" linked-workflow-id="25832524-da3e-407e-a64a-d4418bcb3174">
213         <display-name>info</display-name>
214
215         <in-binding>
216             <bind name="message" type="string" export-name="outputText"/>
217         </in-binding>
218
219         <out-binding/>
220
221         <position x="744.5" y="55.40909090909091"/>
222     </workflow-item>
223
224     <workflow-item name="item5" out-name="item8" type="link" linked-workflow-id="2cdac1c6-1c4b-4fd4-aa62-a2736a71f7e7">
225         <display-name>error</display-name>
226
227         <in-binding>
228             <bind name="message" type="string" export-name="errorText"/>
229         </in-binding>
230
231         <out-binding/>
232
233         <position x="624.5" y="119.04545454545453"/>
234     </workflow-item>
235
236     <workflow-item name="item8" throw-bind-name="errorText" type="end" end-mode="1">
237         <position x="804.5" y="109.04545454545453"/>
238     </workflow-item>
239
240     <workflow-item name="item9" out-name="item3" type="link" linked-workflow-id="1f0fc470-006c-4c15-a3b9-95e2e7540f22">
241         <display-name>global_parameters</display-name>
242
243         <in-binding/>
244
245         <out-binding>
246             <bind name="mailto" type="string"/>
247             <bind name="smtp_server" type="string"/>
248             <bind name="smtp_port" type="string"/>
249             <bind name="database" type="SQL:Database" export-name="database"/>
250             <bind name="vmPassword" type="SecureString"/>
251             <bind name="ssh_shell_server" type="string" export-name="hostNameOrIP"/>
252         </out-binding>
253
254         <position x="204.5" y="55.40909090909091"/>
255     </workflow-item>
256
257     <workflow-item name="item1" out-name="item4" type="condition" alt-out-name="item5" comparator="0">
258         <display-name>Decision</display-name>
259
260         <script encoded="false">
261 //Generated by the system, cannot be edited
262 return (errorText != null) ;
263         </script>
264
265         <in-binding>
266             <bind name="errorText" type="string" export-name="errorText"/>
267         </in-binding>
268         <condition name="errorText" type="string" comparator="3" label="null"/>
269
270         <position x="644.5" y="45.40909090909091"/>
271     </workflow-item>
272
273     <presentation>
274         <p-param name="vm">
275             <desc>Virtual Machine</desc>
276         </p-param>
277         <p-param name="kort_beskrivelse">
278             <desc>Kort beskrivelse av ny VM</desc>
279         </p-param>
280         <p-param name="epostliste">
281             <desc>Mail alias for ny VM</desc>
282         </p-param>
283         <p-param name="vlanName">
284             <desc>Vlan nummer</desc>
285         </p-param>
286         <p-param name="osname">
287             <desc>Navn på OS</desc>
288         </p-param>
289         <p-param name="macAddress">
290             <desc>Dersom undef, så defineres ikke macAddress</desc>
291         </p-param>
292     </presentation>
293 </workflow>