예제 #1
0
 def test_throws_typeerror_well_with_message(self):
     try:
         ssh.connect("123.456.789.0", invalidkey="bad")
     except TypeError as exc:
         self.assertEqual(
             "connect() got an unexpected keyword "
             "argument 'invalidkey'", str(exc))
예제 #2
0
파일: bash.py 프로젝트: gondoi/satori
    def __init__(self, address, **kwargs):
        """An interface for executing shell commands on remote machines.

        :param str host:        The ip address or host name of the server
                                to connect to
        :param str password:    A password to use for authentication
                                or for unlocking a private key
        :param username:        The username to authenticate as
        :param private_key:     Private SSH Key string to use
                                (instead of using a filename)
        :param key_filename:    a private key filename (path)
        :param port:            tcp/ip port to use (defaults to 22)
        :param float timeout:   an optional timeout (in seconds) for the
                                TCP connection
        :param socket proxy:    an existing SSH instance to use
                                for proxying
        :param dict options:    A dictionary used to set ssh options
                                (when proxying).
                                e.g. for `ssh -o StrictHostKeyChecking=no`,
                                you would provide
                                (.., options={'StrictHostKeyChecking': 'no'})
                                Conversion of booleans is also supported,
                                (.., options={'StrictHostKeyChecking': False})
                                is equivalent.
        :keyword interactive:   If true, prompt for password if missing.
        """
        self.sshclient = ssh.connect(address, **kwargs)
        self.host = self.sshclient.host
        self.port = self.sshclient.port
예제 #3
0
    def __init__(self, address, **kwargs):
        """An interface for executing shell commands on remote machines.

        :param str host:        The ip address or host name of the server
                                to connect to
        :param str password:    A password to use for authentication
                                or for unlocking a private key
        :param username:        The username to authenticate as
        :param private_key:     Private SSH Key string to use
                                (instead of using a filename)
        :param key_filename:    a private key filename (path)
        :param port:            tcp/ip port to use (defaults to 22)
        :param float timeout:   an optional timeout (in seconds) for the
                                TCP connection
        :param socket proxy:    an existing SSH instance to use
                                for proxying
        :param dict options:    A dictionary used to set ssh options
                                (when proxying).
                                e.g. for `ssh -o StrictHostKeyChecking=no`,
                                you would provide
                                (.., options={'StrictHostKeyChecking': 'no'})
                                Conversion of booleans is also supported,
                                (.., options={'StrictHostKeyChecking': False})
                                is equivalent.
        :keyword interactive:   If true, prompt for password if missing.
        """
        self.sshclient = ssh.connect(address, **kwargs)
        self.host = self.sshclient.host
        self.port = self.sshclient.port
예제 #4
0
 def test_adds_missing_host_key(self, mock_LOG):
     client = ssh.connect("123.456.789.0",
                          options={'StrictHostKeyChecking': 'no'})
     client._connect()
     pkey = ssh.make_pkey(self.rsakey)
     client._policy.missing_host_key(client, "123.456.789.0", pkey)
     expected = {'123.456.789.0': {'ssh-rsa': pkey}}
     self.assertEqual(expected, client._host_keys)
예제 #5
0
파일: bash.py 프로젝트: mgeisler/satori
    def __init__(self, address, password=None, username=None,
                 private_key=None, key_filename=None, port=None,
                 timeout=None, gateway=None, options=None, interactive=False,
                 protocol='ssh', root_password=None, **kwargs):
        """An interface for executing shell commands on remote machines.

        :param str host:        The ip address or host name of the server
                                to connect to
        :param str password:    A password to use for authentication
                                or for unlocking a private key
        :param username:        The username to authenticate as
        :param private_key:     Private SSH Key string to use
                                (instead of using a filename)
        :param root_password:   root user password to be used if username is
                                not root. This will use username and password
                                to login and then 'su' to root using
                                root_password
        :param key_filename:    a private key filename (path)
        :param port:            tcp/ip port to use (defaults to 22)
        :param float timeout:   an optional timeout (in seconds) for the
                                TCP connection
        :param socket gateway:  an existing SSH instance to use
                                for proxying
        :param dict options:    A dictionary used to set ssh options
                                (when proxying).
                                e.g. for `ssh -o StrictHostKeyChecking=no`,
                                you would provide
                                (.., options={'StrictHostKeyChecking': 'no'})
                                Conversion of booleans is also supported,
                                (.., options={'StrictHostKeyChecking': False})
                                is equivalent.
        :keyword interactive:   If true, prompt for password if missing.
        """
        if kwargs:
            LOG.warning("Satori RemoteClient received unrecognized "
                        "keyword arguments: %s", kwargs.keys())

        if protocol == 'smb':
            self._client = smb.connect(address, password=password,
                                       username=username,
                                       port=port, timeout=timeout,
                                       gateway=gateway)
        else:
            self._client = ssh.connect(address, password=password,
                                       username=username,
                                       private_key=private_key,
                                       key_filename=key_filename,
                                       port=port, timeout=timeout,
                                       gateway=gateway,
                                       options=options,
                                       interactive=interactive,
                                       root_password=root_password)
        self.host = self._client.host
        self.port = self._client.port
