Skip to content

Commit

Permalink
vsp change get volume's rule when it's id is not continuity (#965)
Browse files Browse the repository at this point in the history
  • Loading branch information
tanjiangyu-ghca authored Dec 20, 2022
1 parent 7e44e32 commit c3080b5
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 21 deletions.
2 changes: 2 additions & 0 deletions delfin/drivers/hitachi/vsp/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@
LDEV_NUMBER_OF_PER_REQUEST = 300
SUPPORTED_VSP_SERIES = ('VSP G350', 'VSP G370', 'VSP G700', 'VSP G900',
'VSP F350', 'VSP F370', 'VSP F700', 'VSP F900')
# the max number when get volumes in a request
MAX_VOLUME_NUMBER = 16384
12 changes: 11 additions & 1 deletion delfin/drivers/hitachi/vsp/rest_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import threading
import time

import requests
import six
Expand Down Expand Up @@ -221,7 +222,7 @@ def get_all_pools(self):

def get_volumes(self, head_id,
max_number=consts.LDEV_NUMBER_OF_PER_REQUEST):
url = '%s/%s/ldevs?headLdevId=%s&count=%s' % \
url = '%s/%s/ldevs?headLdevId=%s&count=%s&ldevOption=defined' % \
(RestHandler.COMM_URL, self.storage_device_id, head_id,
max_number)
result_json = self.get_rest_info(url)
Expand Down Expand Up @@ -296,3 +297,12 @@ def get_lun_path(self, port_id, group_number):
group_number)
result_json = self.get_rest_info(url)
return result_json

def get_volumes_with_defined(self):
url = '%s/%s/ldevs?ldevOption=defined&count=%s' % \
(RestHandler.COMM_URL, self.storage_device_id,
consts.MAX_VOLUME_NUMBER)
LOG.info('get volume start time:%s' % time.time())
result_json = self.get_rest_info(url, timeout=None)
LOG.info('get volume end time:%s' % time.time())
return result_json
44 changes: 28 additions & 16 deletions delfin/drivers/hitachi/vsp/vsp_stor.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,25 +215,37 @@ def to_vsp_lun_id_format(lun_id):
return result

def list_volumes(self, context):
head_id = 0
is_end = False
volume_list = []
while is_end is False:
is_end = self.get_volumes_paginated(volume_list, head_id)
head_id += consts.LDEV_NUMBER_OF_PER_REQUEST
try:
volume_list = []
volumes = self.rest_handler.get_volumes_with_defined()
if not volumes:
return volume_list
volume_list = self.parse_volumes(volumes)
if len(volumes.get('data')) >= consts.MAX_VOLUME_NUMBER:
head_id = volumes.get('data')[-1].get('ldevId') + 1
while True:
volumes_info = self.rest_handler.get_volumes(head_id)
if not volumes_info or not volumes_info.get('data'):
break
volume_list.extend(self.parse_volumes(volumes_info))
head_id = volumes_info.get('data')[-1].get('ldevId') + 1
except exception.DelfinException as err:
err_msg = "Failed to get volume from hitachi vsp: %s" % \
(six.text_type(err))
LOG.error(err_msg)
raise err
except Exception as e:
err_msg = "Failed to get volume from hitachi vsp: %s" % \
(six.text_type(e))
LOG.error(err_msg)
raise exception.InvalidResults(err_msg)
return volume_list

def get_volumes_paginated(self, volume_list, head_id):
def parse_volumes(self, volumes):
try:
if head_id > 10000:
return True
volumes_info = self.rest_handler.get_volumes(head_id)
if not volumes_info or not volumes_info.get('data'):
return True
volumes = volumes_info.get('data')
volume_list = []
volumes = volumes.get('data')
for volume in volumes:
if volume.get('emulationType') == 'NOT DEFINED':
continue
orig_pool_id = volume.get('poolId')
compressed = False
deduplicated = False
Expand Down Expand Up @@ -283,7 +295,7 @@ def get_volumes_paginated(self, volume_list, head_id):
}

volume_list.append(v)
return False
return volume_list
except exception.DelfinException as err:
err_msg = "Failed to get volumes metrics from hitachi vsp: %s" % \
(six.text_type(err))
Expand Down
4 changes: 0 additions & 4 deletions delfin/tests/unit/drivers/hitachi/vsp/test_hitachi_vspstor.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,6 @@ def __init__(self):
"ssid": "0004",
"resourceGroupId": 0,
"isAluaEnabled": False
},
{
"ldevId": 0,
"emulationType": "NOT DEFINED",
}
]
}
Expand Down

0 comments on commit c3080b5

Please sign in to comment.