Skip to content

Commit 44f04c0

Browse files
author
Aashish Sharma
committed
mgr/dashboard: provide hub Cluster HA for multi-cluster setup
Fixes: https://tracker.ceph.com/issues/65499 Signed-off-by: Aashish Sharma <[email protected]>
1 parent ebd9263 commit 44f04c0

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

src/pybind/mgr/dashboard/controllers/multi_cluster.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
import base64
44
import json
55
import time
6+
from urllib.parse import urlparse
67

78
import requests
89

910
from .. import mgr
1011
from ..exceptions import DashboardException
1112
from ..security import Scope
13+
from ..services.orchestrator import OrchClient
1214
from ..settings import Settings
1315
from ..tools import configure_cors
1416
from . import APIDoc, APIRouter, CreatePermission, DeletePermission, Endpoint, \
@@ -69,9 +71,11 @@ def auth(self, url: str, cluster_alias: str, username: str,
6971
cluster_token = self.check_cluster_connection(url, payload, username,
7072
ssl_verify, ssl_certificate)
7173

74+
cors_endpoints_string = self.get_cors_endpoints_string(hub_url)
75+
7276
self._proxy('PUT', url, 'ui-api/multi-cluster/set_cors_endpoint',
73-
payload={'url': hub_url}, token=cluster_token, verify=ssl_verify,
74-
cert=ssl_certificate)
77+
payload={'url': cors_endpoints_string}, token=cluster_token,
78+
verify=ssl_verify, cert=ssl_certificate)
7579

7680
fsid = self._proxy('GET', url, 'api/health/get_cluster_fsid', token=cluster_token)
7781

@@ -101,6 +105,26 @@ def auth(self, url: str, cluster_alias: str, username: str,
101105

102106
return False
103107

108+
def get_cors_endpoints_string(self, hub_url):
109+
parsed_url = urlparse(hub_url)
110+
hostname = parsed_url.hostname
111+
cors_endpoints_set = set()
112+
cors_endpoints_set.add(hub_url)
113+
114+
orch = OrchClient.instance()
115+
inventory_hosts = [host.to_json() for host in orch.hosts.list()]
116+
117+
for host in inventory_hosts:
118+
host_addr = host['addr']
119+
host_ip_url = hub_url.replace(hostname, host_addr)
120+
host_hostname_url = hub_url.replace(hostname, host['hostname'])
121+
122+
cors_endpoints_set.add(host_ip_url)
123+
cors_endpoints_set.add(host_hostname_url)
124+
125+
cors_endpoints_string = ", ".join(cors_endpoints_set)
126+
return cors_endpoints_string
127+
104128
def check_cluster_connection(self, url, payload, username, ssl_verify, ssl_certificate):
105129
try:
106130
content = self._proxy('POST', url, 'api/auth', payload=payload,

0 commit comments

Comments
 (0)