Provide extension methods

This commit is contained in:
Erki 2024-05-12 12:00:19 +03:00
parent bc5eb0561d
commit 675f35f2a6
2 changed files with 21 additions and 0 deletions

View File

@ -2,3 +2,7 @@ import grpc
from .sys_mon_agent_api_pb2 import AgentConfiguration, AgentConfigurationResponse, MonitoringStats, MonitoredServiceState, MonitoredService, MonitoredStorage
from .sys_mon_agent_api_pb2_grpc import AgentServicer, AgentStub, add_AgentServicer_to_server
from .api_extensions import _MonitoringStats_get_storage_by_name, _MonitoringStats_get_service_by_name
MonitoringStats.storage_by_name = _MonitoringStats_get_storage_by_name
MonitoringStats.service_by_name = _MonitoringStats_get_service_by_name

17
api/api_extensions.py Normal file
View File

@ -0,0 +1,17 @@
from typing import Optional
from .sys_mon_agent_api_pb2 import MonitoringStats, MonitoredStorage, MonitoredService
def _MonitoringStats_get_storage_by_name(self: MonitoringStats, name: str) -> Optional[MonitoredStorage]:
for storage in self.storage:
if storage.name == name:
return storage
return None
def _MonitoringStats_get_service_by_name(self: MonitoringStats, name: str) -> Optional[MonitoredService]:
for service in self.services:
if service.name == name:
return service
return None