Files
watcher-visio/dashboard/openstack_utils/connect.py
Nikolay Tatarinov 2a0e0c216a
Some checks failed
CI / ci (push) Failing after 14s
Refactor code for consistency and readability
- Standardized string quotes across multiple files to use double quotes for consistency.
- Improved formatting of JSON dumps in mock data for better readability.
- Enhanced the structure of various functions and data definitions for clarity.
- Updated test cases to reflect changes in data structure and ensure accuracy.
2026-02-07 18:01:49 +03:00

23 lines
827 B
Python

import openstack
from openstack.connection import Connection
from watcher_visio.settings import OPENSTACK_CLOUD, OPENSTACK_REGION_NAME
def check_openstack() -> dict:
"""
Lightweight check that OpenStack is reachable (connection only).
Returns {"status": "ok"} or {"status": "error", "message": "..."}.
"""
try:
conn = openstack.connect(cloud=OPENSTACK_CLOUD, region_name=OPENSTACK_REGION_NAME)
if conn is None:
return {"status": "error", "message": "No connection"}
return {"status": "ok"}
except Exception as e:
return {"status": "error", "message": str(e) or "Connection failed"}
def get_connection() -> Connection:
connection = openstack.connect(cloud=OPENSTACK_CLOUD, region_name=OPENSTACK_REGION_NAME)
return connection