예제 #6
0
파일: bash.py 프로젝트: jmikedupont/satori
    def __init__(self, address, password=None, username=None,
                 private_key=None, key_filename=None, port=None,
                 timeout=None, gateway=None, options=None, interactive=False,
                 protocol='ssh', root_password=None, **kwargs):
        """An interface for executing shell commands on remote machines.

        :param str host:        The ip address or host name of the server
                                to connect to
        :param str password:    A password to use for authentication
                                or for unlocking a private key
        :param username:        The username to authenticate as
        :param private_key:     Private SSH Key string to use
                                (instead of using a filename)
        :param root_password:   root user password to be used if username is
                                not root. This will use username and password
                                to login and then 'su' to root using
                                root_password
        :param key_filename:    a private key filename (path)
        :param port:            tcp/ip port to use (defaults to 22)
        :param float timeout:   an optional timeout (in seconds) for the
                                TCP connection
        :param socket gateway:  an existing SSH instance to use
                                for proxying
        :param dict options:    A dictionary used to set ssh options
                                (when proxying).
                                e.g. for `ssh -o StrictHostKeyChecking=no`,
                                you would provide
                                (.., options={'StrictHostKeyChecking': 'no'})
                                Conversion of booleans is also supported,
                                (.., options={'StrictHostKeyChecking': False})
                                is equivalent.
        :keyword interactive:   If true, prompt for password if missing.
        """
        if kwargs:
            LOG.warning("Satori RemoteClient received unrecognized "
                        "keyword arguments: %s", kwargs.keys())

        if protocol == 'smb':
            self._client = smb.connect(address, password=password,
                                       username=username,
                                       port=port, timeout=timeout,
                                       gateway=gateway)
        else:
            self._client = ssh.connect(address, password=password,
                                       username=username,
                                       private_key=private_key,
                                       key_filename=key_filename,
                                       port=port, timeout=timeout,
                                       gateway=gateway,
                                       options=options,
                                       interactive=interactive,
                                       root_password=root_password)
        self.host = self._client.host
        self.port = self._client.port
예제 #7
0
 def test_adds_missing_host_key(self, mock_LOG):
     client = ssh.connect(
         "123.456.789.0", options={'StrictHostKeyChecking': 'no'})
     client._connect()
     pkey = ssh.make_pkey(self.rsakey)
     client._policy.missing_host_key(
         client,
         "123.456.789.0",
         pkey)
     expected = {'123.456.789.0': {
                 'ssh-rsa': pkey}}
     self.assertEqual(expected, client._host_keys)
예제 #8
0
 def test_connect_helper(self):
     self.assertIsInstance(ssh.connect("123.456.789.0"), ssh.SSH)
예제 #9
0
 def test_missing_host_key_policy(self, mock_LOG):
     client = ssh.connect("123.456.789.0",
                          options={'StrictHostKeyChecking': 'no'})
     client._connect()
     self.assertIsInstance(client._policy, ssh.AcceptMissingHostKey)
예제 #10
0
파일: tunnel.py 프로젝트: nick-o/tunnels
def get_sshclient(*args, **kwargs):

    kwargs.setdefault('options', {})
    kwargs['options'].update({'StrictHostKeyChecking': False})
    kwargs['timeout'] = None
    return ssh.connect(*args, **kwargs)
예제 #11
0
 def test_throws_typeerror_well_with_message(self):
     try:
         ssh.connect("123.456.789.0", invalidkey="bad")
     except TypeError as exc:
         self.assertEqual("connect() got an unexpected keyword "
                          "argument 'invalidkey'", str(exc))
예제 #12
0
 def test_connect_helper(self):
     self.assertIsInstance(ssh.connect("123.456.789.0"), ssh.SSH)
예제 #13
0
 def test_missing_host_key_policy(self, mock_LOG):
     client = ssh.connect(
         "123.456.789.0", options={'StrictHostKeyChecking': 'no'})
     client._connect()
     self.assertIsInstance(client._policy, ssh.AcceptMissingHostKey)
예제 #14
0
def get_sshclient(*args, **kwargs):

    kwargs.setdefault('options', {})
    kwargs['options'].update({'StrictHostKeyChecking': False})
    kwargs['timeout'] = None
    return ssh.connect(*args, **kwargs)