første xml update
[virt-orchestrator.git] / vFLOWER / content / Workflows / Library / SSH / Run SSH command.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="item6" object-name="Workflow:name=generic" id="90808080808080808080808080808080D28080800120523434428525559a3425f" version="0.0.3" api-version="3.1.0" allowed-operations="fve" restartMode="1" resumeFromFailedMode="0">
3     <display-name>Run SSH command</display-name>
4
5     <description>Runs an SSH command.</description>
6
7     <position x="160.0" y="10.0"/>
8
9     <input>
10         <param name="hostNameOrIP" type="string">
11             <description>Hostname or IP address of the SSH host</description>
12         </param>
13         <param name="username" type="string">
14             <description>Username</description>
15         </param>
16         <param name="password" type="SecureString">
17             <description>Password</description>
18         </param>
19         <param name="cmd" type="string">
20             <description>The SSH command to run</description>
21         </param>
22         <param name="passwordAuthentication" type="boolean">
23             <description>Sets authentication to password or key file</description>
24         </param>
25         <param name="path" type="Path">
26             <description>Path to the private key</description>
27         </param>
28         <param name="passphrase" type="SecureString">
29             <description>Private key pass-phrase</description>
30         </param>
31     </input>
32
33     <output>
34         <param name="result" type="number">
35             <description>0 = OK, Negative = Error, Positive = Number of values returned, after error text</description>
36         </param>
37         <param name="errorText" type="string">
38             <description>Error text, if any</description>
39         </param>
40         <param name="outputText" type="string">
41             <description>Result of running the SSH command</description>
42         </param>
43     </output>
44
45     <attrib name="output" type="string" read-only="false">
46         <value encoded="n"/>
47         <description>Standard output</description>
48     </attrib>
49     <attrib name="error" type="string" read-only="false">
50         <value encoded="n"/>
51         <description>Error output</description>
52     </attrib>
53     <attrib name="defaultKeyPairPath" type="Path" read-only="false">
54         <value encoded="n">../conf/vco_key</value>
55         <description>Default path to the key file</description>
56     </attrib>
57     <attrib name="exitCode" type="string" read-only="false">
58         <value encoded="n"/>
59         <description>Returns 0 if successful, and a negative value if there is a failure</description>
60     </attrib>
61     <attrib name="logText" type="string" read-only="false">
62         <value encoded="n"/>
63         <description>Log String</description>
64     </attrib>
65
66     <workflow-item name="item3" out-name="item2" type="condition" alt-out-name="item4" comparator="0">
67         <display-name>ok?</display-name>
68
69         <script encoded="false">
70 //Generated by the system, cannot be edited
71 return (error == "null") ;
72         </script>
73
74         <in-binding>
75             <bind name="error" type="string" export-name="error"/>
76         </in-binding>
77         <condition name="error" type="string" comparator="0" label="null"/>
78
79         <position x="120.0" y="170.0"/>
80     </workflow-item>
81
82     <workflow-item name="item2" out-name="item5" content-mode="y" type="task">
83         <display-name>System+Server log</display-name>
84
85         <script encoded="false">
86 //Auto-generated script
87 System.log(text + " - " + object);
88 Server.log(text, object);
89         </script>
90
91         <in-binding>
92             <bind name="text" type="String" export-name="cmd">
93                 <description>The text to log</description>
94             </bind>
95             <bind name="object" type="string" export-name="logText">
96                 <description>The text to log and additional info</description>
97             </bind>
98         </in-binding>
99
100         <out-binding/>
101
102         <description>Log the input text to the console and the server log with level 'log'</description>
103
104         <position x="40.0" y="240.0"/>
105     </workflow-item>
106
107     <workflow-item name="item4" out-name="item5" content-mode="y" type="task">
108         <display-name>System+Server error</display-name>
109
110         <script encoded="false">
111 //Auto-generated script
112 System.error(text + " - " + object);
113 Server.error(text, object);
114         </script>
115
116         <in-binding>
117             <bind name="text" type="String" export-name="cmd">
118                 <description>The text to log</description>
119             </bind>
120             <bind name="object" type="string" export-name="logText">
121                 <description>The text to log and additional info</description>
122             </bind>
123         </in-binding>
124
125         <out-binding/>
126
127         <description>Log the input text to the console and the server log with level 'error'</description>
128
129         <position x="200.0" y="240.0"/>
130     </workflow-item>
131
132     <workflow-item name="item5" out-name="item8" type="task">
133         <display-name>Assign</display-name>
134
135         <script encoded="false">
136 outputText = output;
137 errorText = error;
138 if(error == ""){
139         result = 1;
140 } else {
141         result = -1;
142         throw "SSH execute command failed. " + error;
143 }
144         </script>
145
146         <in-binding>
147             <bind name="output" type="string" export-name="output"/>
148             <bind name="error" type="string" export-name="error"/>
149         </in-binding>
150
151         <out-binding>
152             <bind name="result" type="number" export-name="result"/>
153             <bind name="outputText" type="string" export-name="outputText"/>
154             <bind name="errorText" type="string" export-name="errorText"/>
155         </out-binding>
156
157         <position x="120.0" y="280.0"/>
158     </workflow-item>
159
160     <workflow-item name="item6" out-name="item9" type="task">
161         <display-name>Execute SSH Command</display-name>
162
163         <script encoded="false">
164 try{
165         var session = new SSHSession(hostName,username);
166         
167         if(passwordAuthentication){
168                 System.log("Connecting with password");
169         } else {
170                 if(path == null || path == ""){
171                         System.log("using default");
172                         path = defaultKeyPairPath;
173                 }
174                 System.log("Connecting with key pair ("+path+")");
175                 password = passphrase;
176         }
177
178         session.connectWithPasswordOrIdentity(passwordAuthentication,password,path);
179         System.log("Connected!");
180         
181         System.log("Executing '"+cmd+"'");
182         session.executeCommand(cmd,true) ;
183         
184         output = session.getOutput();
185         error = session.getError();
186         exitCode = session.exitCode;
187         
188         System.log("Output: '"+output+"'");
189         System.log("Error: '"+error+"'");
190         System.log("Exit code: '"+exitCode+"'");
191         
192         session.disconnect();
193         
194 } catch (e) {
195         throw "Unable to execute command " + e;
196 }
197         </script>
198
199         <in-binding>
200             <bind name="username" type="string" export-name="username"/>
201             <bind name="password" type="SecureString" export-name="password"/>
202             <bind name="cmd" type="string" export-name="cmd"/>
203             <bind name="passwordAuthentication" type="boolean" export-name="passwordAuthentication"/>
204             <bind name="path" type="Path" export-name="path"/>
205             <bind name="hostName" type="string" export-name="hostNameOrIP"/>
206             <bind name="passphrase" type="SecureString" export-name="passphrase"/>
207             <bind name="defaultKeyPairPath" type="Path" export-name="defaultKeyPairPath"/>
208         </in-binding>
209
210         <out-binding>
211             <bind name="output" type="string" export-name="output"/>
212             <bind name="error" type="string" export-name="error"/>
213             <bind name="exitCode" type="string" export-name="exitCode"/>
214         </out-binding>
215
216         <position x="120.0" y="60.0"/>
217     </workflow-item>
218
219     <workflow-item name="item8" type="end" end-mode="0">
220         <position x="160.0" y="310.0"/>
221     </workflow-item>
222
223     <workflow-item name="item9" out-name="item3" type="task">
224         <display-name>Prepare for log</display-name>
225
226         <script encoded="false">
227 logText = "output: " + output + "\n" + "error: " + error;
228         </script>
229
230         <in-binding>
231             <bind name="output" type="string" export-name="output"/>
232             <bind name="error" type="string" export-name="error"/>
233         </in-binding>
234
235         <out-binding>
236             <bind name="logText" type="string" export-name="logText"/>
237         </out-binding>
238
239         <position x="120.0" y="120.0"/>
240     </workflow-item>
241
242     <presentation>
243         <p-step>
244             <title>Host</title>
245             <p-group>
246                 <title>Host selection</title>
247                 <desc>Select if you want ot choose host from a list or enter a name or IP address</desc>
248                 <p-param name="hostNameOrIP">
249                     <desc>Host name or IP  of the SSH host</desc>
250                     <p-qual kind="static" name="mandatory" type="boolean">true</p-qual>
251                 </p-param>
252             </p-group>
253             <p-group>
254                 <title>Command</title>
255                 <desc>The command to execute</desc>
256                 <p-param name="cmd">
257                     <desc>The SSH command to run</desc>
258                     <p-qual name="defaultValue" type="string">uptime</p-qual>
259                 </p-param>
260             </p-group>
261             <p-group>
262                 <title>Authentication</title>
263                 <p-param name="passwordAuthentication">
264                     <desc>Do you want to use password authentication? If you click No, key file authentication will be used.</desc>
265                 </p-param>
266             </p-group>
267         </p-step>
268         <p-step>
269             <title>Authentication</title>
270             <p-group>
271                 <title>Host</title>
272                 <desc>Enter connection info for host to execute the command on</desc>
273                 <p-param name="username">
274                     <desc>Username</desc>
275                 </p-param>
276             </p-group>
277             <p-group>
278                 <title>Authentication</title>
279                 <desc>If authentication method is password enter the password, otherwise enter the path for the key pair and passphrase for the private key</desc>
280                 <p-param name="password">
281                     <desc>Password</desc>
282                     <p-qual name="visible">passwordAuthentication/passwordAuthentication</p-qual>
283                 </p-param>
284                 <p-param name="path">
285                     <desc>Path to private key</desc>
286                     <p-qual name="notVisible">passwordAuthentication/passwordAuthentication</p-qual>
287                     <p-qual kind="ognl" name="defaultValue" type="Path">#defaultKeyPairPath</p-qual>
288                 </p-param>
289                 <p-param name="passphrase">
290                     <desc>Private key pass-phrase</desc>
291                     <p-qual name="notVisible">passwordAuthentication/passwordAuthentication</p-qual>
292                 </p-param>
293             </p-group>
294         </p-step>
295     </presentation>
296 </workflow>