From bbc4cae2230e6476cf64c4adc4db244ac5fd08f9 Mon Sep 17 00:00:00 2001 From: tanjy Date: Wed, 26 Jan 2022 14:38:18 +0800 Subject: [PATCH 1/7] vsp add host view mapping --- delfin/drivers/hitachi/vsp/rest_handler.py | 53 +++- delfin/drivers/hitachi/vsp/vsp_stor.py | 249 ++++++++++++++++++ .../hitachi/vsp/test_hitachi_vspstor.py | 153 +++++++++++ 3 files changed, 446 insertions(+), 9 deletions(-) diff --git a/delfin/drivers/hitachi/vsp/rest_handler.py b/delfin/drivers/hitachi/vsp/rest_handler.py index 55e34fc0b..bc7f0e141 100644 --- a/delfin/drivers/hitachi/vsp/rest_handler.py +++ b/delfin/drivers/hitachi/vsp/rest_handler.py @@ -18,7 +18,7 @@ import six from oslo_log import log as logging -from delfin import cryptor +# from delfin import cryptor from delfin import exception from delfin.drivers.hitachi.vsp import consts from delfin.drivers.utils.rest_client import RestClient @@ -73,7 +73,7 @@ def call_with_token(self, url, data, method, calltimeout): auth_key = self.session.headers.get(RestHandler.AUTH_KEY, None) if auth_key: self.session.headers[RestHandler.AUTH_KEY] \ - = cryptor.decode(auth_key) + = auth_key res = self. \ do_call(url, data, method, calltimeout) if auth_key: @@ -106,17 +106,17 @@ def get_token(self): self.session.auth = \ requests.auth.HTTPBasicAuth( self.rest_username, - cryptor.decode(self.rest_password)) + self.rest_password) res = self.call_with_token(url, data, 'POST', 30) if res.status_code == 200: succeed = True result = res.json() - self.session_id = cryptor.encode( - result.get('sessionId')) + self.session_id = \ + result.get('sessionId') access_session = 'Session %s' % result.get('token') self.session.headers[ - RestHandler.AUTH_KEY] = cryptor.encode( - access_session) + RestHandler.AUTH_KEY] = \ + access_session else: LOG.error("Login error. URL: %(url)s\n" "Reason: %(reason)s.", @@ -152,7 +152,7 @@ def logout(self): url = '%s/%s/sessions/%s' % \ (RestHandler.COMM_URL, self.storage_device_id, - cryptor.decode(self.session_id)) + self.session_id) if self.san_address: self.call(url, method='DELETE') url = None @@ -184,7 +184,8 @@ def get_device_id(self): self.device_model = system.get('model') self.serial_number = system.get('serialNumber') break - elif system.get('svpIp') == self.rest_host: + # elif system.get('svpIp') == self.rest_host: + else: self.storage_device_id = system.get('storageDeviceId') self.device_model = system.get('model') self.serial_number = system.get('serialNumber') @@ -261,3 +262,37 @@ def get_alerts(self, param, start, end): param, start, end) result_json = self.get_rest_info(url) return result_json + + def get_all_host_groups(self): + url = '%s/%s/host-groups' % \ + (RestHandler.COMM_URL, self.storage_device_id) + result_json = self.get_rest_info(url) + return result_json + + def get_specific_host_group(self, group_id): + url = '%s/%s/host-groups/%s' % \ + (RestHandler.COMM_URL, self.storage_device_id, group_id) + result_json = self.get_rest_info(url) + return result_json + + def get_host_wwn(self, port_id, group_number): + url = '%s/%s/host-wwns?portId=%s&hostGroupNumber=%s' % \ + (RestHandler.COMM_URL, self.storage_device_id, port_id, + group_number) + result_json = self.get_rest_info(url) + return result_json + + def get_iscsi_name(self, port_id, group_number): + url = '%s/%s/host-iscsis?portId=%s&hostGroupNumber=%s' % \ + (RestHandler.COMM_URL, self.storage_device_id, port_id, + group_number) + result_json = self.get_rest_info(url) + return result_json + + def get_lun_path(self, port_id, group_number): + url = '%s/%s/luns?portId=%s&hostGroupNumber=%s&' \ + 'isBasicLunInformation=true' % \ + (RestHandler.COMM_URL, self.storage_device_id, port_id, + group_number) + result_json = self.get_rest_info(url) + return result_json diff --git a/delfin/drivers/hitachi/vsp/vsp_stor.py b/delfin/drivers/hitachi/vsp/vsp_stor.py index f9f554813..e0631f19e 100644 --- a/delfin/drivers/hitachi/vsp/vsp_stor.py +++ b/delfin/drivers/hitachi/vsp/vsp_stor.py @@ -64,6 +64,18 @@ class HitachiVspDriver(driver.StorageDriver): "HNASS": constants.PortType.OTHER, "HNASU": constants.PortType.OTHER } + OS_TYPE_MAP = {"HP-UX": constants.HostOSTypes.HP_UX, + "SOLARIS": constants.HostOSTypes.SOLARIS, + "AIX": constants.HostOSTypes.AIX, + "WIN": constants.HostOSTypes.WINDOWS, + "LINUX/IRIX": constants.HostOSTypes.LINUX, + "TRU64": constants.HostOSTypes.UNKNOWN, + "OVMS": constants.HostOSTypes.OPEN_VMS, + "NETWARE": constants.HostOSTypes.UNKNOWN, + "VMWARE": constants.HostOSTypes.VMWARE_ESX, + "VMWARE_EX": constants.HostOSTypes.VMWARE_ESX, + "WIN_EX": constants.HostOSTypes.WINDOWS + } TIME_PATTERN = '%Y-%m-%dT%H:%M:%S' AUTO_PORT_SPEED = 8 * units.Gi @@ -487,3 +499,240 @@ def parse_alert(context, alert): def clear_alert(self, context, alert): pass + + @staticmethod + def get_host_info(data, storage_id, host_list, type, os_type): + if data: + host_entries = data.get('data') + if not host_entries: + return True + for host in host_entries: + if type == 'iscsi': + host_id = host.get('hostIscsiId') + host_name = host.get('iscsiNickname') if \ + host.get('iscsiNickname') != '-' \ + else host.get('iscsiName') + else: + host_id = host.get('hostWwnId') + host_name = host.get('wwnNickname') if \ + host.get('wwnNickname') != '-' \ + else host.get('hostWwn') + host_result = { + "name": host_name, + "storage_id": storage_id, + "native_storage_host_id": host_id.replace(",", "_"), + "os_type": os_type, + "status": constants.HostStatus.NORMAL + } + host_list.append(host_result) + return True + + def list_storage_hosts(self, context): + try: + host_groups = self.rest_handler.get_all_host_groups() + host_list = [] + if not host_groups: + return host_list + group_entries = host_groups.get('data') + for group in group_entries: + kwargs = { + 'method': 'host', + 'group': group, + 'result': host_list + } + self.handle_san_info(**kwargs) + LOG.error(host_list) + return host_list + except Exception as e: + LOG.error("Failed to get host from vsp") + raise e + + @staticmethod + def get_initiator_from_host(data, storage_id, initiator_list, type): + if data: + host_entries = data.get('data') + if not host_entries: + return True + for host in host_entries: + if type == 'iscsi': + initiator_id = host.get('hostIscsiId') + init_type = constants.InitiatorType.ISCSI + init_name = host.get('iscsiName') + else: + initiator_id = host.get('hostWwnId') + init_type = constants.InitiatorType.FC + init_name = host.get('hostWwn') + init_result = { + "name": init_name, + "storage_id": storage_id, + "native_storage_host_initiator_id": + initiator_id.replace(",", "_"), + "wwn": init_name, + "status": constants.InitiatorStatus.ONLINE, + "type": init_type, + "alias": host.get('portId'), + "native_storage_host_id": initiator_id.replace(",", "_") + } + initiator_list.append(init_result) + return True + + def list_storage_host_initiators(self, context): + try: + initiator_list = [] + host_groups = self.rest_handler.get_all_host_groups() + if not host_groups: + return initiator_list + group_entries = host_groups.get('data') + for group in group_entries: + kwargs = { + 'method': 'initator', + 'group': group, + 'result': initiator_list + } + self.handle_san_info(**kwargs) + LOG.error(initiator_list) + return initiator_list + except Exception as e: + LOG.error("Failed to get initiators from vsp") + raise e + + @staticmethod + def get_host_ids(data, target, host_ids, host_grp_relation_list, + storage_id, group_id): + if data: + host_entries = data.get('data') + if not host_entries: + return True + for host in host_entries: + if host.get(target): + host_ids.append(host.get(target).replace(",", "_")) + relation = { + 'storage_id': storage_id, + 'native_storage_host_group_id': group_id, + 'native_storage_host_id': + host.get(target).replace(",", "_") + } + host_grp_relation_list.append(relation) + + def list_storage_host_groups(self, context): + try: + host_groups = self.rest_handler.get_all_host_groups() + host_group_list = [] + host_grp_relation_list = [] + if not host_groups: + return host_group_list + group_data = host_groups.get('data') + for group in group_data: + kwargs = { + 'method': 'group', + 'group': group, + 'result': host_grp_relation_list, + 'group_list': host_group_list + } + self.handle_san_info(**kwargs) + result = { + 'storage_host_groups': host_group_list, + 'storage_host_grp_host_rels': host_grp_relation_list + } + LOG.error(result) + return result + except Exception: + LOG.error("Failed to get host_groups from vsp") + raise + + def handle_lun_path(self, **kwargs): + view_list = [] + views = self.rest_handler.get_lun_path( + kwargs.get('port'), kwargs.get('group')) + if not views: + return None + view_entries = views.get('data') + if not view_entries: + return None + for view in view_entries: + group_id = '%s_%s' % (view.get('portId'), + view.get('hostGroupNumber')) + view_result = { + "name": view.get('lunId'), + "native_storage_host_group_id": group_id, + "storage_id": self.storage_id, + "native_volume_id": HitachiVspDriver.to_vsp_lun_id_format( + view.get('ldevId')), + "native_masking_view_id": view.get('lunId').replace(",", "_"), + } + kwargs.get('result').append(view_result) + return view_list + + def list_masking_views(self, context): + try: + view_list = [] + host_groups = self.rest_handler.get_all_host_groups() + if not host_groups: + return view_list + group_data = host_groups.get('data') + for group in group_data: + kwargs = { + 'group': group.get('hostGroupNumber'), + 'port': group.get('portId'), + 'result': view_list + } + self.handle_lun_path(**kwargs) + LOG.error(view_list) + return view_list + except Exception as e: + LOG.error("Failed to get views from vsp") + raise e + + def handle_san_info(self, **kwargs): + specific_group = self.rest_handler.get_specific_host_group( + kwargs.get('group').get('hostGroupId')) + iscsis = None + wwns = None + result = None + if specific_group.get('iscsiName'): + iscsis = self.rest_handler.get_iscsi_name( + kwargs.get('group').get('portId'), + kwargs.get('group').get('hostGroupNumber')) + else: + wwns = self.rest_handler.get_host_wwn( + kwargs.get('group').get('portId'), + kwargs.get('group').get('hostGroupNumber')) + if kwargs.get('method') == 'host': + os_type = HitachiVspDriver.OS_TYPE_MAP.get( + kwargs.get('group').get('hostMode'), + constants.HostOSTypes.UNKNOWN) + if specific_group.get('iscsiName'): + result = HitachiVspDriver.get_host_info( + iscsis, self.storage_id, kwargs.get('result'), + 'iscsi', os_type) + else: + result = HitachiVspDriver.get_host_info( + wwns, self.storage_id, kwargs.get('result'), 'fc', os_type) + elif kwargs.get('method') == 'group': + host_ids = [] + group_id = kwargs.get('group').get('hostGroupId').replace(",", "_") + if specific_group.get('iscsiName'): + HitachiVspDriver.get_host_ids( + iscsis, 'hostIscsiId', host_ids, + kwargs.get('result'), self.storage_id, + group_id) + else: + HitachiVspDriver.get_host_ids( + wwns, 'hostWwnId', host_ids, + kwargs.get('result'), self.storage_id, + group_id) + group_result = { + "name": kwargs.get('group').get('hostGroupName'), + "storage_id": self.storage_id, + "native_storage_host_group_id": group_id, + "storage_hosts": ','.join(host_ids) + } + kwargs.get('group_list').append(group_result) + else: + if specific_group.get('iscsiName'): + result = HitachiVspDriver.get_initiator_from_host( + iscsis, self.storage_id, kwargs.get('result'), 'iscsi') + else: + result = HitachiVspDriver.get_initiator_from_host( + wwns, self.storage_id, kwargs.get('result'), 'fc') + return result diff --git a/delfin/tests/unit/drivers/hitachi/vsp/test_hitachi_vspstor.py b/delfin/tests/unit/drivers/hitachi/vsp/test_hitachi_vspstor.py index 52df5aaef..62fdaee05 100644 --- a/delfin/tests/unit/drivers/hitachi/vsp/test_hitachi_vspstor.py +++ b/delfin/tests/unit/drivers/hitachi/vsp/test_hitachi_vspstor.py @@ -454,6 +454,115 @@ def __init__(self): 'ipv4_mask': '255.255.0.0', 'ipv6': None }] +GET_ALL_GROUPS = { + "data": [ + { + "hostGroupId": "CL1-A,0", + "portId": "CL1-A", + "hostGroupNumber": 0, + "hostGroupName": "1A-G00", + "hostMode": "LINUX/IRIX" + } + ] +} +GET_SINGLE_WWN_GROUP = { + "hostGroupId": "CL1-A,0", + "portId": "CL1-A", + "hostGroupNumber": 0, + "hostGroupName": "1A-G00", + "hostMode": "LINUX/IRIX" +} +GET_SINGLE_ISCSI_GROUP = { + "hostGroupId": "CL1-A,0", + "portId": "CL1-A", + "hostGroupNumber": 0, + "hostGroupName": "1A-G00", + "hostMode": "LINUX/IRIX", + "iscsiName": "iqn.ewdhehdhdhh" +} +GET_HOST_WWN = { + "data": [ + { + "hostWwnId": "CL1-A,0,21000024ff8f5296", + "portId": "CL1-A", + "hostGroupNumber": 0, + "hostGroupName": "1A-G00", + "hostWwn": "21000024ff8f5296", + "wwnNickname": "-" + } + ] +} +GET_HOST_ISCSI = { + "data": [ + { + "hostIscsiId": "CL1-A,0,iqn.ewdhehdhdhh", + "portId": "CL1-A", + "hostGroupNumber": 0, + "hostGroupName": "3C-G00", + "iscsiName": "iqn.ewdhehdhdhh", + "iscsiNickname": "test_tjy" + } + ] +} +GET_LUN_PATH = { + "data": [ + { + "lunId": "CL1-A,1,1", + "portId": "CL1-A", + "hostGroupNumber": 0, + "hostMode": "LINUX/IRIX", + "lun": 1, + "ldevId": 1 + } + ] +} +initator_result = [ + { + 'name': '21000024ff8f5296', + 'storage_id': '12345', + 'native_storage_host_initiator_id': 'CL1-A_0_21000024ff8f5296', + 'wwn': '21000024ff8f5296', + 'status': 'online', + 'type': 'fc', + 'alias': 'CL1-A', + 'native_storage_host_id': 'CL1-A_0_21000024ff8f5296' + } +] +host_result = [ + { + 'name': 'test_tjy', + 'storage_id': '12345', + 'native_storage_host_id': 'CL1-A_0_iqn.ewdhehdhdhh', + 'os_type': 'Linux', + 'status': 'normal' + } +] +view_result = [ + { + 'name': 'CL1-A,1,1', + 'native_storage_host_group_id': 'CL1-A_0', + 'storage_id': '12345', + 'native_volume_id': '00:00:01', + 'native_masking_view_id': 'CL1-A_1_1' + } +] +groups_result = { + 'storage_host_groups': [ + { + 'name': '1A-G00', + 'storage_id': '12345', + 'native_storage_host_group_id': 'CL1-A_0', + 'storage_hosts': 'CL1-A_0_iqn.ewdhehdhdhh' + } + ], + 'storage_host_grp_host_rels': [ + { + 'storage_id': '12345', + 'native_storage_host_group_id': 'CL1-A_0', + 'native_storage_host_id': 'CL1-A_0_iqn.ewdhehdhdhh' + } + ] +} def create_driver(): @@ -551,3 +660,47 @@ def test_list_ports(self, mock_detail, mock_all): mock_detail.return_value = GET_DETAIL_PORT port = HitachiVspDriver(**ACCESS_INFO).list_ports(context) self.assertEqual(port, port_result) + + @mock.patch.object(RestHandler, 'get_specific_host_group') + @mock.patch.object(RestHandler, 'get_all_host_groups') + @mock.patch.object(RestHandler, 'get_host_wwn') + def test_host_initiators(self, mock_wwn, mock_groups, mock_group): + RestHandler.login = mock.Mock(return_value=None) + mock_groups.return_value = GET_ALL_GROUPS + mock_group.return_value = GET_SINGLE_WWN_GROUP + mock_wwn.return_value = GET_HOST_WWN + initiators = HitachiVspDriver( + **ACCESS_INFO).list_storage_host_initiators(context) + self.assertEqual(initiators, initator_result) + + @mock.patch.object(RestHandler, 'get_specific_host_group') + @mock.patch.object(RestHandler, 'get_all_host_groups') + @mock.patch.object(RestHandler, 'get_iscsi_name') + def test_hosts(self, mock_iscsi, mock_groups, mock_group): + RestHandler.login = mock.Mock(return_value=None) + mock_groups.return_value = GET_ALL_GROUPS + mock_group.return_value = GET_SINGLE_ISCSI_GROUP + mock_iscsi.return_value = GET_HOST_ISCSI + hosts = HitachiVspDriver(**ACCESS_INFO).list_storage_hosts(context) + self.assertEqual(hosts, host_result) + + @mock.patch.object(RestHandler, 'get_all_host_groups') + @mock.patch.object(RestHandler, 'get_lun_path') + def test_masking_views(self, mock_view, mock_groups): + RestHandler.login = mock.Mock(return_value=None) + mock_groups.return_value = GET_ALL_GROUPS + mock_view.return_value = GET_LUN_PATH + views = HitachiVspDriver(**ACCESS_INFO).list_masking_views(context) + self.assertEqual(views, view_result) + + @mock.patch.object(RestHandler, 'get_specific_host_group') + @mock.patch.object(RestHandler, 'get_all_host_groups') + @mock.patch.object(RestHandler, 'get_iscsi_name') + def test_host_groups(self, mock_iscsi, mock_groups, mock_group): + RestHandler.login = mock.Mock(return_value=None) + mock_groups.return_value = GET_ALL_GROUPS + mock_group.return_value = GET_SINGLE_ISCSI_GROUP + mock_iscsi.return_value = GET_HOST_ISCSI + groups = \ + HitachiVspDriver(**ACCESS_INFO).list_storage_host_groups(context) + self.assertEqual(groups, groups_result) From 2c8e0520b5ec8173417deb56b75d715465cc739a Mon Sep 17 00:00:00 2001 From: tanjy Date: Wed, 26 Jan 2022 14:41:39 +0800 Subject: [PATCH 2/7] vsp add host view mapping --- delfin/drivers/hitachi/vsp/rest_handler.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/delfin/drivers/hitachi/vsp/rest_handler.py b/delfin/drivers/hitachi/vsp/rest_handler.py index bc7f0e141..349c54678 100644 --- a/delfin/drivers/hitachi/vsp/rest_handler.py +++ b/delfin/drivers/hitachi/vsp/rest_handler.py @@ -18,7 +18,7 @@ import six from oslo_log import log as logging -# from delfin import cryptor +from delfin import cryptor from delfin import exception from delfin.drivers.hitachi.vsp import consts from delfin.drivers.utils.rest_client import RestClient @@ -73,7 +73,7 @@ def call_with_token(self, url, data, method, calltimeout): auth_key = self.session.headers.get(RestHandler.AUTH_KEY, None) if auth_key: self.session.headers[RestHandler.AUTH_KEY] \ - = auth_key + = cryptor.decode(auth_key) res = self. \ do_call(url, data, method, calltimeout) if auth_key: @@ -106,17 +106,17 @@ def get_token(self): self.session.auth = \ requests.auth.HTTPBasicAuth( self.rest_username, - self.rest_password) + cryptor.decode(self.rest_password)) res = self.call_with_token(url, data, 'POST', 30) if res.status_code == 200: succeed = True result = res.json() - self.session_id = \ - result.get('sessionId') + self.session_id = cryptor.encode( + result.get('sessionId')) access_session = 'Session %s' % result.get('token') self.session.headers[ - RestHandler.AUTH_KEY] = \ - access_session + RestHandler.AUTH_KEY] = cryptor.encode( + access_session) else: LOG.error("Login error. URL: %(url)s\n" "Reason: %(reason)s.", @@ -152,7 +152,7 @@ def logout(self): url = '%s/%s/sessions/%s' % \ (RestHandler.COMM_URL, self.storage_device_id, - self.session_id) + cryptor.decode(self.session_id)) if self.san_address: self.call(url, method='DELETE') url = None From 06eb298aa94e4f3956d062e1b3b9388f859f40a2 Mon Sep 17 00:00:00 2001 From: tanjy Date: Wed, 26 Jan 2022 14:42:24 +0800 Subject: [PATCH 3/7] vsp add host view mapping --- delfin/drivers/hitachi/vsp/rest_handler.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/delfin/drivers/hitachi/vsp/rest_handler.py b/delfin/drivers/hitachi/vsp/rest_handler.py index 349c54678..ff5a465ea 100644 --- a/delfin/drivers/hitachi/vsp/rest_handler.py +++ b/delfin/drivers/hitachi/vsp/rest_handler.py @@ -184,8 +184,7 @@ def get_device_id(self): self.device_model = system.get('model') self.serial_number = system.get('serialNumber') break - # elif system.get('svpIp') == self.rest_host: - else: + elif system.get('svpIp') == self.rest_host: self.storage_device_id = system.get('storageDeviceId') self.device_model = system.get('model') self.serial_number = system.get('serialNumber') From 4c1cdd72b9ae6822908298bc02b1d774132cee35 Mon Sep 17 00:00:00 2001 From: tanjy Date: Wed, 26 Jan 2022 14:55:32 +0800 Subject: [PATCH 4/7] vsp add host view mapping --- delfin/drivers/hitachi/vsp/vsp_stor.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/delfin/drivers/hitachi/vsp/vsp_stor.py b/delfin/drivers/hitachi/vsp/vsp_stor.py index e0631f19e..2e68554dd 100644 --- a/delfin/drivers/hitachi/vsp/vsp_stor.py +++ b/delfin/drivers/hitachi/vsp/vsp_stor.py @@ -541,7 +541,6 @@ def list_storage_hosts(self, context): 'result': host_list } self.handle_san_info(**kwargs) - LOG.error(host_list) return host_list except Exception as e: LOG.error("Failed to get host from vsp") @@ -562,11 +561,13 @@ def get_initiator_from_host(data, storage_id, initiator_list, type): initiator_id = host.get('hostWwnId') init_type = constants.InitiatorType.FC init_name = host.get('hostWwn') + for initiator in initiator_list: + if initiator.get('wwn') == init_name: + continue init_result = { "name": init_name, "storage_id": storage_id, - "native_storage_host_initiator_id": - initiator_id.replace(",", "_"), + "native_storage_host_initiator_id": init_name, "wwn": init_name, "status": constants.InitiatorStatus.ONLINE, "type": init_type, @@ -590,7 +591,6 @@ def list_storage_host_initiators(self, context): 'result': initiator_list } self.handle_san_info(**kwargs) - LOG.error(initiator_list) return initiator_list except Exception as e: LOG.error("Failed to get initiators from vsp") @@ -634,7 +634,6 @@ def list_storage_host_groups(self, context): 'storage_host_groups': host_group_list, 'storage_host_grp_host_rels': host_grp_relation_list } - LOG.error(result) return result except Exception: LOG.error("Failed to get host_groups from vsp") @@ -677,7 +676,6 @@ def list_masking_views(self, context): 'result': view_list } self.handle_lun_path(**kwargs) - LOG.error(view_list) return view_list except Exception as e: LOG.error("Failed to get views from vsp") From 6eaa1d00a1883f1c421e1830ea80d2a387a0646d Mon Sep 17 00:00:00 2001 From: tanjy Date: Wed, 26 Jan 2022 14:58:27 +0800 Subject: [PATCH 5/7] vsp add host view mapping --- delfin/tests/unit/drivers/hitachi/vsp/test_hitachi_vspstor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/delfin/tests/unit/drivers/hitachi/vsp/test_hitachi_vspstor.py b/delfin/tests/unit/drivers/hitachi/vsp/test_hitachi_vspstor.py index 62fdaee05..43c5a5956 100644 --- a/delfin/tests/unit/drivers/hitachi/vsp/test_hitachi_vspstor.py +++ b/delfin/tests/unit/drivers/hitachi/vsp/test_hitachi_vspstor.py @@ -520,7 +520,7 @@ def __init__(self): { 'name': '21000024ff8f5296', 'storage_id': '12345', - 'native_storage_host_initiator_id': 'CL1-A_0_21000024ff8f5296', + 'native_storage_host_initiator_id': '21000024ff8f5296', 'wwn': '21000024ff8f5296', 'status': 'online', 'type': 'fc', From 5a47a662110a4d9cda15ce62ff60a85fef70806b Mon Sep 17 00:00:00 2001 From: tanjy Date: Thu, 10 Feb 2022 17:47:36 +0800 Subject: [PATCH 6/7] vsp host view do some optimize --- delfin/drivers/hitachi/vsp/consts.py | 2 +- delfin/drivers/hitachi/vsp/rest_handler.py | 6 +- delfin/drivers/hitachi/vsp/vsp_stor.py | 136 ++++++++++-------- .../hitachi/vsp/test_hitachi_vspstor.py | 30 ++-- 4 files changed, 101 insertions(+), 73 deletions(-) diff --git a/delfin/drivers/hitachi/vsp/consts.py b/delfin/drivers/hitachi/vsp/consts.py index b8538606e..29bd9b98e 100644 --- a/delfin/drivers/hitachi/vsp/consts.py +++ b/delfin/drivers/hitachi/vsp/consts.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -SOCKET_TIMEOUT = 90 +SOCKET_TIMEOUT = 180 ERROR_SESSION_INVALID_CODE = 403 ERROR_SESSION_IS_BEING_USED_CODE = 409 BLOCK_SIZE = 512 diff --git a/delfin/drivers/hitachi/vsp/rest_handler.py b/delfin/drivers/hitachi/vsp/rest_handler.py index ff5a465ea..b489dae75 100644 --- a/delfin/drivers/hitachi/vsp/rest_handler.py +++ b/delfin/drivers/hitachi/vsp/rest_handler.py @@ -268,9 +268,9 @@ def get_all_host_groups(self): result_json = self.get_rest_info(url) return result_json - def get_specific_host_group(self, group_id): - url = '%s/%s/host-groups/%s' % \ - (RestHandler.COMM_URL, self.storage_device_id, group_id) + def get_specific_host_group(self, port_id): + url = '%s/%s/host-groups?portId=%s' % \ + (RestHandler.COMM_URL, self.storage_device_id, port_id) result_json = self.get_rest_info(url) return result_json diff --git a/delfin/drivers/hitachi/vsp/vsp_stor.py b/delfin/drivers/hitachi/vsp/vsp_stor.py index 2e68554dd..2f82ba38c 100644 --- a/delfin/drivers/hitachi/vsp/vsp_stor.py +++ b/delfin/drivers/hitachi/vsp/vsp_stor.py @@ -500,6 +500,22 @@ def parse_alert(context, alert): def clear_alert(self, context, alert): pass + @staticmethod + def handle_group_with_port(group_info): + group_list = {} + if not group_info: + return group_list + group_entries = group_info.get('data') + for group in group_entries: + if group_list.get(group.get('portId')): + group_list[group.get('portId')].append( + group.get('hostGroupNumber')) + else: + group_list[group.get('portId')] = [] + group_list[group.get('portId')].append( + group.get('hostGroupNumber')) + return group_list + @staticmethod def get_host_info(data, storage_id, host_list, type, os_type): if data: @@ -533,11 +549,12 @@ def list_storage_hosts(self, context): host_list = [] if not host_groups: return host_list - group_entries = host_groups.get('data') - for group in group_entries: + group_with_port = HitachiVspDriver.handle_group_with_port( + host_groups) + for port in group_with_port: kwargs = { 'method': 'host', - 'group': group, + 'port': port, 'result': host_list } self.handle_san_info(**kwargs) @@ -583,11 +600,12 @@ def list_storage_host_initiators(self, context): host_groups = self.rest_handler.get_all_host_groups() if not host_groups: return initiator_list - group_entries = host_groups.get('data') - for group in group_entries: + group_with_port = HitachiVspDriver.handle_group_with_port( + host_groups) + for port in group_with_port: kwargs = { 'method': 'initator', - 'group': group, + 'port': port, 'result': initiator_list } self.handle_san_info(**kwargs) @@ -621,11 +639,12 @@ def list_storage_host_groups(self, context): host_grp_relation_list = [] if not host_groups: return host_group_list - group_data = host_groups.get('data') - for group in group_data: + group_with_port = HitachiVspDriver.handle_group_with_port( + host_groups) + for port in group_with_port: kwargs = { 'method': 'group', - 'group': group, + 'port': port, 'result': host_grp_relation_list, 'group_list': host_group_list } @@ -682,55 +701,56 @@ def list_masking_views(self, context): raise e def handle_san_info(self, **kwargs): - specific_group = self.rest_handler.get_specific_host_group( - kwargs.get('group').get('hostGroupId')) - iscsis = None - wwns = None - result = None - if specific_group.get('iscsiName'): - iscsis = self.rest_handler.get_iscsi_name( - kwargs.get('group').get('portId'), - kwargs.get('group').get('hostGroupNumber')) - else: - wwns = self.rest_handler.get_host_wwn( - kwargs.get('group').get('portId'), - kwargs.get('group').get('hostGroupNumber')) - if kwargs.get('method') == 'host': - os_type = HitachiVspDriver.OS_TYPE_MAP.get( - kwargs.get('group').get('hostMode'), - constants.HostOSTypes.UNKNOWN) - if specific_group.get('iscsiName'): - result = HitachiVspDriver.get_host_info( - iscsis, self.storage_id, kwargs.get('result'), - 'iscsi', os_type) - else: - result = HitachiVspDriver.get_host_info( - wwns, self.storage_id, kwargs.get('result'), 'fc', os_type) - elif kwargs.get('method') == 'group': - host_ids = [] - group_id = kwargs.get('group').get('hostGroupId').replace(",", "_") + groups = self.rest_handler.get_specific_host_group( + kwargs.get('port')) + group_data = groups.get('data') + for specific_group in group_data: + iscsis = None + wwns = None if specific_group.get('iscsiName'): - HitachiVspDriver.get_host_ids( - iscsis, 'hostIscsiId', host_ids, - kwargs.get('result'), self.storage_id, - group_id) + iscsis = self.rest_handler.get_iscsi_name( + specific_group.get('portId'), + specific_group.get('hostGroupNumber')) else: - HitachiVspDriver.get_host_ids( - wwns, 'hostWwnId', host_ids, - kwargs.get('result'), self.storage_id, - group_id) - group_result = { - "name": kwargs.get('group').get('hostGroupName'), - "storage_id": self.storage_id, - "native_storage_host_group_id": group_id, - "storage_hosts": ','.join(host_ids) - } - kwargs.get('group_list').append(group_result) - else: - if specific_group.get('iscsiName'): - result = HitachiVspDriver.get_initiator_from_host( - iscsis, self.storage_id, kwargs.get('result'), 'iscsi') + wwns = self.rest_handler.get_host_wwn( + specific_group.get('portId'), + specific_group.get('hostGroupNumber')) + if kwargs.get('method') == 'host': + os_type = HitachiVspDriver.OS_TYPE_MAP.get( + specific_group.get('hostMode'), + constants.HostOSTypes.UNKNOWN) + if specific_group.get('iscsiName'): + HitachiVspDriver.get_host_info( + iscsis, self.storage_id, kwargs.get('result'), + 'iscsi', os_type) + else: + HitachiVspDriver.get_host_info( + wwns, self.storage_id, + kwargs.get('result'), 'fc', os_type) + elif kwargs.get('method') == 'group': + host_ids = [] + group_id = specific_group.get('hostGroupId').replace(",", "_") + if specific_group.get('iscsiName'): + HitachiVspDriver.get_host_ids( + iscsis, 'hostIscsiId', host_ids, + kwargs.get('result'), self.storage_id, + group_id) + else: + HitachiVspDriver.get_host_ids( + wwns, 'hostWwnId', host_ids, + kwargs.get('result'), self.storage_id, + group_id) + group_result = { + "name": specific_group.get('hostGroupName'), + "storage_id": self.storage_id, + "native_storage_host_group_id": group_id, + "storage_hosts": ','.join(host_ids) + } + kwargs.get('group_list').append(group_result) else: - result = HitachiVspDriver.get_initiator_from_host( - wwns, self.storage_id, kwargs.get('result'), 'fc') - return result + if specific_group.get('iscsiName'): + HitachiVspDriver.get_initiator_from_host( + iscsis, self.storage_id, kwargs.get('result'), 'iscsi') + else: + HitachiVspDriver.get_initiator_from_host( + wwns, self.storage_id, kwargs.get('result'), 'fc') diff --git a/delfin/tests/unit/drivers/hitachi/vsp/test_hitachi_vspstor.py b/delfin/tests/unit/drivers/hitachi/vsp/test_hitachi_vspstor.py index 43c5a5956..95e0bdcb6 100644 --- a/delfin/tests/unit/drivers/hitachi/vsp/test_hitachi_vspstor.py +++ b/delfin/tests/unit/drivers/hitachi/vsp/test_hitachi_vspstor.py @@ -466,19 +466,27 @@ def __init__(self): ] } GET_SINGLE_WWN_GROUP = { - "hostGroupId": "CL1-A,0", - "portId": "CL1-A", - "hostGroupNumber": 0, - "hostGroupName": "1A-G00", - "hostMode": "LINUX/IRIX" + "data": [ + { + "hostGroupId": "CL1-A,0", + "portId": "CL1-A", + "hostGroupNumber": 0, + "hostGroupName": "1A-G00", + "hostMode": "LINUX/IRIX" + } + ] } GET_SINGLE_ISCSI_GROUP = { - "hostGroupId": "CL1-A,0", - "portId": "CL1-A", - "hostGroupNumber": 0, - "hostGroupName": "1A-G00", - "hostMode": "LINUX/IRIX", - "iscsiName": "iqn.ewdhehdhdhh" + "data": [ + { + "hostGroupId": "CL1-A,0", + "portId": "CL1-A", + "hostGroupNumber": 0, + "hostGroupName": "1A-G00", + "hostMode": "LINUX/IRIX", + "iscsiName": "iqn.ewdhehdhdhh" + } + ] } GET_HOST_WWN = { "data": [ From 564173655838948b9dcc2dc2431e2fdc3a536c88 Mon Sep 17 00:00:00 2001 From: tanjy Date: Fri, 11 Feb 2022 11:31:41 +0800 Subject: [PATCH 7/7] vsp deviceid optimize --- delfin/drivers/hitachi/vsp/rest_handler.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/delfin/drivers/hitachi/vsp/rest_handler.py b/delfin/drivers/hitachi/vsp/rest_handler.py index b489dae75..7d85fc397 100644 --- a/delfin/drivers/hitachi/vsp/rest_handler.py +++ b/delfin/drivers/hitachi/vsp/rest_handler.py @@ -177,14 +177,14 @@ def get_device_id(self): system_info = storage_systems.get('data') for system in system_info: succeed = True - if system.get('model') in consts.SUPPORTED_VSP_SERIES: - if system.get('ctl1Ip') == self.rest_host or \ - system.get('ctl2Ip') == self.rest_host: + if system.get('svpIp'): + if system.get('svpIp') == self.rest_host: self.storage_device_id = system.get('storageDeviceId') self.device_model = system.get('model') self.serial_number = system.get('serialNumber') break - elif system.get('svpIp') == self.rest_host: + elif system.get('ctl1Ip') == self.rest_host or \ + system.get('ctl2Ip') == self.rest_host: self.storage_device_id = system.get('storageDeviceId') self.device_model = system.get('model') self.serial_number = system.get('serialNumber')