Skip to content

Commit

Permalink
Update vplex masking_view id (#824)
Browse files Browse the repository at this point in the history
  • Loading branch information
luojiagen authored May 19, 2022
1 parent 59475e2 commit 32769d1
Show file tree
Hide file tree
Showing 4 changed files with 400 additions and 0 deletions.
11 changes: 11 additions & 0 deletions delfin/drivers/dell_emc/vplex/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
'ib': constants.PortType.IB,
'other': constants.PortType.OTHER,
}

INITIATOR_DESCRIPTION = {
'iscsi': constants.InitiatorType.ISCSI,
'fc': constants.InitiatorType.FC,
}

PORT_LOGICAL_TYPE_MAP = {
'front-end': constants.PortLogicalType.FRONTEND,
'back-end': constants.PortLogicalType.BACKEND,
Expand Down Expand Up @@ -60,3 +66,8 @@
"lost communication": constants.ControllerStatus.OFFLINE,
"unknown": constants.ControllerStatus.UNKNOWN
}
HOST_TYPE_MAP = {
"hpux": constants.HostOSTypes.HP_UX,
"aix": constants.HostOSTypes.AIX,
"unknown": constants.HostOSTypes.UNKNOWN
}
10 changes: 10 additions & 0 deletions delfin/drivers/dell_emc/vplex/rest_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,13 @@ def get_engine_director_hardware_port_resp(self):
url = '%s/engines/*/directors/*/hardware/ports/*' % consts.BASE_CONTEXT
response = self.get_rest_info(url)
return response

def get_initiators_resp(self):
url = '%s/clusters/*/exports/initiator-ports/*' % consts.BASE_CONTEXT
response = self.get_rest_info(url)
return response

def get_storage_views(self):
url = '%s/clusters/*/exports/storage-views/*' % consts.BASE_CONTEXT
response = self.get_rest_info(url)
return response
155 changes: 155 additions & 0 deletions delfin/drivers/dell_emc/vplex/vplex_stor.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,161 @@ def analyse_speed(speed_value):
speed = speed * units.k
return speed

def list_masking_views(self, content):
try:
view_list = []
view_response = self.rest_handler.get_storage_views()
storage_view_list = self.get_attributes_from_response(
view_response)
if storage_view_list:
host_list = self.list_storage_hosts(content)
host_map = {}
for host_value in host_list:
host_map[host_value.get('name')] = \
host_value.get('native_storage_host_id')
for storage_view in storage_view_list:
virtual_volumes = storage_view.get('virtual-volumes')
initiators_list = storage_view.get('initiators')
view_name = storage_view.get('name')
if initiators_list:
for initiator_info in initiators_list:
native_masking_view_id = initiator_info
native_storage_host_id = host_map.get(
initiator_info)
if virtual_volumes:
for virtual_volume in virtual_volumes:
volume_value = virtual_volume.split(
',')
native_volume_id = volume_value[2]
volume_id = native_volume_id.replace(
':', '')
view_map = {
"name": view_name,
"description": view_name,
"storage_id": self.storage_id,
"native_masking_view_id":
native_masking_view_id + volume_id,
"native_port_group_id":
"port_group_" + initiator_info,
"native_volume_id":
native_volume_id,
"native_storage_host_id":
native_storage_host_id
}
view_list.append(view_map)
return view_list
except Exception:
LOG.error("Failed to get view from vplex")
raise

def list_storage_host_initiators(self, content):
try:
initiators_list = []
initiators_response = self.rest_handler.get_initiators_resp()
initiators_info_list = self.get_attributes_from_response(
initiators_response)
for initiators_map in initiators_info_list:
initiators_type = initiators_map.get('port_type')
initiators_type_arr = initiators_type.split('-')
initiators_type_index = initiators_type_arr[0]
description = consts.INITIATOR_DESCRIPTION.get(
initiators_type_index,
constants.InitiatorType.UNKNOWN)
initiator_item = {
"name": initiators_map.get('name'),
"type": description,
"storage_id": self.storage_id,
"native_storage_host_initiator_id":
initiators_map.get('port-wwn'),
"wwn": initiators_map.get('port-wwn'),
"alias": initiators_map.get('port-wwn'),
"status": constants.InitiatorStatus.ONLINE,
"native_storage_host_id": initiators_map.get('port-wwn')
}
initiators_list.append(initiator_item)
return initiators_list
except Exception:
LOG.error("Failed to get host_initiators from vplex")
raise

def list_storage_hosts(self, content):
try:
hosts_list = []
host_response = self.rest_handler.get_initiators_resp()
hosts_info_list = self.get_attributes_from_response(host_response)
for host_info in hosts_info_list:
os_type = host_info.get('type')
host_dict = {
"name": host_info.get('name'),
"storage_id": self.storage_id,
"os_type": consts.HOST_TYPE_MAP.get(
os_type, constants.HostOSTypes.UNKNOWN),
"native_storage_host_id": host_info.get('port-wwn'),
"status": constants.HostStatus.NORMAL
}
hosts_list.append(host_dict)
return hosts_list
except Exception:
LOG.error("Failed to get storage_host from vplex")
raise

def list_port_groups(self, context):
try:
port_groups_list = []
port_group_relation_list = []
port_group_response = self.rest_handler.get_storage_views()
storage_view_list = self.get_attributes_from_response(
port_group_response)
for storage_view in storage_view_list:
ports = storage_view.get('ports')
initiators_info_list = storage_view.get('initiators')
if initiators_info_list:
for initiator_info in initiators_info_list:
port_group_map = {
"name": "port_group_" + initiator_info,
"description": "port_group_" + initiator_info,
"storage_id": self.storage_id,
"native_port_group_id": "port_group_"
+ initiator_info,
"ports": ports
}
if ports:
for port in ports:
port_group_relation = {
'storage_id': self.storage_id,
'native_port_group_id': "port_group_"
+ initiator_info,
'native_port_id': port
}
port_group_relation_list.append(
port_group_relation)
port_groups_list.append(port_group_map)
port_groups_result = {
'port_groups': port_groups_list,
'port_grp_port_rels': port_group_relation_list
}
return port_groups_result
except Exception:
LOG.error("Failed to get port_groups from vplex")
raise

@staticmethod
def get_attributes_from_response(response):
attributes_list = []
if response:
contexts = response.get("context")
for context in contexts:
child_map = {}
attributes = context.get("attributes")
context_type = context.get("type")
child_map['port_type'] = context_type
for children in attributes:
name = children.get("name")
value = children.get("value")
child_map[name] = value
attributes_list.append(child_map)
return attributes_list


@staticmethod
def handle_detail_list(detail_info, detail_map, split):
Expand Down
Loading

0 comments on commit 32769d1

Please sign in to comment.