2022-07-25 14:08:31 +00:00
|
|
|
"""Abstract class for a service running on a server"""
|
|
|
|
from abc import ABC, abstractmethod
|
|
|
|
from enum import Enum
|
2022-07-30 14:48:33 +00:00
|
|
|
import typing
|
2022-07-25 14:08:31 +00:00
|
|
|
|
2022-08-25 17:03:56 +00:00
|
|
|
from pydantic import BaseModel
|
|
|
|
from selfprivacy_api.jobs import Job
|
|
|
|
|
|
|
|
from selfprivacy_api.utils.block_devices import BlockDevice
|
|
|
|
|
2022-07-25 14:08:31 +00:00
|
|
|
|
|
|
|
class ServiceStatus(Enum):
|
|
|
|
"""Enum for service status"""
|
|
|
|
|
2022-08-25 17:03:56 +00:00
|
|
|
ACTIVE = "ACTIVE"
|
|
|
|
RELOADING = "RELOADING"
|
|
|
|
INACTIVE = "INACTIVE"
|
|
|
|
FAILED = "FAILED"
|
|
|
|
ACTIVATING = "ACTIVATING"
|
|
|
|
DEACTIVATING = "DEACTIVATING"
|
2022-07-25 14:08:31 +00:00
|
|
|
OFF = "OFF"
|
|
|
|
|
|
|
|
|
2022-08-25 17:03:56 +00:00
|
|
|
class ServiceDnsRecord(BaseModel):
|
2022-07-30 14:48:33 +00:00
|
|
|
type: str
|
|
|
|
name: str
|
|
|
|
content: str
|
|
|
|
ttl: int
|
2022-08-25 17:03:56 +00:00
|
|
|
priority: typing.Optional[int] = None
|
2022-07-30 14:48:33 +00:00
|
|
|
|
|
|
|
|
2022-07-25 14:08:31 +00:00
|
|
|
class Service(ABC):
|
|
|
|
"""
|
|
|
|
Service here is some software that is hosted on the server and
|
|
|
|
can be installed, configured and used by a user.
|
|
|
|
"""
|
|
|
|
|
2022-08-25 17:03:56 +00:00
|
|
|
@staticmethod
|
|
|
|
@abstractmethod
|
|
|
|
def get_id() -> str:
|
|
|
|
pass
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
@abstractmethod
|
|
|
|
def get_display_name() -> str:
|
|
|
|
pass
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
@abstractmethod
|
|
|
|
def get_description() -> str:
|
|
|
|
pass
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
@abstractmethod
|
|
|
|
def get_svg_icon() -> str:
|
|
|
|
pass
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
@abstractmethod
|
|
|
|
def get_url() -> typing.Optional[str]:
|
|
|
|
pass
|
|
|
|
|
|
|
|
@staticmethod
|
2022-07-25 14:08:31 +00:00
|
|
|
@abstractmethod
|
2022-08-25 17:03:56 +00:00
|
|
|
def is_movable() -> bool:
|
2022-07-25 14:08:31 +00:00
|
|
|
pass
|
|
|
|
|
2022-08-25 17:03:56 +00:00
|
|
|
@staticmethod
|
2022-07-25 14:08:31 +00:00
|
|
|
@abstractmethod
|
2022-08-25 17:03:56 +00:00
|
|
|
def is_required() -> bool:
|
2022-07-25 14:08:31 +00:00
|
|
|
pass
|
|
|
|
|
2022-08-25 17:03:56 +00:00
|
|
|
@staticmethod
|
2022-07-25 14:08:31 +00:00
|
|
|
@abstractmethod
|
2022-08-25 17:03:56 +00:00
|
|
|
def is_enabled() -> bool:
|
2022-07-25 14:08:31 +00:00
|
|
|
pass
|
|
|
|
|
2022-08-25 17:03:56 +00:00
|
|
|
@staticmethod
|
2022-07-25 14:08:31 +00:00
|
|
|
@abstractmethod
|
2022-08-25 17:03:56 +00:00
|
|
|
def get_status() -> ServiceStatus:
|
2022-07-25 14:08:31 +00:00
|
|
|
pass
|
|
|
|
|
2022-08-25 17:03:56 +00:00
|
|
|
@staticmethod
|
2022-07-25 14:08:31 +00:00
|
|
|
@abstractmethod
|
2022-08-25 17:03:56 +00:00
|
|
|
def enable():
|
2022-07-25 14:08:31 +00:00
|
|
|
pass
|
|
|
|
|
2022-08-25 17:03:56 +00:00
|
|
|
@staticmethod
|
2022-07-25 14:08:31 +00:00
|
|
|
@abstractmethod
|
2022-08-25 17:03:56 +00:00
|
|
|
def disable():
|
2022-07-25 14:08:31 +00:00
|
|
|
pass
|
|
|
|
|
2022-08-25 17:03:56 +00:00
|
|
|
@staticmethod
|
2022-07-25 14:08:31 +00:00
|
|
|
@abstractmethod
|
2022-08-25 17:03:56 +00:00
|
|
|
def stop():
|
2022-07-25 14:08:31 +00:00
|
|
|
pass
|
|
|
|
|
2022-08-25 17:03:56 +00:00
|
|
|
@staticmethod
|
2022-07-25 14:08:31 +00:00
|
|
|
@abstractmethod
|
2022-08-25 17:03:56 +00:00
|
|
|
def start():
|
2022-07-25 14:08:31 +00:00
|
|
|
pass
|
|
|
|
|
2022-08-25 17:03:56 +00:00
|
|
|
@staticmethod
|
2022-07-25 14:08:31 +00:00
|
|
|
@abstractmethod
|
2022-08-25 17:03:56 +00:00
|
|
|
def restart():
|
2022-07-25 14:08:31 +00:00
|
|
|
pass
|
|
|
|
|
2022-08-25 17:03:56 +00:00
|
|
|
@staticmethod
|
2022-07-25 14:08:31 +00:00
|
|
|
@abstractmethod
|
2022-08-25 17:03:56 +00:00
|
|
|
def get_configuration():
|
2022-07-25 14:08:31 +00:00
|
|
|
pass
|
|
|
|
|
2022-08-25 17:03:56 +00:00
|
|
|
@staticmethod
|
2022-07-25 14:08:31 +00:00
|
|
|
@abstractmethod
|
2022-08-25 17:03:56 +00:00
|
|
|
def set_configuration(config_items):
|
2022-07-25 14:08:31 +00:00
|
|
|
pass
|
|
|
|
|
2022-08-25 17:03:56 +00:00
|
|
|
@staticmethod
|
2022-07-25 14:08:31 +00:00
|
|
|
@abstractmethod
|
2022-08-25 17:03:56 +00:00
|
|
|
def get_logs():
|
2022-07-25 14:08:31 +00:00
|
|
|
pass
|
|
|
|
|
2022-08-25 17:03:56 +00:00
|
|
|
@staticmethod
|
2022-07-25 14:08:31 +00:00
|
|
|
@abstractmethod
|
2022-08-25 17:03:56 +00:00
|
|
|
def get_storage_usage() -> int:
|
2022-07-25 14:08:31 +00:00
|
|
|
pass
|
|
|
|
|
2022-08-25 17:03:56 +00:00
|
|
|
@staticmethod
|
2022-07-25 14:08:31 +00:00
|
|
|
@abstractmethod
|
2022-08-25 17:03:56 +00:00
|
|
|
def get_dns_records() -> typing.List[ServiceDnsRecord]:
|
2022-07-25 14:08:31 +00:00
|
|
|
pass
|
|
|
|
|
2022-08-25 17:03:56 +00:00
|
|
|
@staticmethod
|
2022-07-25 14:08:31 +00:00
|
|
|
@abstractmethod
|
2023-04-14 10:18:21 +00:00
|
|
|
def get_drive() -> str:
|
2022-07-25 14:08:31 +00:00
|
|
|
pass
|
2022-07-30 14:48:33 +00:00
|
|
|
|
2023-04-14 10:32:14 +00:00
|
|
|
# @staticmethod
|
|
|
|
# @abstractmethod
|
|
|
|
# def get_folders() -> str:
|
|
|
|
# pass
|
|
|
|
|
2023-04-17 12:54:21 +00:00
|
|
|
@staticmethod
|
|
|
|
def get_foldername(path: str) -> str:
|
|
|
|
return path.split("/")[-1]
|
|
|
|
|
2022-07-30 14:48:33 +00:00
|
|
|
@abstractmethod
|
2022-08-25 17:03:56 +00:00
|
|
|
def move_to_volume(self, volume: BlockDevice) -> Job:
|
2022-07-30 14:48:33 +00:00
|
|
|
pass
|
2023-02-08 15:27:49 +00:00
|
|
|
|
|
|
|
def pre_backup(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def post_restore(self):
|
|
|
|
pass
|