Beispiel #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))
Beispiel #2
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
Beispiel #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
Beispiel #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)
Beispiel #5
0
    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
Beispiel #6
0
    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
Beispiel #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)
Beispiel #8
0
 def test_connect_helper(self):
     self.assertIsInstance(ssh.connect("123.456.789.0"), ssh.SSH)
Beispiel #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)
Beispiel #10
0
def get_sshclient(*args, **kwargs):

    kwargs.setdefault('options', {})
    kwargs['options'].update({'StrictHostKeyChecking': False})
    kwargs['timeout'] = None
    return ssh.connect(*args, **kwargs)
Beispiel #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))
Beispiel #12
0
 def test_connect_helper(self):
     self.assertIsInstance(ssh.connect("123.456.789.0"), ssh.SSH)
Beispiel #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)
Beispiel #14
0
def get_sshclient(*args, **kwargs):

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