From 36b5c372ed107ebdc9bdd6b593ee49025c2c802f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Diot?= Date: Wed, 22 Feb 2023 19:02:49 +0100 Subject: [PATCH] Refactor Instance and remove unused method --- src/ui/src/Instances.py | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/src/ui/src/Instances.py b/src/ui/src/Instances.py index bc8ac3a60..b08ca4120 100644 --- a/src/ui/src/Instances.py +++ b/src/ui/src/Instances.py @@ -1,6 +1,6 @@ -from os.path import exists +from pathlib import Path from subprocess import run -from typing import Any, Union +from typing import Any, Optional, Union from API import API from ApiCaller import ApiCaller @@ -23,7 +23,7 @@ class Instance: _type: str, status: str, data: Any = None, - apiCaller: ApiCaller = ApiCaller(), + apiCaller: Optional[ApiCaller] = None, ) -> None: self._id = _id self.name = name @@ -39,7 +39,7 @@ class Instance: else True ) self.env = data - self.apiCaller = apiCaller + self.apiCaller = apiCaller or ApiCaller() def get_id(self) -> str: return self._id @@ -122,7 +122,7 @@ class Instances: "service", status, instance, - apiCaller, + None, ) ) elif self.__integration == "Kubernetes": @@ -172,7 +172,7 @@ class Instances: ) # Local instance - if exists("/usr/sbin/nginx"): + if Path("/usr/sbin/nginx").exists(): instances.insert( 0, Instance( @@ -180,24 +180,12 @@ class Instances: "local", "127.0.0.1", "local", - "up" if exists("/var/tmp/bunkerweb/nginx.pid") else "down", + "up" if Path("/var/tmp/bunkerweb/nginx.pid").exists() else "down", ), ) return instances - def send_custom_configs_to_instances(self) -> Union[list[str], str]: - failed_to_send: list[str] = [] - for instance in self.get_instances(): - if instance.health is False: - failed_to_send.append(instance.name) - continue - - if not instance.send_custom_configs(): - failed_to_send.append(instance.name) - - return failed_to_send or "Successfully sent custom configs to instances" - def reload_instances(self) -> Union[list[str], str]: not_reloaded: list[str] = [] for instance in self.get_instances(): @@ -210,7 +198,9 @@ class Instances: return not_reloaded or "Successfully reloaded instances" - def reload_instance(self, id: int = None, instance: Instance = None) -> str: + def reload_instance( + self, id: Optional[int] = None, instance: Optional[Instance] = None + ) -> str: if instance is None: instance = self.__instance_from_id(id)