selfprivacy-rest-api/selfprivacy_api/migrations/add_monitoring.py

38 lines
1.4 KiB
Python
Raw Normal View History

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