From bb43a8f47f4436d424b4b4ba8eda6e7fabc0245f Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Sun, 6 Mar 2016 08:20:16 +0100 Subject: [PATCH 1/9] Add ssh multiplexing options to default REMOTE_EXEC and REMOTE_COPY. --- cdist/__init__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cdist/__init__.py b/cdist/__init__.py index 4454a3ac..28464710 100644 --- a/cdist/__init__.py +++ b/cdist/__init__.py @@ -41,8 +41,10 @@ BANNER = """ "P' "" "" """ -REMOTE_COPY = "scp -o User=root -q" -REMOTE_EXEC = "ssh -o User=root -q" +SSH_MUX_OPTS = ("-o ControlPath=~/.ssh/master-%l-%r@%h:%p" + " -o ControlMaster=auto -o ControlPersist=125") +REMOTE_COPY = "scp -o User=root -q " + SSH_MUX_OPTS +REMOTE_EXEC = "ssh -o User=root -q " + SSH_MUX_OPTS class Error(Exception): """Base exception class for this project""" From 2dfc30e3c45bda3cd5737d3b6064008256cd0d9b Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Thu, 10 Mar 2016 20:01:08 +0100 Subject: [PATCH 2/9] Revert "Add ssh multiplexing options to default REMOTE_EXEC and REMOTE_COPY." This reverts commit bb43a8f47f4436d424b4b4ba8eda6e7fabc0245f. --- cdist/__init__.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/cdist/__init__.py b/cdist/__init__.py index 28464710..4454a3ac 100644 --- a/cdist/__init__.py +++ b/cdist/__init__.py @@ -41,10 +41,8 @@ BANNER = """ "P' "" "" """ -SSH_MUX_OPTS = ("-o ControlPath=~/.ssh/master-%l-%r@%h:%p" - " -o ControlMaster=auto -o ControlPersist=125") -REMOTE_COPY = "scp -o User=root -q " + SSH_MUX_OPTS -REMOTE_EXEC = "ssh -o User=root -q " + SSH_MUX_OPTS +REMOTE_COPY = "scp -o User=root -q" +REMOTE_EXEC = "ssh -o User=root -q" class Error(Exception): """Base exception class for this project""" From 215e58eb388662945178bdf6f168b3bb46f589e9 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Thu, 10 Mar 2016 20:20:41 +0100 Subject: [PATCH 3/9] Inspect and add by default ssh multiplexing options. --- scripts/cdist | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/scripts/cdist b/scripts/cdist index 39449666..d5737f9c 100755 --- a/scripts/cdist +++ b/scripts/cdist @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- # # 2010-2013 Nico Schottelius (nico-cdist at schottelius.org) +# 2016 Darko Poljak (darko.poljak at gmail.com) # # This file is part of cdist. # @@ -20,6 +21,32 @@ # # +def inspect_ssh_mux_opts(): + """Inspect whether or not ssh supports multiplexing options""" + wanted_mux_opts = { + "ControlPath":"~/.ssh/master-%l-%r@%h:%p", + "ControlMaster":"auto", + "ControlPersist":"125", + } + # if checked key option is present then this assumes + # all options in value are present + check = { + "ControlMaster": ("ControlMaster", "ControlPath"), + "ControlPersist": ("ControlPersist",), + } + mux_opts = {} + for x in check: + try: + subprocess.check_output("ssh -o {}".format(x), + stderr=subprocess.STDOUT) + except subprocess.CalledProcessError as e: + foo = e.output.decode().lower() + if not "bad configuration option" in foo: + for o in check[x]: + mux_opts[o] = wanted_mux_opts[o] + foo = ["-o {}={}".format(x, mux_opts[x]) for x in mux_opts] + return " ".join(foo) + def commandline(): """Parse command line""" import argparse @@ -53,6 +80,11 @@ def commandline(): parser['banner'].set_defaults(func=cdist.banner.banner) # Config + # inspect multiplexing options for default remote copy/exec scp/ssh + MUX_OPTS = inspect_ssh_mux_opts() + cdist.REMOTE_EXEC += MUX_OPTS + cdist.REMOTE_COPY += MUX_OPTS + parser['config'] = parser['sub'].add_parser('config', parents=[parser['loglevel']]) parser['config'].add_argument('host', nargs='+', From b4ac23b4f81aea4ae00f77705100d498494f8ed7 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Thu, 10 Mar 2016 20:40:37 +0100 Subject: [PATCH 4/9] Default ssh mux options fixes. --- scripts/cdist | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/cdist b/scripts/cdist index d5737f9c..8aa998d2 100755 --- a/scripts/cdist +++ b/scripts/cdist @@ -22,6 +22,8 @@ # def inspect_ssh_mux_opts(): + import subprocess + """Inspect whether or not ssh supports multiplexing options""" wanted_mux_opts = { "ControlPath":"~/.ssh/master-%l-%r@%h:%p", @@ -38,13 +40,13 @@ def inspect_ssh_mux_opts(): for x in check: try: subprocess.check_output("ssh -o {}".format(x), - stderr=subprocess.STDOUT) + stderr=subprocess.STDOUT, shell=True) except subprocess.CalledProcessError as e: foo = e.output.decode().lower() if not "bad configuration option" in foo: for o in check[x]: mux_opts[o] = wanted_mux_opts[o] - foo = ["-o {}={}".format(x, mux_opts[x]) for x in mux_opts] + foo = [" -o {}={}".format(x, mux_opts[x]) for x in mux_opts] return " ".join(foo) def commandline(): From 8ed0c672b14f2fcb642c7511d64d839651049c59 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Fri, 11 Mar 2016 19:23:59 +0100 Subject: [PATCH 5/9] Fix error with args. --- cdist/exec/local.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdist/exec/local.py b/cdist/exec/local.py index 40f34e25..5aadce0c 100644 --- a/cdist/exec/local.py +++ b/cdist/exec/local.py @@ -195,7 +195,7 @@ class Local(object): except subprocess.CalledProcessError: raise cdist.Error("Command failed: " + " ".join(command)) except OSError as error: - raise cdist.Error(" ".join(*args) + ": " + error.args[1]) + raise cdist.Error(" ".join((str(x) for x in error.args))) finally: if message_prefix: message.merge_messages() From 3ae042f2cd9d468ce607344fe673cd90c0036d55 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Fri, 18 Mar 2016 12:27:23 +0100 Subject: [PATCH 6/9] Rverting manually (limited connectivity) to original. Will be fixed in a separate branch. --- cdist/exec/local.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdist/exec/local.py b/cdist/exec/local.py index 5aadce0c..dc7c02bc 100644 --- a/cdist/exec/local.py +++ b/cdist/exec/local.py @@ -195,7 +195,7 @@ class Local(object): except subprocess.CalledProcessError: raise cdist.Error("Command failed: " + " ".join(command)) except OSError as error: - raise cdist.Error(" ".join((str(x) for x in error.args))) + raise cdist.Error(" ".join(*args) + ": " + error.args[1]) finally: if message_prefix: message.merge_messages() From 6ae94df0a194e6314f3296567363ddb4987ec933 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Fri, 18 Mar 2016 12:29:16 +0100 Subject: [PATCH 7/9] Reset manually to original. Limited connectivity, but have extra time, so doing it online. Will be fixed in a separate branch. --- cdist/exec/local.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdist/exec/local.py b/cdist/exec/local.py index dc7c02bc..40f34e25 100644 --- a/cdist/exec/local.py +++ b/cdist/exec/local.py @@ -195,7 +195,7 @@ class Local(object): except subprocess.CalledProcessError: raise cdist.Error("Command failed: " + " ".join(command)) except OSError as error: - raise cdist.Error(" ".join(*args) + ": " + error.args[1]) + raise cdist.Error(" ".join(*args) + ": " + error.args[1]) finally: if message_prefix: message.merge_messages() From 4851197de2e4eb0657dfa5557edf3d5ca4030c0b Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Fri, 18 Mar 2016 12:31:06 +0100 Subject: [PATCH 8/9] Reseting to original manually (limited connect). Limited connectivity, but have extra time, so reseting this to original. This new feature will be implemented in separate branch. --- scripts/cdist | 34 ---------------------------------- 1 file changed, 34 deletions(-) diff --git a/scripts/cdist b/scripts/cdist index 8aa998d2..39449666 100755 --- a/scripts/cdist +++ b/scripts/cdist @@ -2,7 +2,6 @@ # -*- coding: utf-8 -*- # # 2010-2013 Nico Schottelius (nico-cdist at schottelius.org) -# 2016 Darko Poljak (darko.poljak at gmail.com) # # This file is part of cdist. # @@ -21,34 +20,6 @@ # # -def inspect_ssh_mux_opts(): - import subprocess - - """Inspect whether or not ssh supports multiplexing options""" - wanted_mux_opts = { - "ControlPath":"~/.ssh/master-%l-%r@%h:%p", - "ControlMaster":"auto", - "ControlPersist":"125", - } - # if checked key option is present then this assumes - # all options in value are present - check = { - "ControlMaster": ("ControlMaster", "ControlPath"), - "ControlPersist": ("ControlPersist",), - } - mux_opts = {} - for x in check: - try: - subprocess.check_output("ssh -o {}".format(x), - stderr=subprocess.STDOUT, shell=True) - except subprocess.CalledProcessError as e: - foo = e.output.decode().lower() - if not "bad configuration option" in foo: - for o in check[x]: - mux_opts[o] = wanted_mux_opts[o] - foo = [" -o {}={}".format(x, mux_opts[x]) for x in mux_opts] - return " ".join(foo) - def commandline(): """Parse command line""" import argparse @@ -82,11 +53,6 @@ def commandline(): parser['banner'].set_defaults(func=cdist.banner.banner) # Config - # inspect multiplexing options for default remote copy/exec scp/ssh - MUX_OPTS = inspect_ssh_mux_opts() - cdist.REMOTE_EXEC += MUX_OPTS - cdist.REMOTE_COPY += MUX_OPTS - parser['config'] = parser['sub'].add_parser('config', parents=[parser['loglevel']]) parser['config'].add_argument('host', nargs='+', From 5e5106479f55a184fff67ee89e3530680f8a9ec0 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Fri, 18 Mar 2016 18:22:14 +0100 Subject: [PATCH 9/9] Fix old bug: join wrong arg for OSError. --- cdist/exec/local.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdist/exec/local.py b/cdist/exec/local.py index 40f34e25..0be803a9 100644 --- a/cdist/exec/local.py +++ b/cdist/exec/local.py @@ -195,7 +195,7 @@ class Local(object): except subprocess.CalledProcessError: raise cdist.Error("Command failed: " + " ".join(command)) except OSError as error: - raise cdist.Error(" ".join(*args) + ": " + error.args[1]) + raise cdist.Error(" ".join(command) + ": " + error.args[1]) finally: if message_prefix: message.merge_messages()