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 |
|
|
18 |
|
|
19 |
1 |
from http import HTTPStatus |
20 |
1 |
import logging |
21 |
1 |
from threading import Lock |
22 |
|
|
23 |
1 |
from osm_common.common_utils import FakeLock |
24 |
|
|
25 |
|
|
26 |
1 |
__author__ = "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>" |
27 |
|
|
28 |
|
|
29 |
1 |
class FsException(Exception): |
30 |
1 |
def __init__(self, message, http_code=HTTPStatus.INTERNAL_SERVER_ERROR): |
31 |
0 |
self.http_code = http_code |
32 |
0 |
Exception.__init__(self, "storage exception " + message) |
33 |
|
|
34 |
|
|
35 |
1 |
class FsBase(object): |
36 |
1 |
def __init__(self, logger_name="fs", lock=False): |
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 |
1 |
self.logger = logging.getLogger(logger_name) |
46 |
1 |
if not lock: |
47 |
1 |
self.lock = FakeLock() |
48 |
0 |
elif lock is True: |
49 |
0 |
self.lock = Lock() |
50 |
0 |
elif isinstance(lock, Lock): |
51 |
0 |
self.lock = lock |
52 |
|
else: |
53 |
0 |
raise ValueError("lock parameter must be a Lock class or boolean") |
54 |
|
|
55 |
1 |
def get_params(self): |
56 |
0 |
return {} |
57 |
|
|
58 |
1 |
def fs_connect(self, config): |
59 |
0 |
pass |
60 |
|
|
61 |
1 |
def fs_disconnect(self): |
62 |
0 |
pass |
63 |
|
|
64 |
1 |
def mkdir(self, folder): |
65 |
0 |
raise FsException("Method 'mkdir' not implemented") |
66 |
|
|
67 |
1 |
def dir_rename(self, src, dst): |
68 |
0 |
raise FsException("Method 'dir_rename' not implemented") |
69 |
|
|
70 |
1 |
def dir_ls(self, storage): |
71 |
0 |
raise FsException("Method 'dir_ls' not implemented") |
72 |
|
|
73 |
1 |
def file_exists(self, storage): |
74 |
0 |
raise FsException("Method 'file_exists' not implemented") |
75 |
|
|
76 |
1 |
def file_size(self, storage): |
77 |
0 |
raise FsException("Method 'file_size' not implemented") |
78 |
|
|
79 |
1 |
def file_extract(self, tar_object, path): |
80 |
0 |
raise FsException("Method 'file_extract' not implemented") |
81 |
|
|
82 |
1 |
def file_open(self, storage, mode): |
83 |
0 |
raise FsException("Method 'file_open' not implemented") |
84 |
|
|
85 |
1 |
def file_delete(self, storage, ignore_non_exist=False): |
86 |
0 |
raise FsException("Method 'file_delete' not implemented") |
87 |
|
|
88 |
1 |
def sync(self, from_path=None): |
89 |
0 |
raise FsException("Method 'sync' not implemented") |
90 |
|
|
91 |
1 |
def reverse_sync(self, from_path): |
92 |
0 |
raise FsException("Method 'reverse_sync' not implemented") |