code: def _connect_to_gateway(self):
          
          for key in self.ssh_pkeys:
              self.logger.debug('Trying to log in with key: {0}'
                                .format(hexlify(key.get_fingerprint())))
              try:
                  self._transport = self._get_transport()
                  self._transport.connect(hostkey=self.ssh_host_key,
                                          username=self.ssh_username,
                                          pkey=key)
                  if self._transport.is_alive:
                      return
              except paramiko.AuthenticationException:
                  self.logger.debug('Authentication error')
                  self._stop_transport()
  
          if self.ssh_password:  # avoid conflict using both pass and pkey
              self.logger.debug('Trying to log in with password: {0}'
                                .format('*' * len(self.ssh_password)))
              try:
                  self._transport = self._get_transport()
                  self._transport.connect(hostkey=self.ssh_host_key,
                                          username=self.ssh_username,
                                          password=self.ssh_password)
                  if self._transport.is_alive:
                      return
              except paramiko.AuthenticationException:
                  self.logger.debug('Authentication error')
                  self._stop_transport()
  
          self.logger.error('Could not open connection to gateway')
docs: Open connection to SSH gateway
           - First try with all keys loaded from an SSH agent (if allowed)
           - Then with those passed directly or read from ~/.ssh/config
           - As last resort, try with a provided password