Package linspector :: Package lib :: Package services :: Module ssh
[hide private]
[frames] | no frames]

Source Code for Module linspector.lib.services.ssh

 1  """ 
 2  The ssh service This is for executing remote shell commands and retrieve the output. 
 3   
 4  This service is using paramiko (http://www.lag.net/paramiko/). 
 5  """ 
 6   
 7  import paramiko 
 8  import pprint 
 9  import os 
10  from service import Service 
11   
12   
13 -class SshService(Service):
14 - def __init__(self, **kwargs):
15 super(SshService, self).__init__(**kwargs) 16 17 args = self.get_arguments() 18 if "command" in args: 19 self.command = args["command"] 20 else: 21 raise Exception("There is no command argument")
22
23 - def needs_arguments(self):
24 return True
25
26 - def execute(self):
27 path = os.path.join(os.environ['HOME'], '.ssh', 'id_rsa') 28 key = paramiko.RSAKey.from_private_key_file(path) 29 30 client = paramiko.SSHClient() 31 client.get_host_keys().add('hanez.org', 'ssh-rsa', key) 32 pprint.pprint(client._host_keys) 33 34 client.connect('hanez.org', username='hanez') 35 36 #self.command.call() ist dann das: 37 stdin, stdout, stderr = client.exec_command('ls') 38 for line in stdout: 39 print '... ' + line.strip('\n') 40 client.close()
41 42
43 -def create(**kwargs):
44 return SshService(**kwargs)
45 46 # def main(): 47 # # service = SshService(parser, log, command='uptime') 48 # return 49 # 50 # if __name__ == "__main__": 51 # main() 52