added config service manager to CoreEmu and made it possible to create a session and nodes with config services from a script
This commit is contained in:
parent
191a9e9909
commit
dcc683dd38
8 changed files with 41 additions and 37 deletions
|
@ -40,12 +40,6 @@ class ConfigService(abc.ABC):
|
|||
configs = self.default_configs[:]
|
||||
self._define_config(configs)
|
||||
|
||||
def __hash__(self) -> int:
|
||||
return hash(self.name)
|
||||
|
||||
def __eq__(self, other: "ConfigService") -> bool:
|
||||
return self.name == other.name
|
||||
|
||||
@property
|
||||
@abc.abstractmethod
|
||||
def name(self) -> str:
|
||||
|
|
|
@ -1,23 +1,21 @@
|
|||
import logging
|
||||
import pathlib
|
||||
from typing import List
|
||||
from typing import List, Type
|
||||
|
||||
from core import utils
|
||||
from core.configservice.base import ConfigService
|
||||
from core.errors import CoreError
|
||||
from core.nodes.base import CoreNode
|
||||
|
||||
|
||||
class ConfigServiceManager:
|
||||
def __init__(self):
|
||||
self.services = {}
|
||||
|
||||
def set_service(self, node: CoreNode, name: str) -> None:
|
||||
def get_service(self, name: str) -> Type[ConfigService]:
|
||||
service_class = self.services.get(name)
|
||||
if service_class in node.config_services:
|
||||
raise CoreError(f"node already has service {name}")
|
||||
service = service_class(node)
|
||||
node.config_services.add(service)
|
||||
if service_class is None:
|
||||
raise CoreError(f"service does not exit {name}")
|
||||
return service_class
|
||||
|
||||
def add(self, service: ConfigService) -> None:
|
||||
name = service.name
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue