Skip to content

Commit

Permalink
Soft mode for sections in config file
Browse files Browse the repository at this point in the history
  • Loading branch information
romanov committed Sep 5, 2022
1 parent 31223a7 commit 3839513
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion sla/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def load(self, filename: str):

def read_from_dict(self, raw_data: dict):
for section_name in self.__fields__:
section_data: dict = raw_data.get(section_name, dict())
section_data: dict = raw_data.get(section_name)
section: BaseSectionModel = self.__getattribute__(section_name)
self.__setattr__(
section_name,
Expand Down
23 changes: 15 additions & 8 deletions sla/sla.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ def __init__(self, config_file: str, log_level: str, log_dest: str) -> None:
self.policies: dict = dict()

def _load_devices(self):
for device in config.Devices.Devices:
self.devices.update(
{
device.name: SLADevice(
**device.to_sla_device()
)
}
)
if config.Policies.Policies:
for device in config.Devices.Devices:
self.devices.update(
{
device.name: SLADevice(
**device.to_sla_device()
)
}
)
self.devices.update(
{
'simplesla-local': SLADevice(
Expand All @@ -39,6 +40,8 @@ def _load_devices(self):
)

def _load_policies(self):
if not config.Policies.Policies:
return
for policy in config.Policies.Policies:
self.policies.update(
{
Expand All @@ -50,6 +53,8 @@ def _load_policies(self):
)

def _load_services(self):
if not config.Services.Services:
return
for service in config.Services.Services:
self.services.update(
{
Expand All @@ -66,6 +71,8 @@ def _load_services(self):
)

def _load_service_groups(self):
if not config.ServicesGroups.ServicesGroups:
return
for service_group in config.ServicesGroups.ServicesGroups:
sub_services: list[SubService] = list()
for sub in service_group.services:
Expand Down

0 comments on commit 3839513

Please sign in to comment.