selfprivacy-rest-api/selfprivacy_api/services/service.py

139 lines
2.4 KiB
Python
Raw Normal View History

2022-07-25 17:08:31 +03:00
"""Abstract class for a service running on a server"""
from abc import ABC, abstractmethod
from enum import Enum
import typing
2022-07-25 17:08:31 +03:00
2022-08-11 22:11:00 +03:00
from pydantic import BaseModel
2022-08-17 23:58:56 +03:00
from selfprivacy_api.jobs import Job
2022-08-11 22:11:00 +03:00
2022-08-02 22:50:16 +03:00
from selfprivacy_api.utils.block_devices import BlockDevice
2022-07-25 17:08:31 +03:00
class ServiceStatus(Enum):
"""Enum for service status"""
RUNNING = "RUNNING"
DEGRADED = "DEGRADED"
ERROR = "ERROR"
STOPPED = "STOPPED"
OFF = "OFF"
2022-08-11 22:11:00 +03:00
class ServiceDnsRecord(BaseModel):
type: str
name: str
content: str
ttl: int
2022-08-11 22:11:00 +03:00
priority: typing.Optional[int] = None
2022-07-25 17:08:31 +03: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-11 22:11:00 +03:00
@staticmethod
2022-07-25 17:08:31 +03:00
@abstractmethod
2022-08-11 22:11:00 +03:00
def get_id() -> str:
2022-07-25 17:08:31 +03:00
pass
2022-08-11 22:11:00 +03:00
@staticmethod
2022-07-25 17:08:31 +03:00
@abstractmethod
2022-08-11 22:11:00 +03:00
def get_display_name() -> str:
2022-07-25 17:08:31 +03:00
pass
2022-08-11 22:11:00 +03:00
@staticmethod
2022-07-25 17:08:31 +03:00
@abstractmethod
2022-08-11 22:11:00 +03:00
def get_description() -> str:
2022-07-25 17:08:31 +03:00
pass
2022-08-11 22:11:00 +03:00
@staticmethod
2022-07-25 17:08:31 +03:00
@abstractmethod
2022-08-11 22:11:00 +03:00
def get_svg_icon() -> str:
2022-07-25 17:08:31 +03:00
pass
2022-08-13 00:29:18 +03:00
@staticmethod
@abstractmethod
def get_url() -> typing.Optional[str]:
pass
2022-08-11 22:11:00 +03:00
@staticmethod
2022-08-11 02:36:36 +03:00
@abstractmethod
def is_movable() -> bool:
pass
2022-08-11 22:11:00 +03:00
@staticmethod
2022-08-11 02:36:36 +03:00
@abstractmethod
def is_required() -> bool:
pass
2022-08-11 22:11:00 +03:00
@staticmethod
2022-07-25 17:08:31 +03:00
@abstractmethod
2022-08-11 22:11:00 +03:00
def is_enabled() -> bool:
2022-07-25 17:08:31 +03:00
pass
2022-08-11 22:11:00 +03:00
@staticmethod
2022-07-25 17:08:31 +03:00
@abstractmethod
2022-08-11 22:11:00 +03:00
def get_status() -> ServiceStatus:
2022-07-25 17:08:31 +03:00
pass
2022-08-11 22:11:00 +03:00
@staticmethod
2022-07-25 17:08:31 +03:00
@abstractmethod
2022-08-11 22:11:00 +03:00
def enable():
2022-07-25 17:08:31 +03:00
pass
2022-08-11 22:11:00 +03:00
@staticmethod
2022-07-25 17:08:31 +03:00
@abstractmethod
2022-08-11 22:11:00 +03:00
def disable():
2022-07-25 17:08:31 +03:00
pass
2022-08-11 22:11:00 +03:00
@staticmethod
2022-07-25 17:08:31 +03:00
@abstractmethod
2022-08-11 22:11:00 +03:00
def stop():
2022-07-25 17:08:31 +03:00
pass
2022-08-11 22:11:00 +03:00
@staticmethod
2022-07-25 17:08:31 +03:00
@abstractmethod
2022-08-11 22:11:00 +03:00
def start():
2022-07-25 17:08:31 +03:00
pass
2022-08-11 22:11:00 +03:00
@staticmethod
2022-07-25 17:08:31 +03:00
@abstractmethod
2022-08-11 22:11:00 +03:00
def restart():
2022-07-25 17:08:31 +03:00
pass
2022-08-11 22:11:00 +03:00
@staticmethod
2022-07-25 17:08:31 +03:00
@abstractmethod
2022-08-11 22:11:00 +03:00
def get_configuration():
2022-07-25 17:08:31 +03:00
pass
2022-08-11 22:11:00 +03:00
@staticmethod
2022-07-25 17:08:31 +03:00
@abstractmethod
2022-08-11 22:11:00 +03:00
def set_configuration(config_items):
2022-07-25 17:08:31 +03:00
pass
2022-08-11 22:11:00 +03:00
@staticmethod
2022-07-25 17:08:31 +03:00
@abstractmethod
2022-08-11 22:11:00 +03:00
def get_logs():
2022-07-25 17:08:31 +03:00
pass
2022-08-11 22:11:00 +03:00
@staticmethod
2022-07-25 17:08:31 +03:00
@abstractmethod
2022-08-11 22:11:00 +03:00
def get_storage_usage() -> int:
2022-07-25 17:08:31 +03:00
pass
2022-08-11 22:11:00 +03:00
@staticmethod
@abstractmethod
2022-08-11 22:11:00 +03:00
def get_dns_records() -> typing.List[ServiceDnsRecord]:
pass
2022-08-02 22:50:16 +03:00
2022-08-11 22:11:00 +03:00
@staticmethod
2022-08-02 22:50:16 +03:00
@abstractmethod
2022-08-11 22:11:00 +03:00
def get_location() -> str:
2022-08-02 22:50:16 +03:00
pass
@abstractmethod
2022-08-17 23:58:56 +03:00
def move_to_volume(self, volume: BlockDevice) -> Job:
2022-08-02 22:50:16 +03:00
pass