@@ -61,30 +61,38 @@ def __init__(self, **kwargs) -> None:
61
61
super ().__init__ ()
62
62
config = PodmanConfig ()
63
63
64
- api_kwargs = kwargs .copy ()
64
+ self . api_kwargs = kwargs .copy ()
65
65
66
- if "connection" in api_kwargs :
67
- connection = config .services [api_kwargs .get ("connection" )]
68
- api_kwargs ["base_url" ] = connection .url .geturl ()
66
+ if "connection" in self . api_kwargs :
67
+ connection = config .services [self . api_kwargs .get ("connection" )]
68
+ self . api_kwargs ["base_url" ] = connection .url .geturl ()
69
69
70
70
# Override configured identity, if provided in arguments
71
- api_kwargs ["identity" ] = kwargs .get ("identity" , str (connection .identity ))
72
- elif "base_url" not in api_kwargs :
71
+ self . api_kwargs ["identity" ] = kwargs .get ("identity" , str (connection .identity ))
72
+ elif "base_url" not in self . api_kwargs :
73
73
path = str (Path (get_runtime_dir ()) / "podman" / "podman.sock" )
74
- api_kwargs ["base_url" ] = "http+unix://" + path
75
- self .api = APIClient (** api_kwargs )
74
+ self .api_kwargs ["base_url" ] = "http+unix://" + path
76
75
77
- # Check if the connection to the Podman service is successful
78
76
try :
79
- SystemManager (client = self .api ).version ()
77
+ self .api = APIClient (** self .api_kwargs )
78
+ response = self .api .get ("_ping" )
79
+
80
+ if response .status_code != 200 :
81
+ raise PodmanConnectionError (
82
+ message = f"Unexpected response from Podman service: { response .status_code } " ,
83
+ environment = os .environ ,
84
+ host = self .api_kwargs .get ("base_url" ),
85
+ original_error = None ,
86
+ )
87
+ except PodmanConnectionError :
88
+ raise
80
89
except Exception as e :
81
- error_msg = "Failed to connect to Podman service"
82
90
raise PodmanConnectionError (
83
- message = error_msg ,
91
+ message = f"Failed to connect to Podman service: { str ( e ) } " ,
84
92
environment = os .environ ,
85
- host = api_kwargs .get ("base_url" ),
93
+ host = self . api_kwargs .get ("base_url" ),
86
94
original_error = e ,
87
- )
95
+ ) from e
88
96
89
97
def __enter__ (self ) -> "PodmanClient" :
90
98
return self
0 commit comments