Skip to content

Commit

Permalink
svc add host mapping view (#801)
Browse files Browse the repository at this point in the history
  • Loading branch information
tanjiangyu-ghca authored May 6, 2022
1 parent e53d3a1 commit 21d151c
Show file tree
Hide file tree
Showing 3 changed files with 262 additions and 0 deletions.
122 changes: 122 additions & 0 deletions delfin/drivers/ibm/storwize_svc/ssh_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,21 @@ class SSHHandler(object):
ALERT_NOT_FOUND_CODE = 'CMMVC8275E'
BLOCK_SIZE = 512
BYTES_TO_BIT = 8
OS_TYPE_MAP = {'generic': constants.HostOSTypes.UNKNOWN,
'hpux': constants.HostOSTypes.HP_UX,
'openvms': constants.HostOSTypes.OPEN_VMS,
'tpgs': constants.HostOSTypes.UNKNOWN,
'vvol': constants.HostOSTypes.UNKNOWN
}
INITIATOR_STATUS_MAP = {'active': constants.InitiatorStatus.ONLINE,
'offline': constants.InitiatorStatus.OFFLINE,
'inactive': constants.InitiatorStatus.ONLINE
}
HOST_STATUS_MAP = {'online': constants.HostStatus.NORMAL,
'offline': constants.HostStatus.OFFLINE,
'degraded': constants.HostStatus.DEGRADED,
'mask': constants.HostStatus.NORMAL,
}

def __init__(self, **kwargs):
self.ssh_pool = SSHPool(**kwargs)
Expand Down Expand Up @@ -1044,3 +1059,110 @@ def get_latest_perf_timestamp(self):
if latest_time < occur_time:
latest_time = occur_time
return latest_time

def list_storage_hosts(self, storage_id):
try:
host_list = []
hosts = self.exec_ssh_command('lshost')
host_res = hosts.split('\n')
for i in range(1, len(host_res)):
if host_res[i] is None or host_res[i] == '':
continue
control_str = ' '.join(host_res[i].split())
str_info = control_str.split(' ')
host_id = str_info[0]
detail_command = 'lshost %s' % host_id
deltail_info = self.exec_ssh_command(detail_command)
host_map = {}
self.handle_detail(deltail_info, host_map, split=' ')
status = SSHHandler.HOST_STATUS_MAP.get(host_map.get('status'))
host_result = {
"name": host_map.get('name'),
"storage_id": storage_id,
"native_storage_host_id": host_map.get('id'),
"os_type": SSHHandler.OS_TYPE_MAP.get(
host_map.get('type', '').lower()),
"status": status
}
host_list.append(host_result)
return host_list
except Exception as e:
LOG.error("Failed to get host metrics from svc")
raise e

def list_masking_views(self, storage_id):
try:
view_list = []
hosts = self.exec_ssh_command('lshostvdiskmap')
host_res = hosts.split('\n')
for i in range(1, len(host_res)):
if host_res[i] is None or host_res[i] == '':
continue
control_str = ' '.join(host_res[i].split())
str_info = control_str.split(' ')
if len(str_info) > 3:
host_id = str_info[0]
vdisk_id = str_info[3]
view_id = '%s_%s' % (str_info[0], str_info[3])
view_result = {
"name": view_id,
"native_storage_host_id": host_id,
"storage_id": storage_id,
"native_volume_id": vdisk_id,
"native_masking_view_id": view_id,
}
view_list.append(view_result)
return view_list
except Exception as e:
LOG.error("Failed to get view metrics from svc")
raise e

def list_storage_host_initiators(self, storage_id):
try:
initiator_list = []
hosts = self.exec_ssh_command('lshost')
host_res = hosts.split('\n')
for i in range(1, len(host_res)):
if host_res[i] is None or host_res[i] == '':
continue
control_str = ' '.join(host_res[i].split())
str_info = control_str.split(' ')
host_id = str_info[0]
detail_command = 'lshost %s' % host_id
deltail_info = self.exec_ssh_command(detail_command)
init_name = None
type = None
host_id = None
for host in deltail_info.split('\n'):
if host:
strinfo = host.split(' ', 1)
key = strinfo[0]
value = None
if len(strinfo) > 1:
value = strinfo[1]
if key == 'WWPN':
init_name = value
type = 'fc'
elif key == 'iscsi_name':
init_name = value
type = 'iscsi'
elif key == 'id':
host_id = value
elif key == 'state' and init_name:
status = SSHHandler.INITIATOR_STATUS_MAP.get(value)
init_result = {
"name": init_name,
"storage_id": storage_id,
"native_storage_host_initiator_id": init_name,
"wwn": init_name,
"status": status,
"type": type,
"native_storage_host_id": host_id
}
initiator_list.append(init_result)
init_name = None
type = None
return initiator_list
except Exception as e:
LOG.error("Failed to get initiators metrics from svc")
raise e
9 changes: 9 additions & 0 deletions delfin/drivers/ibm/storwize_svc/storwize_svc.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,12 @@ def get_capabilities(context, filters=None):

def get_latest_perf_timestamp(self, context):
return self.ssh_hanlder.get_latest_perf_timestamp()

def list_storage_hosts(self, context):
return self.ssh_hanlder.list_storage_hosts(self.storage_id)

def list_masking_views(self, context):
return self.ssh_hanlder.list_masking_views(self.storage_id)

def list_storage_host_initiators(self, context):
return self.ssh_hanlder.list_storage_host_initiators(self.storage_id)
131 changes: 131 additions & 0 deletions delfin/tests/unit/drivers/ibm/storwize_svc/test_ibm_storwize_svc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1366,6 +1366,113 @@ def __init__(self):
}, values={
1638346330000: 0.0
})]
get_all_hosts = """id name
1 host1
"""
get_host_summery = """id 38
name tjy_test_iscsi
port_count 3
type generic
mask 11111111111111111111111111111111111111
iogrp_count 4
status online
site_id
site_name
host_cluster_id
host_cluster_name
WWPN 21000024FF543B0C
node_logged_in_count 1
state inactive
WWPN 21000024FF438098
node_logged_in_count 1
state active
WWPN 21000024FF41C461
node_logged_in_count 1
state inactive
"""
host_result = [
{
'name': 'tjy_test_iscsi',
'storage_id': '12345',
'native_storage_host_id': '38',
'os_type': 'Unknown',
'status': 'normal'
}
]
get_all_views = """id name SCSI_id vdisk_id vdisk_name
2 Solaris11.3_57 0 27 PG_1
6 hwstorage_8.44.133.80 0 24 wyktest
7 VNX-WIN8-TEST 0 31 SVC-WIN8_test
14 pd_esx6 0 65 pd_taiping0
14 pd_esx6 1 66 pd_taiping1
14 pd_esx6 2 67 pd_taiping2
"""
view_result = [
{
'name': '2_27',
'native_storage_host_id': '2',
'storage_id': '12345',
'native_volume_id': '27',
'native_masking_view_id': '2_27'
}, {
'name': '6_24',
'native_storage_host_id': '6',
'storage_id': '12345',
'native_volume_id': '24',
'native_masking_view_id': '6_24'
}, {
'name': '7_31',
'native_storage_host_id': '7',
'storage_id': '12345',
'native_volume_id': '31',
'native_masking_view_id': '7_31'
}, {
'name': '14_65',
'native_storage_host_id': '14',
'storage_id': '12345',
'native_volume_id': '65',
'native_masking_view_id': '14_65'
}, {
'name': '14_66',
'native_storage_host_id': '14',
'storage_id': '12345',
'native_volume_id': '66',
'native_masking_view_id': '14_66'
}, {
'name': '14_67',
'native_storage_host_id': '14',
'storage_id': '12345',
'native_volume_id': '67',
'native_masking_view_id': '14_67'
}
]
init_result = [
{
'name': '21000024FF543B0C',
'storage_id': '12345',
'native_storage_host_initiator_id': '21000024FF543B0C',
'wwn': '21000024FF543B0C',
'status': 'online',
'type': 'fc',
'native_storage_host_id': '38'
}, {
'name': '21000024FF438098',
'storage_id': '12345',
'native_storage_host_initiator_id': '21000024FF438098',
'wwn': '21000024FF438098',
'status': 'online',
'type': 'fc',
'native_storage_host_id': '38'
}, {
'name': '21000024FF41C461',
'storage_id': '12345',
'native_storage_host_initiator_id': '21000024FF41C461',
'wwn': '21000024FF41C461',
'status': 'online',
'type': 'fc',
'native_storage_host_id': '38'
}
]


