]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: provide hub Cluster HA for multi-cluster setup 56847/head
authorAashish Sharma <aasharma@li-e74156cc-2f67-11b2-a85c-e98659a63c5c.ibm.com>
Fri, 12 Apr 2024 05:54:03 +0000 (11:24 +0530)
committerAashish Sharma <aasharma@li-e74156cc-2f67-11b2-a85c-e98659a63c5c.ibm.com>
Tue, 16 Apr 2024 06:24:51 +0000 (11:54 +0530)
Fixes: https://tracker.ceph.com/issues/65499
Signed-off-by: Aashish Sharma <aasharma@redhat.com>
src/pybind/mgr/dashboard/controllers/multi_cluster.py

index de29496e5e7a8eeb0400665de25c988c6947d52b..5239c0bdb71191d99b3bc04d1d1e5a0246937fe0 100644 (file)
@@ -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,