forked from distributed-system-analysis/smallfile
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ssh_thread.py
35 lines (26 loc) · 1.1 KB
/
ssh_thread.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# -*- coding: utf-8 -*-
'''
ssh_thread.py -- manages parallel execution of shell commands on remote hosts
Copyright 2012 -- Ben England
Licensed under the Apache License at http://www.apache.org/licenses/LICENSE-2.0
See Appendix on this page for instructions pertaining to license.
'''
import threading
import os
# this class is just used to create a python thread
# for each remote host that we want to use as a workload generator
# the thread just executes an ssh command to run this program on a remote host
class ssh_thread(threading.Thread):
ssh_prefix = 'ssh -x -o StrictHostKeyChecking=no '
def __str__(self):
return 'ssh-thread:%s:%s:%s' % \
(self.remote_host, str(self.status), self.remote_cmd)
def __init__(self, remote_host, remote_cmd_in):
threading.Thread.__init__(self)
self.remote_host = remote_host
self.remote_cmd = '%s %s "%s"' % \
(self.ssh_prefix, self.remote_host, remote_cmd_in)
# print('thread cmd %s'%self.remote_cmd)
self.status = None
def run(self):
self.status = os.system(self.remote_cmd)