tensor/objects.py
def _init_ssh(self):
        """ Configure SSH client options
        """

        self.ssh_host = self.config.get('ssh_host', self.hostname)

        self.known_hosts = self.config.get('ssh_knownhosts_file',
            self.tensor.config.get('ssh_knownhosts_file', None))

        self.ssh_keyfile = self.config.get('ssh_keyfile',
            self.tensor.config.get('ssh_keyfile', None))

        self.ssh_key = self.config.get('ssh_key',
            self.tensor.config.get('ssh_key', None))

        # Not sure why you'd bother but maybe you've got a weird policy
        self.ssh_keypass = self.config.get('ssh_keypass',
            self.tensor.config.get('ssh_keypass', None))

        self.ssh_user = self.config.get('ssh_username',
            self.tensor.config.get('ssh_username', None))

        self.ssh_password = self.config.get('ssh_password',
            self.tensor.config.get('ssh_password', None))

        self.ssh_port = self.config.get('ssh_port',
            self.tensor.config.get('ssh_port', 22))

        # Verify config to see if we're good to go

        if not (self.ssh_key or self.ssh_keyfile or self.ssh_password):
            raise Exception("To use SSH you must specify *one* of ssh_key,"
                            " ssh_keyfile or ssh_password for this source"
                            " check or globally")

        if not self.ssh_user:
            raise Exception("ssh_username must be set")

        self.ssh_keydb = []

        cHash = hashlib.sha1(':'.join((
                        self.ssh_host, self.ssh_user, str(self.ssh_port),
                        str(self.ssh_password), str(self.ssh_key),
                        str(self.ssh_keyfile)
                    )).encode()).hexdigest()

        if cHash in self.tensor.hostConnectorCache:
            self.ssh_client = self.tensor.hostConnectorCache.get(cHash)
            self.ssh_connector = False
        else:
            self.ssh_connector = True
            self.ssh_client = ssh.SSHClient(self.ssh_host, self.ssh_user,
                    self.ssh_port, password=self.ssh_password,
                    knownhosts=self.known_hosts)

            if self.ssh_keyfile:
                self.ssh_client.addKeyFile(self.ssh_keyfile, self.ssh_keypass)

            if self.ssh_key:
                self.ssh_client.addKeyString(self.ssh_key, self.ssh_keypass)

            self.tensor.hostConnectorCache[cHash] = self.ssh_client
def _init_ssh(self):
        """ Configure SSH client options
        """

        self.ssh_host = self.config.get('ssh_host', self.hostname)

        self.known_hosts = self.config.get('ssh_knownhosts_file',
            self.tensor.config.get('ssh_knownhosts_file', None))

        self.ssh_keyfile = self.config.get('ssh_keyfile',
            self.tensor.config.get('ssh_keyfile', None))

        self.ssh_key = self.config.get('ssh_key',
            self.tensor.config.get('ssh_key', None))

        # Not sure why you'd bother but maybe you've got a weird policy
        self.ssh_keypass = self.config.get('ssh_keypass',
            self.tensor.config.get('ssh_keypass', None))

        self.ssh_user = self.config.get('ssh_username',
            self.tensor.config.get('ssh_username', None))

        self.ssh_password = self.config.get('ssh_password',
            self.tensor.config.get('ssh_password', None))

        self.ssh_port = self.config.get('ssh_port',
            self.tensor.config.get('ssh_port', 22))

        # Verify config to see if we're good to go

        if not (self.ssh_key or self.ssh_keyfile or self.ssh_password):
            raise Exception("To use SSH you must specify *one* of ssh_key,"
                            " ssh_keyfile or ssh_password for this source"
                            " check or globally")

        if not self.ssh_user:
            raise Exception("ssh_username must be set")

        self.ssh_keydb = []

        cHash = hashlib.sha1(':'.join((
                        self.ssh_host, self.ssh_user, str(self.ssh_port),
                        str(self.ssh_password), str(self.ssh_key),
                        str(self.ssh_keyfile)
                    )).encode()).hexdigest()

        if cHash in self.tensor.hostConnectorCache:
            self.ssh_client = self.tensor.hostConnectorCache.get(cHash)
            self.ssh_connector = False
        else:
            self.ssh_connector = True
            self.ssh_client = ssh.SSHClient(self.ssh_host, self.ssh_user,
                    self.ssh_port, password=self.ssh_password,
                    knownhosts=self.known_hosts)

            if self.ssh_keyfile:
                self.ssh_client.addKeyFile(self.ssh_keyfile, self.ssh_keypass)

            if self.ssh_key:
                self.ssh_client.addKeyString(self.ssh_key, self.ssh_keypass)

            self.tensor.hostConnectorCache[cHash] = self.ssh_client
Configure SSH client options