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-02 19:50:16 +00:00
|
|
|
from selfprivacy_api.utils.block_devices import BlockDevice
|
|
|
|
|
2022-07-25 14:08:31 +00:00
|
|
|
|
|
|
|
class ServiceStatus(Enum):
|
|
|
|
"""Enum for service status"""
|
|
|
|
|
|
|
|
RUNNING = "RUNNING"
|
|
|
|
DEGRADED = "DEGRADED"
|
|
|
|
ERROR = "ERROR"
|
|
|
|
STOPPED = "STOPPED"
|
|
|
|
OFF = "OFF"
|
|
|
|
|
|
|
|
|
2022-07-30 14:48:33 +00:00
|
|
|
class ServiceDnsRecord:
|
|
|
|
type: str
|
|
|
|
name: str
|
|
|
|
content: str
|
|
|
|
ttl: int
|
|
|
|
priority: typing.Optional[int]
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
"""
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def get_id(self) -> str:
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def get_display_name(self) -> str:
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def get_description(self) -> str:
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def get_svg_icon(self) -> str:
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def is_enabled(self) -> bool:
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def get_status(self) -> ServiceStatus:
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def enable(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def disable(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def stop(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def start(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def restart(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def get_configuration(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def set_configuration(self, config_items):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def get_logs(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
2022-08-02 19:50:16 +00:00
|
|
|
def get_storage_usage(self) -> int:
|
2022-07-25 14:08:31 +00:00
|
|
|
pass
|
2022-07-30 14:48:33 +00:00
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def get_dns_records(self) -> typing.List[ServiceDnsRecord]:
|
|
|
|
pass
|
2022-08-02 19:50:16 +00:00
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def get_location(self) -> str:
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def move_to_volume(self, volume: BlockDevice):
|
|
|
|
pass
|