Class SshTemplate

  extended by sunlabs.brazil.template.Template
      extended by sunlabs.brazil.ssh.SshTemplate (view source)
All Implemented Interfaces:

public class SshTemplate
extends Template

Template to start an ssh connecton to a server.

Constructor Summary
Method Summary
 void close(String id)
 void tag_ssh(RewriteContext hr)
          Simple version: one connection per session, no port forwarding.
 void tag_sshcommand(RewriteContext hr)
          Run a command synchronously from an existing ssh connection.
Methods inherited from class sunlabs.brazil.template.Template
done, init
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail


public SshTemplate()
Method Detail


public void tag_ssh(RewriteContext hr)
Simple version: one connection per session, no port forwarding. This implements the ssh tag:
   user=xx host=xx pass=xx [key=xx id=xx] stdinQ=xx stdoutQ=xx
   unbuffered=true|false] />
 <ssh close="x" />
   user=xx host=xx pass=xx [key=xxx id=xx] stdinQ=xx stdoutQ=xx
   unbuffered=true|false] />
Alternately, one a connection is opened (using defer=true) Commands may by run synchronously, and have their output captured in the variables "stdout" and "stderr".
 <ssh id=xx user=xx host=xx pass=xx [key=xx] defer=true>
 <sshcommand  id=xx command=xx [stdin=xx]>
 <ssh close=xx>
Tag attributes:
The host to ssh to
The server port (defaults to 22)
The user name
The user's password, if using password authentication, or the password for the private key if "key" is specified.
The user's private key, in PEM format. If "key" is provided, the "pass" option (if any) is used to decrypt "key". If no key is provided, then password based authentication using "user" and "pass" is attempted instead.
A unique identifier for this session. This value will be present in all Q'd output, enabling multiple sessions to share the same output Q's.
If specified, this command is run on the remote side, otherwise an interactive shell is created.
The Queues (See QueueTemplate) to use to communicate with the ssh streams. The stderr/stdout of the ssh connection is sent to the "stdOutQ", and is accessible using <dequeue name=[stdOutQ]>. the output will be in the queue element "line". Data can be sent to the stdin of the ssh connection with: <enqueue name=[stdinQ] data="line ..." />
by default, the "stderr" from the ssh stream is unbuffered, and the "stdout" stream is line buffered. Setting "unbuffered" to true sets stderr to unbuffered as well.
close=[id] The connection specified by "id" (if any) is closed. When "close" is specified, all other parameters are ignored.

If authentication failed, the property [id].error is set. When ssh terminates, the "error" property of queue entry is set. See also the example included with the distribution.


public void tag_sshcommand(RewriteContext hr)
Run a command synchronously from an existing ssh connection.
 <sshcommand id=xxx command=xxx [stdin=xxx timeout=sec]>.
The "Command" is run against "id" (created with <ssh ...>). If "stdin" is supplied, it is sent to the stdin of the command. The command is run to completion, and the results are placed into the variables "stdout", "stderr", "status" and (sometime) error. Don't forget to run "<ssh close=id>" when done with this connection.


public void close(String id)

Version Kenai-svn-r24, Generated 08/18/09
Copyright (c) 2001-2009, Sun Microsystems.