# home directory at Linux host
self._home_dir = ""
- # list of pids before running the app if the user is root
- self._pids = []
-
# lock to prevent concurrent applications on the same node,
# to execute commands at the same time. There are potential
# concurrency issues when using SSH to a same host from
"sudo -S kill $(ps aux | grep '[n]epi' | awk '{print $2}') || /bin/true ; " +
"sudo -S killall -u %s || /bin/true ; " % self.get("username"))
else:
- pids_temp = []
if self.state >= ResourceState.READY:
- ps_aux = "ps aux |awk '{print $2}' |sort -u"
+ import pickle
+ pids = pickle.load(open("/tmp/save.proc", "rb"))
+ pids_temp = dict()
+ ps_aux = "ps aux |awk '{print $2,$11}'"
(out, err), proc = self.execute(ps_aux)
- pids_temp = out.split()
- kill_pids = list(set(pids_temp) - set(self._pids))
- kill_pids = ' '.join(kill_pids)
+ for line in out.strip().split("\n"):
+ parts = line.strip().split(" ")
+ pids_temp[parts[0]] = parts[1]
+ kill_pids = set(pids_temp.items()) - set(pids.items())
+ kill_pids = ' '.join(dict(kill_pids).keys())
cmd = ("killall tcpdump || /bin/true ; " +
"kill $(ps aux | grep '[n]epi' | awk '{print $2}') || /bin/true ; " +
def upload(self, src, dst, text = False, overwrite = True):
""" Copy content to destination
- src content to copy. Can be a local file, directory or a list of files
+ src string with the content to copy. Can be:
+ - plain text
+ - a string with the path to a local file
+ - a string with a semi-colon separeted list of local files
+ - a string with a local directory
- dst destination path on the remote host (remote is always self.host)
+ dst string with destination path on the remote host (remote is
+ always self.host)
- text src is text input, it must be stored into a temp file before uploading
+ text src is text input, it must be stored into a temp file before
+ uploading
"""
# If source is a string input
f = None
src = f.name
# If dst files should not be overwritten, check that the files do not
- # exits already
+ # exits already
+ if isinstance(src, str):
+ src = map(str.strip, src.split(";"))
+
if overwrite == False:
src = self.filter_existing_files(src, dst)
if not src:
- return ("", ""), None
+ return ("", ""), None
if not self.localhost:
# Build destination as <user>@<server>:<path>
""" Removes files that already exist in the Linux host from src list
"""
# construct a dictionary with { dst: src }
- dests = dict(map(lambda x: ( os.path.join(dst, os.path.basename(x) ), x ),
- src.strip().split(" ") ) ) if src.strip().find(" ") != -1 else dict({dst: src})
+ dests = dict(map(
+ lambda s: (os.path.join(dst, os.path.basename(s)), s ), s)) \
+ if len(src) > 1 else dict({dst: src[0]})
command = []
for d in dests.keys():
del dests[d]
if not dests:
- return ""
+ return []
- return " ".join(dests.values())
+ return dests.values()