54 lines
1.4 KiB
Python
54 lines
1.4 KiB
Python
from dataclasses import dataclass
|
|
from enum import Enum
|
|
|
|
|
|
class RolePriority(Enum):
|
|
GENERAL = 0 # should be on each and every node
|
|
CRITICAL = 1 # network can't work properly without it
|
|
HIGH = 2 # network can manager without it but with some difficulty
|
|
LOW = 3 # it's just nice to have
|
|
|
|
|
|
class HardwareType(Enum):
|
|
DISK_SPACE = 1
|
|
CPU = 2
|
|
GPU = 3
|
|
RAM = 4
|
|
LONGEVITY = 5
|
|
|
|
|
|
class HardwarePriority:
|
|
hardware: HardwareType
|
|
priority: int
|
|
|
|
|
|
@dataclass
|
|
class HardwarePreferences:
|
|
priorities: dict[HardwareType, int]
|
|
|
|
def priority_of(self, hardware: HardwareType) -> int:
|
|
return self.priorities.get(hardware, 0)
|
|
|
|
|
|
class RoleStats:
|
|
def __init__(self, cls, priority: RolePriority, hardware_preferences: HardwarePreferences = None, on_demand: bool = False, minimal_percentage: int = 0):
|
|
self.name = cls.__name__
|
|
self.cls = cls
|
|
self.priority = priority
|
|
self.hardware_preferences = hardware_preferences
|
|
self.on_demand = on_demand
|
|
self.minimal_percentage = max(0, min(minimal_percentage, 100))
|
|
|
|
|
|
class RoleRegistry:
|
|
def __init__(self, role_list):
|
|
roles = {}
|
|
for role_stat in role_list:
|
|
roles[role_stat.name] = role_stat
|
|
|
|
self.roles = roles
|
|
|
|
def get_role_class_by_name(self, name):
|
|
role_stat = self.roles.get(name) if isinstance(name, str) else None
|
|
return role_stat.cls if role_stat is not None else None
|