From 8d44cbf71dd235e8ddafde8dba82149acd4f9ee8 Mon Sep 17 00:00:00 2001 From: Yisheng Liao Date: Thu, 19 May 2016 14:56:56 -0700 Subject: [PATCH 1/4] Initialize all configurations about ssh from config file instead of passing by parameters --- .../ShellScriptHandler.yaml | 8 ++-- .../ShellScriptHandler/ShellScriptHandler.py | 39 ++----------------- 2 files changed, 7 insertions(+), 40 deletions(-) diff --git a/sample_configs/plugins/handler/ShellScriptHandler/ShellScriptHandler.yaml b/sample_configs/plugins/handler/ShellScriptHandler/ShellScriptHandler.yaml index c81afef..ebdc87d 100644 --- a/sample_configs/plugins/handler/ShellScriptHandler/ShellScriptHandler.yaml +++ b/sample_configs/plugins/handler/ShellScriptHandler/ShellScriptHandler.yaml @@ -12,16 +12,16 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # -# supported in code host_key_path: ~/.ssh/known_hosts - -# not supported in code yet port: 22 username: password: pkey: key_filename: allow_agent: yes -look_for_kets: yes +look_for_keys: yes compress: yes sock: +connect_timeout: +compress: false +command_timeout: diff --git a/src/simoorg/plugins/handler/ShellScriptHandler/ShellScriptHandler.py b/src/simoorg/plugins/handler/ShellScriptHandler/ShellScriptHandler.py index cd83889..2ad651e 100644 --- a/src/simoorg/plugins/handler/ShellScriptHandler/ShellScriptHandler.py +++ b/src/simoorg/plugins/handler/ShellScriptHandler/ShellScriptHandler.py @@ -29,11 +29,8 @@ class ShellScriptHandler(BaseHandler): """ Shell Script Handler piggybacking on paramiko SSH""" - def __init__(self, config_dir, hostname, logger_instance=None, port=22, - username=None, password=None, pkey=None, key_filename=None, - connect_timeout=None, allow_agent=True, look_for_keys=True, - compress=False, sock=None, verbose=False, debug=False, - command_timeout=None): + def __init__(self, config_dir, hostname, logger_instance=None, + verbose=False, debug=False): """ Constructor method responsible for reading the config and setting up the ssh client. @@ -41,19 +38,6 @@ def __init__(self, config_dir, hostname, logger_instance=None, port=22, config_dir - Path to config files hostname - hostname to run the handler against logger_instance - An instance of logger class - port - SSH port - username - Username to use for ssh - password - password for ssh - pkey - private ssh key - key_filename - ssh key file path - connect_timeout - Timeout for ssh connection - allow_agent set to False to disable connecting to the SSH agent - look_for_keys - set to False to disable searching for - discoverable private key files in ``~/.ssh/`` - compress - set to True to turn on compression - sock - an open socket or socket-like object - (such as a `.Channel`) to use for communication - to the target host verbose - verbosity flag debug - debug flag Raise: @@ -62,7 +46,7 @@ def __init__(self, config_dir, hostname, logger_instance=None, port=22, None """ BaseHandler.__init__(self, config_dir, hostname, - logger_instance, verbose) + logger_instance, verbose, debug=False) self.debug = debug self.verbose = verbose self.ssh_client = None @@ -75,30 +59,13 @@ def __init__(self, config_dir, hostname, logger_instance=None, port=22, paramiko.common.logging.basicConfig(level=paramiko.common.DEBUG) self.config = None self.load_config() - # initialize the config variables - self.host_key_path = None # read in yaml configuration for key, val in self.config.iteritems(): setattr(self, key, val) del self.config - # Manually listing the arguments self.hostname = hostname - self.port = port - self.username = username - self.password = password - self.pkey = pkey - self.key_filename = key_filename - self.connect_timeout = connect_timeout - self.allow_agent = allow_agent - self.look_for_keys = look_for_keys - self.compress = compress - self.sock = sock - self.verbose = verbose - self.debug = debug - self.command_timeout = command_timeout - self.logger_instance = logger_instance def authenticate(self): """ From 3774f21b8258e6edead8102d4272c841327209cc Mon Sep 17 00:00:00 2001 From: Yisheng Liao Date: Thu, 19 May 2016 15:11:04 -0700 Subject: [PATCH 2/4] fix verbose flag --- .../plugins/handler/ShellScriptHandler/ShellScriptHandler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/simoorg/plugins/handler/ShellScriptHandler/ShellScriptHandler.py b/src/simoorg/plugins/handler/ShellScriptHandler/ShellScriptHandler.py index 2ad651e..f363cce 100644 --- a/src/simoorg/plugins/handler/ShellScriptHandler/ShellScriptHandler.py +++ b/src/simoorg/plugins/handler/ShellScriptHandler/ShellScriptHandler.py @@ -46,7 +46,7 @@ def __init__(self, config_dir, hostname, logger_instance=None, None """ BaseHandler.__init__(self, config_dir, hostname, - logger_instance, verbose, debug=False) + logger_instance, verbose) self.debug = debug self.verbose = verbose self.ssh_client = None From 3a50113fd644c9b300d85efcbad43614020c22ac Mon Sep 17 00:00:00 2001 From: Yisheng Liao Date: Thu, 19 May 2016 15:12:23 -0700 Subject: [PATCH 3/4] fix indentation --- .../plugins/handler/ShellScriptHandler/ShellScriptHandler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/simoorg/plugins/handler/ShellScriptHandler/ShellScriptHandler.py b/src/simoorg/plugins/handler/ShellScriptHandler/ShellScriptHandler.py index f363cce..31ab42e 100644 --- a/src/simoorg/plugins/handler/ShellScriptHandler/ShellScriptHandler.py +++ b/src/simoorg/plugins/handler/ShellScriptHandler/ShellScriptHandler.py @@ -30,7 +30,7 @@ class ShellScriptHandler(BaseHandler): """ Shell Script Handler piggybacking on paramiko SSH""" def __init__(self, config_dir, hostname, logger_instance=None, - verbose=False, debug=False): + verbose=False, debug=False): """ Constructor method responsible for reading the config and setting up the ssh client. From 5da981ad1cf641edd47673ca4b27255e6db0e718 Mon Sep 17 00:00:00 2001 From: Yisheng Liao Date: Thu, 19 May 2016 15:32:00 -0700 Subject: [PATCH 4/4] set logger_instance also --- .../plugins/handler/ShellScriptHandler/ShellScriptHandler.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/simoorg/plugins/handler/ShellScriptHandler/ShellScriptHandler.py b/src/simoorg/plugins/handler/ShellScriptHandler/ShellScriptHandler.py index 31ab42e..3f0cfa1 100644 --- a/src/simoorg/plugins/handler/ShellScriptHandler/ShellScriptHandler.py +++ b/src/simoorg/plugins/handler/ShellScriptHandler/ShellScriptHandler.py @@ -47,6 +47,8 @@ def __init__(self, config_dir, hostname, logger_instance=None, """ BaseHandler.__init__(self, config_dir, hostname, logger_instance, verbose) + self.hostname = hostname + self.logger_instance = logger_instance self.debug = debug self.verbose = verbose self.ssh_client = None @@ -65,8 +67,6 @@ def __init__(self, config_dir, hostname, logger_instance=None, setattr(self, key, val) del self.config - self.hostname = hostname - def authenticate(self): """ Authenticate ssh connection