def create_driver():
Expand Down Expand Up @@ -1492,3 +1599,27 @@ def test_collect_perf_metrics(self, mock_ssh_get, mock_file_list,
resource_metrics,
start_time, end_time)
self.assertEqual(metrics[0][1]['resource_name'], 'powerha')

@mock.patch.object(SSHHandler, 'do_exec')
@mock.patch.object(SSHPool, 'get')
def test_list_hosts(self, mock_ssh_get, mock_host):
mock_ssh_get.return_value = {paramiko.SSHClient()}
mock_host.side_effect = [get_all_hosts, get_host_summery]
host = self.driver.list_storage_hosts(context)
self.assertEqual(host, host_result)

@mock.patch.object(SSHHandler, 'do_exec')
@mock.patch.object(SSHPool, 'get')
def test_masking_views(self, mock_ssh_get, mock_view):
mock_ssh_get.return_value = {paramiko.SSHClient()}
mock_view.return_value = get_all_views
view = self.driver.list_masking_views(context)
self.assertEqual(view, view_result)

@mock.patch.object(SSHHandler, 'do_exec')
@mock.patch.object(SSHPool, 'get')
def test_list_host_initiators(self, mock_ssh_get, mock_host):
mock_ssh_get.return_value = {paramiko.SSHClient()}
mock_host.side_effect = [get_all_hosts, get_host_summery]
init = self.driver.list_storage_host_initiators(context)
self.assertEqual(init, init_result)

0 comments on commit 21d151c

Please sign in to comment.