From 178ca762558f4edb60435b801d3fbbb9e0c9ca19 Mon Sep 17 00:00:00 2001 From: Ricardo Marques Date: Thu, 28 Mar 2019 14:54:23 +0000 Subject: [PATCH] mgr/dashboard: Display the number of iSCSI active sessions Fixes: https://tracker.ceph.com/issues/38989 Signed-off-by: Ricardo Marques (cherry picked from commit 74e12be82b7b47f7880ac6cb8209898c3a80601f) --- src/pybind/mgr/dashboard/controllers/iscsi.py | 23 +++++++++++++++++-- .../iscsi-target-list.component.ts | 5 ++++ .../frontend/src/locale/messages.xlf | 7 ++++++ .../mgr/dashboard/services/iscsi_client.py | 5 ++++ src/pybind/mgr/dashboard/tests/test_iscsi.py | 10 +++++++- 5 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/pybind/mgr/dashboard/controllers/iscsi.py b/src/pybind/mgr/dashboard/controllers/iscsi.py index 9b4c19dcf4e1..bb3e297c91b9 100644 --- a/src/pybind/mgr/dashboard/controllers/iscsi.py +++ b/src/pybind/mgr/dashboard/controllers/iscsi.py @@ -30,10 +30,17 @@ class IscsiUi(BaseController): @ReadPermission def status(self): status = {'available': False} - if not IscsiGatewaysConfig.get_gateways_config()['gateways']: + gateways = IscsiGatewaysConfig.get_gateways_config()['gateways'] + if not gateways: status['message'] = 'There are no gateways defined' return status try: + for gateway in gateways.keys(): + try: + IscsiClient.instance(gateway_name=gateway).ping() + except RequestException: + status['message'] = 'Gateway {} is inaccessible'.format(gateway) + return status config = IscsiClient.instance().get_config() if config['version'] != IscsiUi.REQUIRED_CEPH_ISCSI_CONFIG_VERSION: status['message'] = 'Unsupported `ceph-iscsi` config version. Expected {} but ' \ @@ -105,6 +112,7 @@ class IscsiTarget(RESTController): targets = [] for target_iqn in config['targets'].keys(): target = IscsiTarget._config_to_target(target_iqn, config) + IscsiTarget._set_info(target) targets.append(target) return targets @@ -112,7 +120,9 @@ class IscsiTarget(RESTController): config = IscsiClient.instance().get_config() if target_iqn not in config['targets']: raise cherrypy.HTTPError(404) - return IscsiTarget._config_to_target(target_iqn, config) + target = IscsiTarget._config_to_target(target_iqn, config) + IscsiTarget._set_info(target) + return target @iscsi_target_task('delete', {'target_iqn': '{target_iqn}'}) def delete(self, target_iqn): @@ -564,6 +574,15 @@ class IscsiTarget(RESTController): } return target + @staticmethod + def _set_info(target): + if not target['portals']: + return + target_iqn = target['target_iqn'] + gateway_name = target['portals'][0]['host'] + target_info = IscsiClient.instance(gateway_name=gateway_name).get_targetinfo(target_iqn) + target['info'] = target_info + @staticmethod def _sorted_portals(portals): portals = portals or [] diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-list/iscsi-target-list.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-list/iscsi-target-list.component.ts index a798e58b274f..c1f66967f9b5 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-list/iscsi-target-list.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-list/iscsi-target-list.component.ts @@ -101,6 +101,11 @@ export class IscsiTargetListComponent implements OnInit, OnDestroy { name: this.i18n('Images'), prop: 'cdImages', flexGrow: 2 + }, + { + name: this.i18n('# Sessions'), + prop: 'info.num_sessions', + flexGrow: 1 } ]; diff --git a/src/pybind/mgr/dashboard/frontend/src/locale/messages.xlf b/src/pybind/mgr/dashboard/frontend/src/locale/messages.xlf index 615c8a4bfef1..307171844436 100644 --- a/src/pybind/mgr/dashboard/frontend/src/locale/messages.xlf +++ b/src/pybind/mgr/dashboard/frontend/src/locale/messages.xlf @@ -4338,6 +4338,13 @@ 1 + + # Sessions + + src/app/ceph/block/iscsi-target-list/iscsi-target-list.component.ts + 1 + + Hostname diff --git a/src/pybind/mgr/dashboard/services/iscsi_client.py b/src/pybind/mgr/dashboard/services/iscsi_client.py index e69c621b5586..887b0ca0d68f 100644 --- a/src/pybind/mgr/dashboard/services/iscsi_client.py +++ b/src/pybind/mgr/dashboard/services/iscsi_client.py @@ -198,3 +198,8 @@ class IscsiClient(RestClient): return request({ 'action': action }) + + @RestClient.api_get('/api/targetinfo/{target_iqn}') + def get_targetinfo(self, target_iqn, request=None): + logger.debug("iSCSI: Getting targetinfo: %s", target_iqn) + return request() diff --git a/src/pybind/mgr/dashboard/tests/test_iscsi.py b/src/pybind/mgr/dashboard/tests/test_iscsi.py index db88f32f0914..779f1ca22bd1 100644 --- a/src/pybind/mgr/dashboard/tests/test_iscsi.py +++ b/src/pybind/mgr/dashboard/tests/test_iscsi.py @@ -431,7 +431,10 @@ iscsi_target_response = { 'members': ['iqn.1994-05.com.redhat:rh7-client2'] } ], - 'target_controls': {} + 'target_controls': {}, + 'info': { + 'num_sessions': 0 + } } @@ -635,3 +638,8 @@ class IscsiClientMock(object): def update_targetauth(self, target_iqn, action): self.config['targets'][target_iqn]['acl_enabled'] = (action == 'enable_acl') + + def get_targetinfo(self, _): + return { + 'num_sessions': 0 + } -- 2.47.3