| tierno | 87858ca | 2018-10-08 16:30:15 +0200 | [diff] [blame] | 1 | # -*- coding: utf-8 -*- |
| 2 | |
| 3 | # Copyright 2018 Telefonica S.A. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| 14 | # implied. |
| 15 | # See the License for the specific language governing permissions and |
| 16 | # limitations under the License. |
| 17 | |
| tierno | 5c01261 | 2018-04-19 16:01:59 +0200 | [diff] [blame] | 18 | |
| 19 | from http import HTTPStatus |
| aticig | 3dd0db6 | 2022-03-04 19:35:45 +0300 | [diff] [blame^] | 20 | import logging |
| tierno | 1e9a329 | 2018-11-05 18:18:45 +0100 | [diff] [blame] | 21 | from threading import Lock |
| tierno | 5c01261 | 2018-04-19 16:01:59 +0200 | [diff] [blame] | 22 | |
| aticig | 3dd0db6 | 2022-03-04 19:35:45 +0300 | [diff] [blame^] | 23 | from osm_common.common_utils import FakeLock |
| 24 | |
| 25 | |
| tierno | 5c01261 | 2018-04-19 16:01:59 +0200 | [diff] [blame] | 26 | __author__ = "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>" |
| 27 | |
| 28 | |
| 29 | class FsException(Exception): |
| 30 | def __init__(self, message, http_code=HTTPStatus.INTERNAL_SERVER_ERROR): |
| 31 | self.http_code = http_code |
| 32 | Exception.__init__(self, "storage exception " + message) |
| 33 | |
| 34 | |
| 35 | class FsBase(object): |
| garciadeblas | 2644b76 | 2021-03-24 09:21:01 +0100 | [diff] [blame] | 36 | def __init__(self, logger_name="fs", lock=False): |
| tierno | 1e9a329 | 2018-11-05 18:18:45 +0100 | [diff] [blame] | 37 | """ |
| 38 | Constructor of FsBase |
| 39 | :param logger_name: logging name |
| 40 | :param lock: Used to protect simultaneous access to the same instance class by several threads: |
| 41 | False, None: Do not protect, this object will only be accessed by one thread |
| 42 | True: This object needs to be protected by several threads accessing. |
| 43 | Lock object. Use thi Lock for the threads access protection |
| 44 | """ |
| 45 | self.logger = logging.getLogger(logger_name) |
| 46 | if not lock: |
| 47 | self.lock = FakeLock() |
| 48 | elif lock is True: |
| 49 | self.lock = Lock() |
| 50 | elif isinstance(lock, Lock): |
| 51 | self.lock = lock |
| 52 | else: |
| 53 | raise ValueError("lock parameter must be a Lock class or boolean") |
| tierno | 5c01261 | 2018-04-19 16:01:59 +0200 | [diff] [blame] | 54 | |
| 55 | def get_params(self): |
| 56 | return {} |
| 57 | |
| 58 | def fs_connect(self, config): |
| 59 | pass |
| 60 | |
| 61 | def fs_disconnect(self): |
| 62 | pass |
| 63 | |
| 64 | def mkdir(self, folder): |
| tierno | ebbf353 | 2018-05-03 17:49:37 +0200 | [diff] [blame] | 65 | raise FsException("Method 'mkdir' not implemented") |
| tierno | 5c01261 | 2018-04-19 16:01:59 +0200 | [diff] [blame] | 66 | |
| tierno | d4378aa | 2018-12-04 15:37:23 +0000 | [diff] [blame] | 67 | def dir_rename(self, src, dst): |
| 68 | raise FsException("Method 'dir_rename' not implemented") |
| 69 | |
| delacruzramo | 13a71fb | 2019-11-19 15:10:49 +0100 | [diff] [blame] | 70 | def dir_ls(self, storage): |
| 71 | raise FsException("Method 'dir_ls' not implemented") |
| 72 | |
| tierno | 5c01261 | 2018-04-19 16:01:59 +0200 | [diff] [blame] | 73 | def file_exists(self, storage): |
| tierno | ebbf353 | 2018-05-03 17:49:37 +0200 | [diff] [blame] | 74 | raise FsException("Method 'file_exists' not implemented") |
| tierno | 5c01261 | 2018-04-19 16:01:59 +0200 | [diff] [blame] | 75 | |
| 76 | def file_size(self, storage): |
| tierno | ebbf353 | 2018-05-03 17:49:37 +0200 | [diff] [blame] | 77 | raise FsException("Method 'file_size' not implemented") |
| tierno | 5c01261 | 2018-04-19 16:01:59 +0200 | [diff] [blame] | 78 | |
| 79 | def file_extract(self, tar_object, path): |
| tierno | ebbf353 | 2018-05-03 17:49:37 +0200 | [diff] [blame] | 80 | raise FsException("Method 'file_extract' not implemented") |
| tierno | 5c01261 | 2018-04-19 16:01:59 +0200 | [diff] [blame] | 81 | |
| 82 | def file_open(self, storage, mode): |
| tierno | ebbf353 | 2018-05-03 17:49:37 +0200 | [diff] [blame] | 83 | raise FsException("Method 'file_open' not implemented") |
| tierno | 5c01261 | 2018-04-19 16:01:59 +0200 | [diff] [blame] | 84 | |
| 85 | def file_delete(self, storage, ignore_non_exist=False): |
| tierno | ebbf353 | 2018-05-03 17:49:37 +0200 | [diff] [blame] | 86 | raise FsException("Method 'file_delete' not implemented") |
| David Garcia | 788b9d6 | 2020-01-20 13:21:06 +0100 | [diff] [blame] | 87 | |
| tierno | b07e4ef | 2020-05-06 14:22:48 +0000 | [diff] [blame] | 88 | def sync(self, from_path=None): |
| David Garcia | 788b9d6 | 2020-01-20 13:21:06 +0100 | [diff] [blame] | 89 | raise FsException("Method 'sync' not implemented") |
| lloretgalleg | f296d2a | 2020-09-02 09:36:24 +0000 | [diff] [blame] | 90 | |
| 91 | def reverse_sync(self, from_path): |
| 92 | raise FsException("Method 'reverse_sync' not implemented") |