-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathbase.py
More file actions
37 lines (25 loc) · 991 Bytes
/
base.py
File metadata and controls
37 lines (25 loc) · 991 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import atexit
import openstack
from openstack import connection
from openstack_mcp_server import config
class OpenStackConnectionManager:
"""OpenStack Connection Manager"""
_connection: connection.Connection | None = None
@classmethod
def get_connection(cls) -> connection.Connection:
"""OpenStack Connection"""
if cls._connection is None:
openstack.enable_logging(debug=config.MCP_DEBUG_MODE)
cls._connection = openstack.connect(cloud=config.MCP_CLOUD_NAME)
atexit.register(cls._cleanup)
return cls._connection
@classmethod
def _cleanup(cls) -> None:
"""Cleanup method called at program exit"""
if cls._connection is not None:
cls._connection.close()
cls._connection = None
_openstack_connection_manager = OpenStackConnectionManager()
def get_openstack_conn():
"""Get OpenStack Connection"""
return _openstack_connection_manager.get_connection()