Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vsp add host view mapping #810

Merged
merged 15 commits into from
Apr 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion delfin/drivers/hitachi/vsp/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 38 additions & 4 deletions delfin/drivers/hitachi/vsp/rest_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -261,3 +261,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, 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

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
267 changes: 267 additions & 0 deletions delfin/drivers/hitachi/vsp/vsp_stor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
DISK_STATUS_TYPE = {"NML": constants.DiskStatus.NORMAL,
"CPY": constants.DiskStatus.NORMAL,
"CPI": constants.DiskStatus.NORMAL,
Expand Down Expand Up @@ -501,3 +513,258 @@ 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:
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_with_port = HitachiVspDriver.handle_group_with_port(
host_groups)
for port in group_with_port:
kwargs = {
'method': 'host',
'port': port,
'result': host_list
}
self.handle_san_info(**kwargs)
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')
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": init_name,
"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_with_port = HitachiVspDriver.handle_group_with_port(
host_groups)
for port in group_with_port:
kwargs = {
'method': 'initator',
'port': port,
'result': initiator_list
}
self.handle_san_info(**kwargs)
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_with_port = HitachiVspDriver.handle_group_with_port(
host_groups)
for port in group_with_port:
kwargs = {
'method': 'group',
'port': port,
'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
}
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)
return view_list
except Exception as e:
LOG.error("Failed to get views from vsp")
raise e

def handle_san_info(self, **kwargs):
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'):
iscsis = self.rest_handler.get_iscsi_name(
specific_group.get('portId'),
specific_group.get('hostGroupNumber'))
else:
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:
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')
Loading