prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  linux.wait_for_ssh action improvements
  Currently `linux.wait_for_ssh` action (https://github.com/StackStorm/st2/blob/master/contrib/linux/actions/wait_for_ssh.yaml) only supports authenticating with RSA SSH key.
  
  There are multiple ways we can improve this action and make it more generic.
  - Support for other key types
  - Support for password based authentication
  - Refactor the action to utilize the new Paramiko SSH client
  - Default to using system user (stanley) username and key file. Ideally key file location should be read from the config
  
  
  </issue>
  <code>
  [start of contrib/linux/actions/wait_for_ssh.py]
  1 #!/usr/bin/env python
  2 
  3 import time
  4 
  5 import paramiko
  6 
  7 from st2actions.runners.pythonrunner import Action
  8 
  9 
  10 class BaseAction(Action):
  11     def run(self, keyfile, username, hostname, ssh_timeout, retries):
  12         key = paramiko.RSAKey.from_private_key_file(keyfile)
  13         client = paramiko.SSHClient()
  14         client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  15 
  16         for index in range(retries):
  17             attempt = index + 1
  18 
  19             try:
  20                 self.logger.debug('SSH connection attempt: %s' % (attempt))
  21                 client.connect(hostname=hostname, username=username, pkey=key)
  22                 return True
  23             except Exception as e:
  24                 self.logger.info('Attempt %s failed (%s), sleeping...' % (attempt, str(e)))
  25                 time.sleep(ssh_timeout)
  26 
  27         raise Exception('Exceeded max retries (%s)' % (retries))
  28
  [end of contrib/linux/actions/wait_for_ssh.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/contrib/linux/actions/wait_for_ssh.py b/contrib/linux/actions/wait_for_ssh.py
  --- a/contrib/linux/actions/wait_for_ssh.py
  +++ b/contrib/linux/actions/wait_for_ssh.py
  @@ -2,26 +2,36 @@
   
   import time
   
  -import paramiko
  +from oslo_config import cfg
   
   from st2actions.runners.pythonrunner import Action
  +from st2actions.runners.ssh.paramiko_ssh import ParamikoSSHClient
   
   
   class BaseAction(Action):
  -    def run(self, keyfile, username, hostname, ssh_timeout, retries):
  -        key = paramiko.RSAKey.from_private_key_file(keyfile)
  -        client = paramiko.SSHClient()
  -        client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  +    def run(self, hostname, port, username, password=None, keyfile=None, ssh_timeout=5,
  +            sleep_delay=20, retries=10):
  +        # Note: If neither password nor key file is provided, we try to use system user
  +        # key file
  +        if not password and not keyfile:
  +            keyfile = cfg.CONF.system_user.ssh_key_file
  +            self.logger.info('Neither "password" nor "keyfile" parameter provided, '
  +                             'defaulting to using "%s" key file' % (keyfile))
  +
  +        client = ParamikoSSHClient(hostname=hostname, port=port, username=username,
  +                                   password=password, key_files=keyfile,
  +                                   timeout=ssh_timeout)
   
           for index in range(retries):
               attempt = index + 1
   
               try:
                   self.logger.debug('SSH connection attempt: %s' % (attempt))
  -                client.connect(hostname=hostname, username=username, pkey=key)
  +                client.connect()
                   return True
               except Exception as e:
  -                self.logger.info('Attempt %s failed (%s), sleeping...' % (attempt, str(e)))
  -                time.sleep(ssh_timeout)
  +                self.logger.info('Attempt %s failed (%s), sleeping for %s seconds...' %
  +                                 (attempt, str(e), sleep_delay))
  +                time.sleep(sleep_delay)
   
           raise Exception('Exceeded max retries (%s)' % (retries))
  
verification_info: {"golden_diff": "diff --git a/contrib/linux/actions/wait_for_ssh.py b/contrib/linux/actions/wait_for_ssh.py\n--- a/contrib/linux/actions/wait_for_ssh.py\n+++ b/contrib/linux/actions/wait_for_ssh.py\n@@ -2,26 +2,36 @@\n \n import time\n \n-import paramiko\n+from oslo_config import cfg\n \n from st2actions.runners.pythonrunner import Action\n+from st2actions.runners.ssh.paramiko_ssh import ParamikoSSHClient\n \n \n class BaseAction(Action):\n-    def run(self, keyfile, username, hostname, ssh_timeout, retries):\n-        key = paramiko.RSAKey.from_private_key_file(keyfile)\n-        client = paramiko.SSHClient()\n-        client.set_missing_host_key_policy(paramiko.AutoAddPolicy())\n+    def run(self, hostname, port, username, password=None, keyfile=None, ssh_timeout=5,\n+            sleep_delay=20, retries=10):\n+        # Note: If neither password nor key file is provided, we try to use system user\n+        # key file\n+        if not password and not keyfile:\n+            keyfile = cfg.CONF.system_user.ssh_key_file\n+            self.logger.info('Neither \"password\" nor \"keyfile\" parameter provided, '\n+                             'defaulting to using \"%s\" key file' % (keyfile))\n+\n+        client = ParamikoSSHClient(hostname=hostname, port=port, username=username,\n+                                   password=password, key_files=keyfile,\n+                                   timeout=ssh_timeout)\n \n         for index in range(retries):\n             attempt = index + 1\n \n             try:\n                 self.logger.debug('SSH connection attempt: %s' % (attempt))\n-                client.connect(hostname=hostname, username=username, pkey=key)\n+                client.connect()\n                 return True\n             except Exception as e:\n-                self.logger.info('Attempt %s failed (%s), sleeping...' % (attempt, str(e)))\n-                time.sleep(ssh_timeout)\n+                self.logger.info('Attempt %s failed (%s), sleeping for %s seconds...' %\n+                                 (attempt, str(e), sleep_delay))\n+                time.sleep(sleep_delay)\n \n         raise Exception('Exceeded max retries (%s)' % (retries))\n", "issue": "linux.wait_for_ssh action improvements\nCurrently `linux.wait_for_ssh` action (https://github.com/StackStorm/st2/blob/master/contrib/linux/actions/wait_for_ssh.yaml) only supports authenticating with RSA SSH key.\n\nThere are multiple ways we can improve this action and make it more generic.\n- Support for other key types\n- Support for password based authentication\n- Refactor the action to utilize the new Paramiko SSH client\n- Default to using system user (stanley) username and key file. Ideally key file location should be read from the config\n\n", "before_files": [{"content": "#!/usr/bin/env python\n\nimport time\n\nimport paramiko\n\nfrom st2actions.runners.pythonrunner import Action\n\n\nclass BaseAction(Action):\n    def run(self, keyfile, username, hostname, ssh_timeout, retries):\n        key = paramiko.RSAKey.from_private_key_file(keyfile)\n        client = paramiko.SSHClient()\n        client.set_missing_host_key_policy(paramiko.AutoAddPolicy())\n\n        for index in range(retries):\n            attempt = index + 1\n\n            try:\n                self.logger.debug('SSH connection attempt: %s' % (attempt))\n                client.connect(hostname=hostname, username=username, pkey=key)\n                return True\n            except Exception as e:\n                self.logger.info('Attempt %s failed (%s), sleeping...' % (attempt, str(e)))\n                time.sleep(ssh_timeout)\n\n        raise Exception('Exceeded max retries (%s)' % (retries))\n", "path": "contrib/linux/actions/wait_for_ssh.py"}]}