From 44f04c0ddc17d2087995d9cb3d56a48398dd1f8c Mon Sep 17 00:00:00 2001 From: Aashish Sharma Date: Fri, 12 Apr 2024 11:24:03 +0530 Subject: [PATCH] mgr/dashboard: provide hub Cluster HA for multi-cluster setup Fixes: https://tracker.ceph.com/issues/65499 Signed-off-by: Aashish Sharma --- .../dashboard/controllers/multi_cluster.py | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/pybind/mgr/dashboard/controllers/multi_cluster.py b/src/pybind/mgr/dashboard/controllers/multi_cluster.py index de29496e5e7a8..5239c0bdb7119 100644 --- a/src/pybind/mgr/dashboard/controllers/multi_cluster.py +++ b/src/pybind/mgr/dashboard/controllers/multi_cluster.py @@ -3,12 +3,14 @@ import base64 import json import time +from urllib.parse import urlparse import requests from .. import mgr from ..exceptions import DashboardException from ..security import Scope +from ..services.orchestrator import OrchClient from ..settings import Settings from ..tools import configure_cors from . import APIDoc, APIRouter, CreatePermission, DeletePermission, Endpoint, \ @@ -69,9 +71,11 @@ class MultiCluster(RESTController): cluster_token = self.check_cluster_connection(url, payload, username, ssl_verify, ssl_certificate) + cors_endpoints_string = self.get_cors_endpoints_string(hub_url) + self._proxy('PUT', url, 'ui-api/multi-cluster/set_cors_endpoint', - payload={'url': hub_url}, token=cluster_token, verify=ssl_verify, - cert=ssl_certificate) + payload={'url': cors_endpoints_string}, token=cluster_token, + verify=ssl_verify, cert=ssl_certificate) fsid = self._proxy('GET', url, 'api/health/get_cluster_fsid', token=cluster_token) @@ -101,6 +105,26 @@ class MultiCluster(RESTController): return False + def get_cors_endpoints_string(self, hub_url): + parsed_url = urlparse(hub_url) + hostname = parsed_url.hostname + cors_endpoints_set = set() + cors_endpoints_set.add(hub_url) + + orch = OrchClient.instance() + inventory_hosts = [host.to_json() for host in orch.hosts.list()] + + for host in inventory_hosts: + host_addr = host['addr'] + host_ip_url = hub_url.replace(hostname, host_addr) + host_hostname_url = hub_url.replace(hostname, host['hostname']) + + cors_endpoints_set.add(host_ip_url) + cors_endpoints_set.add(host_hostname_url) + + cors_endpoints_string = ", ".join(cors_endpoints_set) + return cors_endpoints_string + def check_cluster_connection(self, url, payload, username, ssl_verify, ssl_certificate): try: content = self._proxy('POST', url, 'api/auth', payload=payload, -- 2.39.5