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
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
25
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
37 stdin, stdout, stderr = client.exec_command('ls')
38 for line in stdout:
39 print '... ' + line.strip('\n')
40 client.close()
41
42
45
46
47
48
49
50
51
52