From 5a40394f928506d14be902f33a5dc6538eacb3b0 Mon Sep 17 00:00:00 2001 From: Ricardo Marques Date: Fri, 23 Feb 2018 16:09:29 +0000 Subject: [PATCH] mgr/dashboard_v2: Add support for $PREFIX config Signed-off-by: Ricardo Marques --- .../src/app/ceph/cephfs/cephfs.service.ts | 2 +- .../src/app/ceph/cluster/monitor.service.ts | 2 +- .../app/ceph/dashboard/dashboard.service.ts | 2 +- .../table-performance-counter.service.ts | 2 +- .../ceph/rgw/services/rgw-daemon.service.ts | 2 +- .../src/app/shared/services/auth.service.ts | 4 ++-- .../shared/services/configuration.service.ts | 2 +- .../src/app/shared/services/host.service.ts | 2 +- .../src/app/shared/services/pool.service.ts | 2 +- .../shared/services/rbd-mirroring.service.ts | 2 +- .../app/shared/services/summary.service.ts | 2 +- .../app/shared/services/tcmu-iscsi.service.ts | 2 +- .../mgr/dashboard_v2/frontend/src/index.html | 5 +++- src/pybind/mgr/dashboard_v2/module.py | 23 +++++++++++-------- 14 files changed, 30 insertions(+), 24 deletions(-) diff --git a/src/pybind/mgr/dashboard_v2/frontend/src/app/ceph/cephfs/cephfs.service.ts b/src/pybind/mgr/dashboard_v2/frontend/src/app/ceph/cephfs/cephfs.service.ts index 27ff31bb782..a5c4994da45 100644 --- a/src/pybind/mgr/dashboard_v2/frontend/src/app/ceph/cephfs/cephfs.service.ts +++ b/src/pybind/mgr/dashboard_v2/frontend/src/app/ceph/cephfs/cephfs.service.ts @@ -3,7 +3,7 @@ import { Injectable } from '@angular/core'; @Injectable() export class CephfsService { - baseURL = '/api/cephfs'; + baseURL = 'api/cephfs'; constructor(private http: HttpClient) {} diff --git a/src/pybind/mgr/dashboard_v2/frontend/src/app/ceph/cluster/monitor.service.ts b/src/pybind/mgr/dashboard_v2/frontend/src/app/ceph/cluster/monitor.service.ts index 5a61870660c..32057f3b6ea 100644 --- a/src/pybind/mgr/dashboard_v2/frontend/src/app/ceph/cluster/monitor.service.ts +++ b/src/pybind/mgr/dashboard_v2/frontend/src/app/ceph/cluster/monitor.service.ts @@ -6,6 +6,6 @@ export class MonitorService { constructor(private http: HttpClient) {} getMonitor() { - return this.http.get('/api/monitor'); + return this.http.get('api/monitor'); } } diff --git a/src/pybind/mgr/dashboard_v2/frontend/src/app/ceph/dashboard/dashboard.service.ts b/src/pybind/mgr/dashboard_v2/frontend/src/app/ceph/dashboard/dashboard.service.ts index 807983cb25e..cb51cb4d71b 100644 --- a/src/pybind/mgr/dashboard_v2/frontend/src/app/ceph/dashboard/dashboard.service.ts +++ b/src/pybind/mgr/dashboard_v2/frontend/src/app/ceph/dashboard/dashboard.service.ts @@ -6,6 +6,6 @@ export class DashboardService { constructor(private http: HttpClient) {} getHealth() { - return this.http.get('/api/dashboard/health'); + return this.http.get('api/dashboard/health'); } } diff --git a/src/pybind/mgr/dashboard_v2/frontend/src/app/ceph/performance-counter/services/table-performance-counter.service.ts b/src/pybind/mgr/dashboard_v2/frontend/src/app/ceph/performance-counter/services/table-performance-counter.service.ts index 45a80ff0ce8..b6ac5d5fe3e 100644 --- a/src/pybind/mgr/dashboard_v2/frontend/src/app/ceph/performance-counter/services/table-performance-counter.service.ts +++ b/src/pybind/mgr/dashboard_v2/frontend/src/app/ceph/performance-counter/services/table-performance-counter.service.ts @@ -4,7 +4,7 @@ import { Injectable } from '@angular/core'; @Injectable() export class TablePerformanceCounterService { - private url = '/api/perf_counters'; + private url = 'api/perf_counters'; constructor(private http: HttpClient) { } diff --git a/src/pybind/mgr/dashboard_v2/frontend/src/app/ceph/rgw/services/rgw-daemon.service.ts b/src/pybind/mgr/dashboard_v2/frontend/src/app/ceph/rgw/services/rgw-daemon.service.ts index 728452b9957..907537ef2d9 100644 --- a/src/pybind/mgr/dashboard_v2/frontend/src/app/ceph/rgw/services/rgw-daemon.service.ts +++ b/src/pybind/mgr/dashboard_v2/frontend/src/app/ceph/rgw/services/rgw-daemon.service.ts @@ -4,7 +4,7 @@ import { Injectable } from '@angular/core'; @Injectable() export class RgwDaemonService { - private url = '/api/rgw/daemon'; + private url = 'api/rgw/daemon'; constructor(private http: HttpClient) { } diff --git a/src/pybind/mgr/dashboard_v2/frontend/src/app/shared/services/auth.service.ts b/src/pybind/mgr/dashboard_v2/frontend/src/app/shared/services/auth.service.ts index d5001157fed..88a7136289e 100644 --- a/src/pybind/mgr/dashboard_v2/frontend/src/app/shared/services/auth.service.ts +++ b/src/pybind/mgr/dashboard_v2/frontend/src/app/shared/services/auth.service.ts @@ -12,13 +12,13 @@ export class AuthService { } login(credentials: Credentials) { - return this.http.post('/api/auth', credentials).toPromise().then((resp: Credentials) => { + return this.http.post('api/auth', credentials).toPromise().then((resp: Credentials) => { this.authStorageService.set(resp.username); }); } logout() { - return this.http.delete('/api/auth').toPromise().then(() => { + return this.http.delete('api/auth').toPromise().then(() => { this.authStorageService.remove(); }); } diff --git a/src/pybind/mgr/dashboard_v2/frontend/src/app/shared/services/configuration.service.ts b/src/pybind/mgr/dashboard_v2/frontend/src/app/shared/services/configuration.service.ts index 80b04aa50b1..41ac7bb5196 100644 --- a/src/pybind/mgr/dashboard_v2/frontend/src/app/shared/services/configuration.service.ts +++ b/src/pybind/mgr/dashboard_v2/frontend/src/app/shared/services/configuration.service.ts @@ -6,6 +6,6 @@ export class ConfigurationService { constructor(private http: HttpClient) {} getConfigData() { - return this.http.get('/api/cluster_conf/'); + return this.http.get('api/cluster_conf/'); } } diff --git a/src/pybind/mgr/dashboard_v2/frontend/src/app/shared/services/host.service.ts b/src/pybind/mgr/dashboard_v2/frontend/src/app/shared/services/host.service.ts index 73bedce6136..3d28cd78926 100644 --- a/src/pybind/mgr/dashboard_v2/frontend/src/app/shared/services/host.service.ts +++ b/src/pybind/mgr/dashboard_v2/frontend/src/app/shared/services/host.service.ts @@ -8,7 +8,7 @@ export class HostService { } list() { - return this.http.get('/api/host').toPromise().then((resp: any) => { + return this.http.get('api/host').toPromise().then((resp: any) => { return resp; }); } diff --git a/src/pybind/mgr/dashboard_v2/frontend/src/app/shared/services/pool.service.ts b/src/pybind/mgr/dashboard_v2/frontend/src/app/shared/services/pool.service.ts index f92ed166da8..8ac6de9d5b4 100644 --- a/src/pybind/mgr/dashboard_v2/frontend/src/app/shared/services/pool.service.ts +++ b/src/pybind/mgr/dashboard_v2/frontend/src/app/shared/services/pool.service.ts @@ -8,7 +8,7 @@ export class PoolService { } rbdPoolImages(pool) { - return this.http.get(`/api/rbd/${pool}`).toPromise().then((resp: any) => { + return this.http.get(`api/rbd/${pool}`).toPromise().then((resp: any) => { return resp; }); } diff --git a/src/pybind/mgr/dashboard_v2/frontend/src/app/shared/services/rbd-mirroring.service.ts b/src/pybind/mgr/dashboard_v2/frontend/src/app/shared/services/rbd-mirroring.service.ts index cec38d1a1a1..b840b3053a0 100644 --- a/src/pybind/mgr/dashboard_v2/frontend/src/app/shared/services/rbd-mirroring.service.ts +++ b/src/pybind/mgr/dashboard_v2/frontend/src/app/shared/services/rbd-mirroring.service.ts @@ -6,6 +6,6 @@ export class RbdMirroringService { constructor(private http: HttpClient) {} get() { - return this.http.get('/api/rbdmirror'); + return this.http.get('api/rbdmirror'); } } diff --git a/src/pybind/mgr/dashboard_v2/frontend/src/app/shared/services/summary.service.ts b/src/pybind/mgr/dashboard_v2/frontend/src/app/shared/services/summary.service.ts index 0bc4566b43d..9556930ebd4 100644 --- a/src/pybind/mgr/dashboard_v2/frontend/src/app/shared/services/summary.service.ts +++ b/src/pybind/mgr/dashboard_v2/frontend/src/app/shared/services/summary.service.ts @@ -19,7 +19,7 @@ export class SummaryService { refresh() { if (this.authStorageService.isLoggedIn()) { - this.http.get('/api/summary').subscribe(data => { + this.http.get('api/summary').subscribe(data => { this.summaryDataSource.next(data); }); } diff --git a/src/pybind/mgr/dashboard_v2/frontend/src/app/shared/services/tcmu-iscsi.service.ts b/src/pybind/mgr/dashboard_v2/frontend/src/app/shared/services/tcmu-iscsi.service.ts index 2976404fc1b..2f36bb81813 100644 --- a/src/pybind/mgr/dashboard_v2/frontend/src/app/shared/services/tcmu-iscsi.service.ts +++ b/src/pybind/mgr/dashboard_v2/frontend/src/app/shared/services/tcmu-iscsi.service.ts @@ -8,7 +8,7 @@ export class TcmuIscsiService { } tcmuiscsi() { - return this.http.get('/api/tcmuiscsi').toPromise().then((resp: any) => { + return this.http.get('api/tcmuiscsi').toPromise().then((resp: any) => { return resp; }); } diff --git a/src/pybind/mgr/dashboard_v2/frontend/src/index.html b/src/pybind/mgr/dashboard_v2/frontend/src/index.html index 36dcf4def26..05a8f709116 100644 --- a/src/pybind/mgr/dashboard_v2/frontend/src/index.html +++ b/src/pybind/mgr/dashboard_v2/frontend/src/index.html @@ -3,7 +3,10 @@ Ceph - + + diff --git a/src/pybind/mgr/dashboard_v2/module.py b/src/pybind/mgr/dashboard_v2/module.py index ff6ee5e8b68..f271f8e7c5f 100644 --- a/src/pybind/mgr/dashboard_v2/module.py +++ b/src/pybind/mgr/dashboard_v2/module.py @@ -37,6 +37,14 @@ def os_exit_noop(*args): os._exit = os_exit_noop +def prepare_url_prefix(url_prefix): + """ + return '' if no prefix, or '/prefix' without slash in the end. + """ + url_prefix = urljoin('/', url_prefix) + return url_prefix.rstrip('/') + + class Module(MgrModule): """ dashboard module entrypoint @@ -80,13 +88,6 @@ class Module(MgrModule): self.log.info('server_addr: %s server_port: %s', server_addr, server_port) - def prepare_url_prefix(url_prefix): - """ - return '' if no prefix, or '/prefix' without slash in the end. - """ - url_prefix = urljoin('/', url_prefix) - return url_prefix.rstrip('/') - self._url_prefix = prepare_url_prefix(self.get_config('url_prefix', default='')) @@ -121,8 +122,8 @@ class Module(MgrModule): self.url_prefix )) - cherrypy.tree.mount(Module.ApiRoot(self), '/api') - cherrypy.tree.mount(Module.StaticRoot(), '/', config=config) + cherrypy.tree.mount(Module.ApiRoot(self), '{}/api'.format(self.url_prefix)) + cherrypy.tree.mount(Module.StaticRoot(), '{}/'.format(self.url_prefix), config=config) def serve(self): if 'COVERAGE_ENABLED' in os.environ: @@ -253,7 +254,9 @@ class StandbyModule(MgrStandbyModule): """ return template.format(delay=5) - cherrypy.tree.mount(Root(), "/", {}) + url_prefix = prepare_url_prefix(self.get_config('url_prefix', + default='')) + cherrypy.tree.mount(Root(), "{}/".format(url_prefix), {}) self.log.info("Starting engine...") cherrypy.engine.start() self.log.info("Waiting for engine...") -- 2.39.5