@@ -23,10 +23,13 @@ def __init__(
2323 self .verify_ssl = False
2424
2525 if not self .base_url or not self .username or not self .password :
26- logger .error ("Portainer URL, username and password must be provided" )
27- raise ValueError ("Portainer URL, username and password must be provided" )
26+ logger .error (
27+ "Portainer URL, username and password must be provided" )
28+ raise ValueError (
29+ "Portainer URL, username and password must be provided" )
2830
29- logger .debug (f"PortainerAPIClient initialized with base URL: { self .base_url } " )
31+ logger .debug (
32+ f"PortainerAPIClient initialized with base URL: { self .base_url } " )
3033
3134 def authenticate (self ) -> str :
3235 """
@@ -52,7 +55,8 @@ def authenticate(self) -> str:
5255
5356 if not token :
5457 logger .error ("Authentication failed: No JWT token in response" )
55- raise ValueError ("Authentication failed: No JWT token in response" )
58+ raise ValueError (
59+ "Authentication failed: No JWT token in response" )
5660
5761 self .jwt_token = token
5862 logger .success ("Successfully authenticated with Portainer API" )
@@ -102,7 +106,8 @@ def get_containers(self, endpoint_id: str, docker_version: str) -> List[Dict]:
102106 )
103107 response .raise_for_status ()
104108 containers = response .json ()
105- logger .success (f"Successfully fetched { len (containers )} containers" )
109+ logger .success (
110+ f"Successfully fetched { len (containers )} containers" )
106111 return containers
107112
108113 except requests .exceptions .RequestException as e :
@@ -222,7 +227,8 @@ def find_service_location(self, service_name: str) -> Optional[Tuple[str, str]]:
222227 )
223228 return (endpoint_id , stack_id )
224229
225- logger .warning (f"Service '{ service_name } ' not found in endpoints configuration" )
230+ logger .warning (
231+ f"Service '{ service_name } ' not found in endpoints configuration" )
226232 return None
227233
228234 def check_service_health (
@@ -247,7 +253,8 @@ def check_service_health(
247253 docker_version = endpoint_info .get ("docker_version" , "v1.24" )
248254
249255 try :
250- containers = self .api_client .get_containers (endpoint_id , docker_version )
256+ containers = self .api_client .get_containers (
257+ endpoint_id , docker_version )
251258
252259 # Filter containers belonging to this service/stack
253260 service_containers = []
@@ -259,7 +266,8 @@ def check_service_health(
259266 service_containers .append (container )
260267
261268 if not service_containers :
262- logger .warning (f"No containers found for service '{ service_name } '" )
269+ logger .warning (
270+ f"No containers found for service '{ service_name } '" )
263271 return (False , service_location )
264272
265273 # Check if all containers are healthy
@@ -306,7 +314,8 @@ def start_service(self, service_name: str) -> Dict[str, Any]:
306314 endpoint_id , stack_id = location
307315
308316 if is_healthy :
309- logger .info (f"Service '{ service_name } ' is already running and healthy" )
317+ logger .info (
318+ f"Service '{ service_name } ' is already running and healthy" )
310319 return {
311320 "success" : True ,
312321 "message" : f"Service '{ service_name } ' is already running" ,
@@ -325,7 +334,8 @@ def start_service(self, service_name: str) -> Dict[str, Any]:
325334 self .api_client .stop_stack (stack_id , endpoint_id )
326335 time .sleep (5 ) # Give it some time to stop
327336 except Exception as e :
328- logger .warning (f"Error stopping service (continuing anyway): { str (e )} " )
337+ logger .warning (
338+ f"Error stopping service (continuing anyway): { str (e )} " )
329339
330340 # Start the service
331341 self .api_client .start_stack (stack_id , endpoint_id )
@@ -339,7 +349,8 @@ def start_service(self, service_name: str) -> Dict[str, Any]:
339349 }
340350
341351 except Exception as e :
342- logger .exception (f"Error starting service '{ service_name } ': { str (e )} " )
352+ logger .exception (
353+ f"Error starting service '{ service_name } ': { str (e )} " )
343354 return {"success" : False , "message" : f"Error starting service: { str (e )} " }
344355
345356 def find_service_from_url (self , referral_url : str ) -> Optional [str ]:
@@ -375,14 +386,16 @@ def find_service_from_url(self, referral_url: str) -> Optional[str]:
375386
376387 docker_version = endpoint_info .get ("docker_version" , "v1.24" )
377388 try :
378- containers = self .api_client .get_containers (endpoint_id , docker_version )
389+ containers = self .api_client .get_containers (
390+ endpoint_id , docker_version )
379391 for container in containers :
380392 labels : dict = container .get ("Labels" , {})
381393 domain_label : str = (
382394 labels .get ("home.resolve.domain" , "" ).lower ().strip ()
383395 )
384396 project_name : str = (
385- labels .get ("com.docker.compose.project" , "" ).lower ().strip ()
397+ labels .get ("com.docker.compose.project" ,
398+ "" ).lower ().strip ()
386399 )
387400
388401 # Skip if missing important labels
0 commit comments