def __init__(self, host, user, passwd, port=22, compress=False, timeout=10, keepalive=10): FS.__init__(self) self._user = user self._host = host self._port = port self._client = client = paramiko.SSHClient() self._locale = None try: client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) client.connect( socket.gethostbyname(host), port, user, passwd, compress=compress, timeout=timeout, allow_agent=False,look_for_keys=False ) if keepalive > 0: client.get_transport().set_keepalive(keepalive) self._sftp = client.open_sftp() self._platform = None except (paramiko.ssh_exception.SSHException, # protocol errors paramiko.ssh_exception.NoValidConnectionsError, # connexion errors socket.gaierror, socket.timeout) as e: # TCP errors message = "Unable to create filesystem: {}".format(e) raise errors.CreateFailed(message)
def makedir(self, path, permissions=None, recreate=False): self.check() result = self.pcloud.createfolder(path=path) if result['result'] != 0: raise errors.CreateFailed( 'Create of directory "{0}" failed with "{1}"'.format( path, result['error']) ) else: # everything is OK return self.opendir(path)
def __init__(self, host, user=None, passwd=None, pkey=None, timeout=10, port=22, keepalive=10, compress=False, config_path='~/.ssh/config'): # noqa: D102 super(SSHFS, self).__init__() # Attempt to get a configuration for the given host ssh_config = self._get_ssh_config(config_path) config = ssh_config.lookup(host) pkey = config.get('identityfile') or pkey # Extract the given info pkey, keyfile= (pkey, None) \ if isinstance(pkey, paramiko.PKey) else (None, pkey) self._user = user = user or config.get('user') self._host = host = config.get('hostname') self._port = port = int(config.get('port', port)) self._client = client = paramiko.SSHClient() self._locale = None try: # TODO: add more options client.load_system_host_keys() client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) client.connect(socket.gethostbyname(host), port, user, passwd, pkey=pkey, key_filename=keyfile, look_for_keys=True if (pkey and keyfile) is None else False, compress=compress, timeout=timeout) if keepalive > 0: client.get_transport().set_keepalive(keepalive) self._sftp = client.open_sftp() self._platform = None except ( paramiko.ssh_exception.SSHException, # protocol errors paramiko.ssh_exception. NoValidConnectionsError, # connexion errors socket.gaierror, socket.timeout) as e: # TCP errors message = "Unable to create filesystem: {}".format(e) raise errors.CreateFailed(message)
def makedir(self, path, permissions=None, recreate=False): self.check() result = self.pcloud.createfolder(path=path) if result["result"] == 2004: raise errors.DirectoryExists( 'Directory "{0}" already exists'.format(path)) elif result["result"] != 0: raise errors.CreateFailed( 'Create of directory "{0}" failed with "{1}"'.format( path, result["error"] ) ) else: # everything is OK return self.opendir(path)
def __init__(self, bucket_name: str, root_path: str = None, create: bool = False, client: Client = None, retry: int = 5, strict: bool = True): super().__init__() self._bucket_name = bucket_name if not root_path: root_path = "" self.root_path = root_path self._prefix = relpath(normpath(root_path)).rstrip(self.DELIMITER) self.strict = strict self.client = client if self.client is None: self.client = Client() if retry: # urllib3: "method_whitelist" was deprecated in favour of "allowed_methods" in version 1.26.0 # Ensure compatibility with versions < 1.26.0 while at the same time avoiding the `DeprecationWarning` # for versions >= 1.26.0 key = "allowed_methods" if version.parse( urllib3.__version__) >= version.parse( "1.26.0") else "method_whitelist" kwargs = {key: False} # retry on any HTTP method max_retries = Retry(total=retry, status_forcelist=[429, 502, 503, 504], backoff_factor=0.5, **kwargs) adapter = HTTPAdapter(max_retries=max_retries) self.client._http.mount("https://", adapter) self.bucket = self.client.bucket(self._bucket_name) if self._prefix != "": if create: root_marker = self._get_blob(self._prefix + GCSFS.DELIMITER) if root_marker is None: blob = self.bucket.blob(self._prefix + GCSFS.DELIMITER) blob.upload_from_string(b"") elif strict and self._get_blob(self._prefix + GCSFS.DELIMITER) is None: raise errors.CreateFailed( "Root path \"{}\" does not exist".format(root_path))
def __init__(self, bucket_name: str, root_path: str = None, create: bool = False, client: Client = None, strict: bool = True): super().__init__() self._bucket_name = bucket_name if not root_path: root_path = "" self.root_path = root_path self._prefix = relpath(normpath(root_path)).rstrip(self.DELIMITER) self.strict = strict self.client = client if self.client is None: self.client = Client() try: self.bucket = self.client.get_bucket(self._bucket_name) except google.api_core.exceptions.NotFound as err: raise CreateFailed( "The bucket \"{}\" does not seem to exist".format( self._bucket_name)) from err except google.api_core.exceptions.Forbidden as err: raise CreateFailed( "You don't have access to the bucket \"{}\"".format( self._bucket_name)) from err if self._prefix != "": if create: root_marker = self._get_blob(self._prefix + GCSFS.DELIMITER) if root_marker is None: blob = self.bucket.blob(self._prefix + GCSFS.DELIMITER) blob.upload_from_string(b"") elif strict and self._get_blob(self._prefix + GCSFS.DELIMITER ) is None and not self._is_dir( self._prefix): raise errors.CreateFailed( "Root path \"{}\" does not exist".format(root_path))
def __init__(self, root: Union[str, DriveItem], writeable=False, client=None): self._lock = threading.RLock() super(FS, self).__init__() if client is None: self.__client = self.get_client(writeable) else: self.__client = client api = GraphApi(self.__client) try: if isinstance(root, DriveItem): drive_item = root else: drive_item, filename = api.files.parse_file_path(root) assert filename == "/" drive_item = drive_item.value except Exception as e: raise errors.CreateFailed(f"Could not open {root}: {e}") from e self._drive_root = self._resource_root = drive_item.get_api_reference() self.session = MSGraphyClientSession(self.__client, self._resource_root) self._meta = { 'case_insensitive': True, 'invalid_path_chars': ':\0\\', 'max_path_length': None, # don't know what the limit is 'max_sys_path_length': None, # there's no syspath 'network': True, 'read_only': False, 'supports_rename': False # since we don't have a syspath... }