Package osh :: Package command :: Module testssh
[frames] | no frames]

Source Code for Module osh.command.testssh

 1  # osh 
 2  # Copyright (C) Jack Orenstein <jao@geophile.com> 
 3  # 
 4  # This program is free software; you can redistribute it and/or modify 
 5  # it under the terms of the GNU General Public License as published by 
 6  # the Free Software Foundation; either version 2 of the License, or 
 7  # (at your option) any later version. 
 8  # 
 9  # This program is distributed in the hope that it will be useful, 
10  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
11  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
12  # GNU General Public License for more details. 
13  # 
14  # You should have received a copy of the GNU General Public License 
15  # along with this program; if not, write to the Free Software 
16  # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 
17   
18  """C{testssh} 
19   
20  Determines if ssh connectivity to a cluster is working.  
21  Can only be run against a cluster, e.g. C{osh @mycluster [ testssh ] $}. 
22   
23  ssh is configured correctly if each node name is printed, along with the output 
24  from the test command, C{hello}, for example:: 
25   
26      ('115', 'hello') 
27      ('116', 'hello') 
28      ('117', 'hello') 
29   
30  If your ssh agent is set up properly, then you may see some additional 
31  output the first time you contact a cluster, e.g. 
32  C{Warning: Permanently added '192.168.140.115' (RSA) to the list of known hosts.} 
33  """ 
34   
35  import os 
36   
37  import osh.args 
38  import osh.core 
39  from osh.util import ssh, remove_crlf 
40  from osh.error import stderr_handler 
41   
42  # CLI 
43 -def _testssh():
44 return _TestSSH()
45 46 # API
47 -def testssh():
48 """Determines if ssh connectivity to a cluster is working. 49 Can only be run against a cluster, e.g. C{osh(remote('mycluster', testssh()), out())}. 50 ssh is configured correctly if each node name is printed, along with the output 51 from the test command, C{hello}, e.g. C{('115', 'hello'), ('116', 'hello'), 52 ('117', 'hello')}. 53 If your ssh agent is set up properly, then you may see some additional 54 output the first time you contact a cluster, e.g. C{Warning: 55 Permanently added '192.168.140.115' (RSA) to the list of known hosts.} 56 """ 57 return _TestSSH().process_args()
58
59 -class _TestSSH(osh.core.RunLocal):
60 61 # object interface 62
63 - def __init__(self):
64 osh.core.RunLocal.__init__(self, '', (0, 0))
65 66 # BaseOp interface 67
68 - def doc(self):
69 return __doc__
70
71 - def setup(self):
72 pass
73 74 # Generator interface 75
76 - def execute(self):
77 host = self.thread_state 78 output, errors = ssh(host.user, host.identity, host.address, 'echo hello') 79 for line in output: 80 self.send(remove_crlf(line)) 81 for line in errors: 82 stderr_handler(line, self, None)
83