File tree Expand file tree Collapse file tree 1 file changed +14
-4
lines changed
src/openstack_mcp_server/tools Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change 1+ import atexit
2+
13import openstack
24
35from openstack import connection
@@ -10,18 +12,26 @@ class OpenStackConnectionManager:
1012
1113 _connection : connection .Connection | None = None
1214
13- # TODO: Try/Catch disconnection by token expired case
1415 @classmethod
1516 def get_connection (cls ) -> connection .Connection :
16- """OpenStack Connection) """
17+ """OpenStack Connection"""
1718 if cls ._connection is None :
1819 openstack .enable_logging (debug = config .MCP_DEBUG_MODE )
1920 cls ._connection = openstack .connect (cloud = config .MCP_CLOUD_NAME )
21+ atexit .register (cls ._cleanup )
2022 return cls ._connection
2123
22- # TODO: Close connection
24+ @classmethod
25+ def _cleanup (cls ) -> None :
26+ """Cleanup method called at program exit"""
27+ if cls ._connection is not None :
28+ cls ._connection .close ()
29+ cls ._connection = None
30+
31+
32+ _openstack_connection_manager = OpenStackConnectionManager ()
2333
2434
2535def get_openstack_conn ():
2636 """Get OpenStack Connection"""
27- return OpenStackConnectionManager .get_connection ()
37+ return _openstack_connection_manager .get_connection ()
You can’t perform that action at this time.
0 commit comments