From 675f35f2a60e8b4f93baf03aa1746b96d3f86f29 Mon Sep 17 00:00:00 2001 From: Erki Date: Sun, 12 May 2024 12:00:19 +0300 Subject: [PATCH] Provide extension methods --- api/__init__.py | 4 ++++ api/api_extensions.py | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 api/api_extensions.py diff --git a/api/__init__.py b/api/__init__.py index 64e386d..471a3cc 100644 --- a/api/__init__.py +++ b/api/__init__.py @@ -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 diff --git a/api/api_extensions.py b/api/api_extensions.py new file mode 100644 index 0000000..02a5bde --- /dev/null +++ b/api/api_extensions.py @@ -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