mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-22 20:11:30 +00:00
dettlaff
4cd90d0c93
Co-authored-by: nhnn <nhnn@disroot.org> Co-authored-by: Inex Code <inex.code@selfprivacy.org> Reviewed-on: https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api/pulls/120 Co-authored-by: dettlaff <dettlaff@riseup.net> Co-committed-by: dettlaff <dettlaff@riseup.net>
38 lines
1.4 KiB
Python
38 lines
1.4 KiB
Python
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
|
|
|
|
|
|
class AddMonitoring(Migration):
|
|
"""Adds monitoring service if it is not present."""
|
|
|
|
def get_migration_name(self) -> str:
|
|
return "add_monitoring"
|
|
|
|
def get_migration_description(self) -> str:
|
|
return "Adds the Monitoring if it is not present."
|
|
|
|
def is_migration_needed(self) -> bool:
|
|
with FlakeServiceManager() as manager:
|
|
if "monitoring" not in manager.services:
|
|
return True
|
|
with ReadUserData() as data:
|
|
if "monitoring" not in data["modules"]:
|
|
return True
|
|
return False
|
|
|
|
def migrate(self) -> None:
|
|
with FlakeServiceManager() as manager:
|
|
if "monitoring" not in manager.services:
|
|
manager.services["monitoring"] = (
|
|
"git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/monitoring"
|
|
)
|
|
with WriteUserData() as data:
|
|
if "monitoring" not in data["modules"]:
|
|
data["modules"]["monitoring"] = {
|
|
"enable": True,
|
|
"location": BlockDevices().get_root_block_device().name,
|
|
}
|