2024-07-17 19:44:56 +04:00
|
|
|
from selfprivacy_api.migrations.migration import Migration
|
|
|
|
|
|
|
|
from selfprivacy_api.services.flake_service_manager import FlakeServiceManager
|
|
|
|
from selfprivacy_api.utils import ReadUserData, WriteUserData
|
2024-07-24 15:02:56 +03:00
|
|
|
from selfprivacy_api.utils.block_devices import BlockDevices
|
2024-07-17 19:44:56 +04:00
|
|
|
|
|
|
|
|
2024-07-24 06:12:18 +03:00
|
|
|
class AddMonitoring(Migration):
|
|
|
|
"""Adds monitoring service if it is not present."""
|
2024-07-17 19:44:56 +04:00
|
|
|
|
|
|
|
def get_migration_name(self) -> str:
|
2024-07-24 06:12:18 +03:00
|
|
|
return "add_monitoring"
|
2024-07-17 19:44:56 +04:00
|
|
|
|
|
|
|
def get_migration_description(self) -> str:
|
2024-07-24 06:12:18 +03:00
|
|
|
return "Adds the Monitoring if it is not present."
|
2024-07-17 19:44:56 +04:00
|
|
|
|
|
|
|
def is_migration_needed(self) -> bool:
|
|
|
|
with FlakeServiceManager() as manager:
|
2024-07-24 06:12:18 +03:00
|
|
|
if "monitoring" not in manager.services:
|
2024-07-17 19:44:56 +04:00
|
|
|
return True
|
|
|
|
with ReadUserData() as data:
|
2024-07-24 06:12:18 +03:00
|
|
|
if "monitoring" not in data["modules"]:
|
2024-07-17 19:44:56 +04:00
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def migrate(self) -> None:
|
|
|
|
with FlakeServiceManager() as manager:
|
2024-07-24 06:12:18 +03:00
|
|
|
if "monitoring" not in manager.services:
|
2024-07-18 20:40:18 +04:00
|
|
|
manager.services[
|
2024-07-24 06:12:18 +03:00
|
|
|
"monitoring"
|
|
|
|
] = "git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/monitoring"
|
2024-07-17 19:44:56 +04:00
|
|
|
with WriteUserData() as data:
|
2024-07-24 06:12:18 +03:00
|
|
|
if "monitoring" not in data["modules"]:
|
|
|
|
data["modules"]["monitoring"] = {
|
2024-07-24 15:02:56 +03:00
|
|
|
"enable": True,
|
2024-07-25 16:48:34 +03:00
|
|
|
"location": BlockDevices().get_root_block_device().name,
|
2024-07-17 19:44:56 +04:00
|
|
|
}
|