1 # -*- coding: utf-8 -*-
3 # Copyright 2018 Telefonica S.A.
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
20 from http
import HTTPStatus
21 from osm_common
.common_utils
import FakeLock
22 from threading
import Lock
24 __author__
= "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>"
27 class FsException(Exception):
28 def __init__(self
, message
, http_code
=HTTPStatus
.INTERNAL_SERVER_ERROR
):
29 self
.http_code
= http_code
30 Exception.__init
__(self
, "storage exception " + message
)
34 def __init__(self
, logger_name
='fs', lock
=False):
37 :param logger_name: logging name
38 :param lock: Used to protect simultaneous access to the same instance class by several threads:
39 False, None: Do not protect, this object will only be accessed by one thread
40 True: This object needs to be protected by several threads accessing.
41 Lock object. Use thi Lock for the threads access protection
43 self
.logger
= logging
.getLogger(logger_name
)
45 self
.lock
= FakeLock()
48 elif isinstance(lock
, Lock
):
51 raise ValueError("lock parameter must be a Lock class or boolean")
56 def fs_connect(self
, config
):
59 def fs_disconnect(self
):
62 def mkdir(self
, folder
):
63 raise FsException("Method 'mkdir' not implemented")
65 def dir_rename(self
, src
, dst
):
66 raise FsException("Method 'dir_rename' not implemented")
68 def dir_ls(self
, storage
):
69 raise FsException("Method 'dir_ls' not implemented")
71 def file_exists(self
, storage
):
72 raise FsException("Method 'file_exists' not implemented")
74 def file_size(self
, storage
):
75 raise FsException("Method 'file_size' not implemented")
77 def file_extract(self
, tar_object
, path
):
78 raise FsException("Method 'file_extract' not implemented")
80 def file_open(self
, storage
, mode
):
81 raise FsException("Method 'file_open' not implemented")
83 def file_delete(self
, storage
, ignore_non_exist
=False):
84 raise FsException("Method 'file_delete' not implemented")
86 def sync(self
, from_path
=None):
87 raise FsException("Method 'sync' not implemented")
89 def reverse_sync(self
, from_path
):
90 raise FsException("Method 'reverse_sync' not implemented")