refactor(services): extract get_drive to the base Service class
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
parent
a87889b252
commit
f08eafc3d8
|
@ -121,14 +121,6 @@ class Bitwarden(Service):
|
||||||
def get_folders() -> typing.List[str]:
|
def get_folders() -> typing.List[str]:
|
||||||
return ["/var/lib/bitwarden", "/var/lib/bitwarden_rs"]
|
return ["/var/lib/bitwarden", "/var/lib/bitwarden_rs"]
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_drive() -> str:
|
|
||||||
with ReadUserData() as user_data:
|
|
||||||
if user_data.get("useBinds", False):
|
|
||||||
return user_data.get("bitwarden", {}).get("location", "sda1")
|
|
||||||
else:
|
|
||||||
return "sda1"
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_dns_records() -> typing.List[ServiceDnsRecord]:
|
def get_dns_records() -> typing.List[ServiceDnsRecord]:
|
||||||
"""Return list of DNS records for Bitwarden service."""
|
"""Return list of DNS records for Bitwarden service."""
|
||||||
|
|
|
@ -116,14 +116,6 @@ class Gitea(Service):
|
||||||
def get_folders() -> typing.List[str]:
|
def get_folders() -> typing.List[str]:
|
||||||
return ["/var/lib/gitea"]
|
return ["/var/lib/gitea"]
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_drive() -> str:
|
|
||||||
with ReadUserData() as user_data:
|
|
||||||
if user_data.get("useBinds", False):
|
|
||||||
return user_data.get("gitea", {}).get("location", "sda1")
|
|
||||||
else:
|
|
||||||
return "sda1"
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_dns_records() -> typing.List[ServiceDnsRecord]:
|
def get_dns_records() -> typing.List[ServiceDnsRecord]:
|
||||||
return [
|
return [
|
||||||
|
|
|
@ -122,10 +122,6 @@ class Jitsi(Service):
|
||||||
def get_folders() -> typing.List[str]:
|
def get_folders() -> typing.List[str]:
|
||||||
return ["/var/lib/jitsi-meet"]
|
return ["/var/lib/jitsi-meet"]
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_drive() -> str:
|
|
||||||
return BlockDevices().get_root_block_device().name
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_dns_records() -> typing.List[ServiceDnsRecord]:
|
def get_dns_records() -> typing.List[ServiceDnsRecord]:
|
||||||
ip4 = network_utils.get_ip4()
|
ip4 = network_utils.get_ip4()
|
||||||
|
|
|
@ -105,14 +105,6 @@ class MailServer(Service):
|
||||||
def get_folders() -> typing.List[str]:
|
def get_folders() -> typing.List[str]:
|
||||||
return ["/var/vmail", "/var/sieve"]
|
return ["/var/vmail", "/var/sieve"]
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_drive() -> str:
|
|
||||||
with utils.ReadUserData() as user_data:
|
|
||||||
if user_data.get("useBinds", False):
|
|
||||||
return user_data.get("email", {}).get("location", "sda1")
|
|
||||||
else:
|
|
||||||
return "sda1"
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_dns_records() -> typing.List[ServiceDnsRecord]:
|
def get_dns_records() -> typing.List[ServiceDnsRecord]:
|
||||||
domain = utils.get_domain()
|
domain = utils.get_domain()
|
||||||
|
|
|
@ -120,15 +120,6 @@ class Nextcloud(Service):
|
||||||
def get_folders() -> typing.List[str]:
|
def get_folders() -> typing.List[str]:
|
||||||
return ["/var/lib/nextcloud"]
|
return ["/var/lib/nextcloud"]
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_drive() -> str:
|
|
||||||
"""Get the name of disk where Nextcloud is installed."""
|
|
||||||
with ReadUserData() as user_data:
|
|
||||||
if user_data.get("useBinds", False):
|
|
||||||
return user_data.get("nextcloud", {}).get("location", "sda1")
|
|
||||||
else:
|
|
||||||
return "sda1"
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_dns_records() -> typing.List[ServiceDnsRecord]:
|
def get_dns_records() -> typing.List[ServiceDnsRecord]:
|
||||||
return [
|
return [
|
||||||
|
|
|
@ -98,10 +98,6 @@ class Ocserv(Service):
|
||||||
def get_logs():
|
def get_logs():
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_drive() -> str:
|
|
||||||
return BlockDevices().get_root_block_device().name
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_dns_records() -> typing.List[ServiceDnsRecord]:
|
def get_dns_records() -> typing.List[ServiceDnsRecord]:
|
||||||
return [
|
return [
|
||||||
|
|
|
@ -119,14 +119,6 @@ class Pleroma(Service):
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_drive() -> str:
|
|
||||||
with ReadUserData() as user_data:
|
|
||||||
if user_data.get("useBinds", False):
|
|
||||||
return user_data.get("pleroma", {}).get("location", "sda1")
|
|
||||||
else:
|
|
||||||
return "sda1"
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_dns_records() -> typing.List[ServiceDnsRecord]:
|
def get_dns_records() -> typing.List[ServiceDnsRecord]:
|
||||||
return [
|
return [
|
||||||
|
|
|
@ -6,10 +6,11 @@ import typing
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
from selfprivacy_api.jobs import Job
|
from selfprivacy_api.jobs import Job
|
||||||
|
|
||||||
from selfprivacy_api.utils.block_devices import BlockDevice
|
from selfprivacy_api.utils.block_devices import BlockDevice, BlockDevices
|
||||||
|
|
||||||
from selfprivacy_api.services.generic_size_counter import get_storage_usage
|
from selfprivacy_api.services.generic_size_counter import get_storage_usage
|
||||||
from selfprivacy_api.services.owned_path import OwnedPath
|
from selfprivacy_api.services.owned_path import OwnedPath
|
||||||
|
from selfprivacy_api import utils
|
||||||
from selfprivacy_api.utils.waitloop import wait_until_true
|
from selfprivacy_api.utils.waitloop import wait_until_true
|
||||||
|
|
||||||
DEFAULT_START_STOP_TIMEOUT = 10 * 60
|
DEFAULT_START_STOP_TIMEOUT = 10 * 60
|
||||||
|
@ -197,10 +198,23 @@ class Service(ABC):
|
||||||
def get_dns_records() -> typing.List[ServiceDnsRecord]:
|
def get_dns_records() -> typing.List[ServiceDnsRecord]:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
@abstractmethod
|
def get_drive(cls) -> str:
|
||||||
def get_drive() -> str:
|
"""
|
||||||
pass
|
Get the name of the drive/volume where the service is located.
|
||||||
|
Example values are `sda1`, `vda`, `sdb`.
|
||||||
|
"""
|
||||||
|
root_device: str = BlockDevices().get_root_block_device().name
|
||||||
|
if not cls.is_movable():
|
||||||
|
return root_device
|
||||||
|
with utils.ReadUserData() as userdata:
|
||||||
|
if userdata.get("useBinds", False):
|
||||||
|
return userdata.get(cls.get_id(), {}).get(
|
||||||
|
"location",
|
||||||
|
root_device,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
return root_device
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_folders(cls) -> typing.List[str]:
|
def get_folders(cls) -> typing.List[str]:
|
||||||
|
|
Loading…
Reference in New Issue