blob: 87d974d522c1568e43a2bbefaed61c855c1fc395 [file] [log] [blame]
tierno87858ca2018-10-08 16:30:15 +02001# -*- 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
tierno5c012612018-04-19 16:01:59 +020018
tierno1e9a3292018-11-05 18:18:45 +010019import logging
tierno5c012612018-04-19 16:01:59 +020020from http import HTTPStatus
tierno1e9a3292018-11-05 18:18:45 +010021from osm_common.common_utils import FakeLock
22from threading import Lock
tierno5c012612018-04-19 16:01:59 +020023
24__author__ = "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>"
25
26
27class 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)
31
32
33class FsBase(object):
tierno1e9a3292018-11-05 18:18:45 +010034 def __init__(self, logger_name='fs', lock=False):
35 """
36 Constructor of FsBase
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
42 """
43 self.logger = logging.getLogger(logger_name)
44 if not lock:
45 self.lock = FakeLock()
46 elif lock is True:
47 self.lock = Lock()
48 elif isinstance(lock, Lock):
49 self.lock = lock
50 else:
51 raise ValueError("lock parameter must be a Lock class or boolean")
tierno5c012612018-04-19 16:01:59 +020052
53 def get_params(self):
54 return {}
55
56 def fs_connect(self, config):
57 pass
58
59 def fs_disconnect(self):
60 pass
61
62 def mkdir(self, folder):
tiernoebbf3532018-05-03 17:49:37 +020063 raise FsException("Method 'mkdir' not implemented")
tierno5c012612018-04-19 16:01:59 +020064
tiernod4378aa2018-12-04 15:37:23 +000065 def dir_rename(self, src, dst):
66 raise FsException("Method 'dir_rename' not implemented")
67
tierno5c012612018-04-19 16:01:59 +020068 def file_exists(self, storage):
tiernoebbf3532018-05-03 17:49:37 +020069 raise FsException("Method 'file_exists' not implemented")
tierno5c012612018-04-19 16:01:59 +020070
71 def file_size(self, storage):
tiernoebbf3532018-05-03 17:49:37 +020072 raise FsException("Method 'file_size' not implemented")
tierno5c012612018-04-19 16:01:59 +020073
74 def file_extract(self, tar_object, path):
tiernoebbf3532018-05-03 17:49:37 +020075 raise FsException("Method 'file_extract' not implemented")
tierno5c012612018-04-19 16:01:59 +020076
77 def file_open(self, storage, mode):
tiernoebbf3532018-05-03 17:49:37 +020078 raise FsException("Method 'file_open' not implemented")
tierno5c012612018-04-19 16:01:59 +020079
80 def file_delete(self, storage, ignore_non_exist=False):
tiernoebbf3532018-05-03 17:49:37 +020081 raise FsException("Method 'file_delete' not implemented")