From fe97b0a51d873d67015b752fb008d436bfeed293 Mon Sep 17 00:00:00 2001 From: Thomas S Hatch Date: Tue, 14 Oct 2014 20:26:40 -0600 Subject: [PATCH 1/2] Add -w --wipe option to salt-ssh to clear the deploy when done --- salt/client/ssh/__init__.py | 4 +++- salt/client/ssh/ssh_py_shim.py | 2 ++ salt/utils/parsers.py | 6 ++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/salt/client/ssh/__init__.py b/salt/client/ssh/__init__.py index 4e117053a2..ea3552d83a 100644 --- a/salt/client/ssh/__init__.py +++ b/salt/client/ssh/__init__.py @@ -713,13 +713,15 @@ OPTIONS.checksum = '{3}' OPTIONS.hashfunc = '{4}' OPTIONS.version = '{5}' OPTIONS.get_modules = {6} -ARGS = {7}\n'''.format(self.minion_config, +OPTIONS.wipe = {7} +ARGS = {8}\n'''.format(self.minion_config, RSTR, self.thin_dir, thin_sum, 'sha1', salt.__version__, 'True' if self.mods else 'False', + 'True' if self.opts.get('wipe_ssh') else 'False', self.argv) py_code = SSH_PY_SHIM.replace('#%%OPTS', arg_str) py_code_enc = py_code.encode('base64').replace('\n', '_') diff --git a/salt/client/ssh/ssh_py_shim.py b/salt/client/ssh/ssh_py_shim.py index da23577525..fd5b3eefce 100644 --- a/salt/client/ssh/ssh_py_shim.py +++ b/salt/client/ssh/ssh_py_shim.py @@ -176,6 +176,8 @@ def main(argv): sys.stderr.write(OPTIONS.delimiter + '\n') sys.stderr.flush() os.execv(sys.executable, salt_argv) + if OPTIONS.wipe: + shutil.rmtree(OPTIONS.saltdir) if __name__ == '__main__': sys.exit(main(sys.argv)) diff --git a/salt/utils/parsers.py b/salt/utils/parsers.py index 0b0888cff0..c2c3972681 100644 --- a/salt/utils/parsers.py +++ b/salt/utils/parsers.py @@ -2190,6 +2190,12 @@ class SaltSSHOptionParser(OptionParser, ConfigDirMixIn, MergeConfigMixIn, help=('Return the data from minions as a group after they ' 'all return.') ) + self.add_option( + '-w', '--wipe', + default=False, + dest='wipe_ssh', + help='Remove the deployment of the salt files when done executing.', + ) auth_group = optparse.OptionGroup( self, 'Authentication Options', From c15231d9c09fdb1a068bbeacf973127704e4a318 Mon Sep 17 00:00:00 2001 From: Thomas S Hatch Date: Tue, 14 Oct 2014 20:52:08 -0600 Subject: [PATCH 2/2] Need to use subprocess if wipeing --- salt/client/ssh/ssh_py_shim.py | 5 ++++- salt/utils/parsers.py | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/salt/client/ssh/ssh_py_shim.py b/salt/client/ssh/ssh_py_shim.py index fd5b3eefce..5cc643b24f 100644 --- a/salt/client/ssh/ssh_py_shim.py +++ b/salt/client/ssh/ssh_py_shim.py @@ -175,9 +175,12 @@ def main(argv): sys.stdout.flush() sys.stderr.write(OPTIONS.delimiter + '\n') sys.stderr.flush() - os.execv(sys.executable, salt_argv) if OPTIONS.wipe: + import subprocess + subprocess.call(salt_argv) shutil.rmtree(OPTIONS.saltdir) + else: + os.execv(sys.executable, salt_argv) if __name__ == '__main__': sys.exit(main(sys.argv)) diff --git a/salt/utils/parsers.py b/salt/utils/parsers.py index c2c3972681..645a8686fc 100644 --- a/salt/utils/parsers.py +++ b/salt/utils/parsers.py @@ -2193,6 +2193,7 @@ class SaltSSHOptionParser(OptionParser, ConfigDirMixIn, MergeConfigMixIn, self.add_option( '-w', '--wipe', default=False, + action='store_true', dest='wipe_ssh', help='Remove the deployment of the salt files when done executing.', )