Exemple #1
0
 def get_ssh_client(self, ssh_client, ssh_server_config, client_type='plink'):
     """ return ssh_client if it is active, otherwise,
     if ssh_client passed in is None or is not active, re-create a ssh_client
     from ssh_server_config dict including hostname, username, and password
     """
     if client_type == 'plink':
         if ssh_client is not None:
             return ssh_client
     
     if client_type == 'paramiko':
         if ssh_client is not None and ssh_client._transport.is_active():
             return ssh_client
     
     return get_ssh_client(ssh_server_config=ssh_server_config, client_type=client_type)
 def __init__(self, storage_location, client_type='paramiko'):
     """
     storage_location = 'sftp://[username:passwd@]my.hostname.com/home/users/cache_dir'
     it is recommended to store sftp user and password in system environment variables or in a security key,
     instead of passing in as plain text.
     """
     server_config = {'port':22}
     o = urlparse(storage_location)
     server_config['hostname'] = o.hostname
     server_config['username'] = o.username or os.environ.get('URBANSIMUSERNAME', None) or os.environ.get('TRAVELMODELUSERNAME', None)
     server_config['password'] = o.password or os.environ.get('URBANSIMPASSWORD', None) or os.environ.get('TRAVELMODELPASSWORD', None)
     if o.port is not None:
         server_config['port'] = o.port
     
     self.ssh_client = get_ssh_client(ssh_server_config=server_config, client_type=client_type)
     
     self._base_directory_remote = o.path
     self._base_directory = self._base_directory_local = tempfile.mkdtemp(prefix='opus_tmp')
    def get_ssh_client(self,
                       ssh_client,
                       ssh_server_config,
                       client_type='plink'):
        """ return ssh_client if it is active, otherwise,
        if ssh_client passed in is None or is not active, re-create a ssh_client
        from ssh_server_config dict including hostname, username, and password
        """
        if client_type == 'plink':
            if ssh_client is not None:
                return ssh_client

        if client_type == 'paramiko':
            if ssh_client is not None and ssh_client._transport.is_active():
                return ssh_client

        return get_ssh_client(ssh_server_config=ssh_server_config,
                              client_type=client_type)
Exemple #4
0
    def __init__(self, storage_location, client_type='paramiko'):
        """
        storage_location = 'sftp://[username:passwd@]my.hostname.com/home/users/cache_dir'
        it is recommended to store sftp user and password in system environment variables or in a security key,
        instead of passing in as plain text.
        """
        server_config = {'port': 22}
        o = urlparse(storage_location)
        server_config['hostname'] = o.hostname
        server_config['username'] = o.username or os.environ.get(
            'URBANSIMUSERNAME', None) or os.environ.get(
                'TRAVELMODELUSERNAME', None)
        server_config['password'] = o.password or os.environ.get(
            'URBANSIMPASSWORD', None) or os.environ.get(
                'TRAVELMODELPASSWORD', None)
        if o.port is not None:
            server_config['port'] = o.port

        self.ssh_client = get_ssh_client(ssh_server_config=server_config,
                                         client_type=client_type)

        self._base_directory_remote = o.path
        self._base_directory = self._base_directory_local = tempfile.mkdtemp(
            prefix='opus_tmp')