From 22fb3541f5626492ebf5706e7e0b4f905c71d337 Mon Sep 17 00:00:00 2001 From: huangpeng5 <1298695987@qq.com> Date: Tue, 30 Jul 2024 15:49:05 +0800 Subject: [PATCH] 1.set case_sensitive to false. 2.check config when do set_up --- .../oceanstorPacific/client/dme_client.py | 38 ++++++++-------- .../oceanstorPacific/client/rest_client.py | 5 ++- .../community/community_operate_share.py | 3 +- .../oceanstorPacific/plugin/plugin_factory.py | 12 ++++-- .../suyan_gfs/suyan_gfs_change_access.py | 24 +++++++---- .../suyan_gfs_check_update_storage.py | 43 ++++++++++--------- .../suyan_gfs/suyan_gfs_operate_share.py | 39 +++++++++-------- .../plugin/suyan_gfs/suyan_gfs_share_tier.py | 12 +++--- .../oceanstorPacific/utils/constants.py | 2 + .../oceanstorPacific/utils/driver_config.py | 4 +- 10 files changed, 103 insertions(+), 79 deletions(-) diff --git a/Manila/file_driver_dir/huawei/oceanstorPacific/client/dme_client.py b/Manila/file_driver_dir/huawei/oceanstorPacific/client/dme_client.py index e7dc0da..f70c174 100644 --- a/Manila/file_driver_dir/huawei/oceanstorPacific/client/dme_client.py +++ b/Manila/file_driver_dir/huawei/oceanstorPacific/client/dme_client.py @@ -131,7 +131,7 @@ def login(self): "userName": self.driver_config.user_name, "value": self.driver_config.user_password } - self.init_http_head(data, self.login_url) + self.init_http_head() # do login LOG.info("Begin to login DME storage, the login url is %s", self.login_url) res = self._session.put( @@ -199,32 +199,32 @@ def create_gfs_dtree(self, gfs_dtree_param): return result def add_ipaddress_to_gfs(self, gfs_params): - url = '/rest/fileservice/v1/gfs/dpc-auth-ip-addresses' + url = '/rest/fileservice/v1/gfs/dpc-auth-clients/add' result = self.call(url, data=gfs_params, method='POST') self._assert_result(result, "add the ip addresses of the dpc to the gfs failed,") return result def remove_ipaddress_from_gfs(self, gfs_params): - url = '/rest/fileservice/v1/gfs/dpc-auth-ip-addresses' - result = self.call(url, data=gfs_params, method='DELETE') + url = '/rest/fileservice/v1/gfs/dpc-auth-clients/delete' + result = self.call(url, data=gfs_params, method='POST') self._assert_result(result, "delete the ip addresses of the dpc to the gfs failed,") return result def change_gfs_size(self, modify_param): - url = '/rest/fileservice/v1/gfs' - result = self.call(url, data=modify_param, method='PUT') + url = '/rest/fileservice/v1/gfs/modify' + result = self.call(url, data=modify_param, method='POST') self._assert_result(result, "Change GFS size failed,") return result def change_gfs_quota_size(self, modify_param): - url = '/rest/fileservice/v1/gfs/quotas' - result = self.call(url, data=modify_param, method='PUT') + url = '/rest/fileservice/v1/gfs/quotas/modify' + result = self.call(url, data=modify_param, method='POST') self._assert_result(result, "Change GFS quota size failed,") return result def change_gfs_dtree_size(self, modify_param): - url = '/rest/fileservice/v1/gfs/dtrees/quotas' - result = self.call(url, data=modify_param, method='PUT') + url = '/rest/fileservice/v1/gfs/dtrees/quotas/modify' + result = self.call(url, data=modify_param, method='POST') self._assert_result(result, "Change GFS dtree size failed,") return result @@ -238,7 +238,7 @@ def query_gfs_detail(self, name_locator): return result def query_gfs_dtree_detail(self, name_locator): - url = '/rest/fileservice/v1/gfs/dtrees/detail/query' + url = '/rest/fileservice/v1/gfs/dtrees/detail-query' data = { "name_locator": name_locator } @@ -372,19 +372,19 @@ def delete_gfs_tier_grade_policy(self, delete_param): return result def modify_gfs_tier_grade_policy(self, modify_param): - url = '/rest/fileservice/v1/gfs/tier-placement-policies' - result = self.call(url, data=modify_param, method='PUT') + url = '/rest/fileservice/v1/gfs/tier-placement-policies/modify' + result = self.call(url, data=modify_param, method='POST') self._assert_result(result, 'Modify GFS tier grade policy failed,') return result def modify_gfs_tier_migrate_policy(self, modify_param): - url = '/rest/fileservice/v1/gfs/tier-migration-policies' - result = self.call(url, data=modify_param, method='PUT') + url = '/rest/fileservice/v1/gfs/tier-migration-policies/modify' + result = self.call(url, data=modify_param, method='POST') self._assert_result(result, 'Modify GFS tier migrate policy failed,') return result def create_gfs_qos_policy(self, qos_param): - url = '/rest/fileservice/v1/gfs/qos' + url = '/rest/fileservice/v1/gfs/qos/create' result = self.call(url, data=qos_param, method='POST') self._assert_result(result, 'Create GFS qos policy failed, ') return result @@ -393,11 +393,11 @@ def query_gfs_qos_policy(self, param): url = '/rest/fileservice/v1/gfs/qos/query' result = self.call(url, data=param, method='POST') self._assert_result(result, 'Get gfs qos from gfs name failed,') - return result.get('data', []) + return result.get('qos_list', []) def update_gfs_qos_policy(self, param): - url = '/rest/fileservice/v1/gfs/qos' - result = self.call(url, data=param, method='PUT') + url = '/rest/fileservice/v1/gfs/qos/modify' + result = self.call(url, data=param, method='POST') self._assert_result(result, 'Update gfs qos from gfs name failed,') return result diff --git a/Manila/file_driver_dir/huawei/oceanstorPacific/client/rest_client.py b/Manila/file_driver_dir/huawei/oceanstorPacific/client/rest_client.py index 9b44b25..b91eb7a 100644 --- a/Manila/file_driver_dir/huawei/oceanstorPacific/client/rest_client.py +++ b/Manila/file_driver_dir/huawei/oceanstorPacific/client/rest_client.py @@ -49,6 +49,9 @@ def wrapped(self, url, **kwargs): if 'timeout' not in kwargs: kwargs['timeout'] = constants.SOCKET_TIMEOUT + if not self._session: + self.retry_relogin(None) + old_token = self._session.headers.get('X-Auth-Token') kwargs['old_token'] = old_token kwargs['full_url'] = full_url @@ -211,7 +214,7 @@ def delete(self, url, **kwargs): url, timeout=kwargs.get('timeout'), verify=self._session.verify) - def init_http_head(self, data, url): + def init_http_head(self): self._session = requests.Session() self._session.headers.update({ "Connection": "keep-alive", diff --git a/Manila/file_driver_dir/huawei/oceanstorPacific/plugin/community/community_operate_share.py b/Manila/file_driver_dir/huawei/oceanstorPacific/plugin/community/community_operate_share.py index b43fad6..b37f4e7 100644 --- a/Manila/file_driver_dir/huawei/oceanstorPacific/plugin/community/community_operate_share.py +++ b/Manila/file_driver_dir/huawei/oceanstorPacific/plugin/community/community_operate_share.py @@ -238,7 +238,8 @@ def _set_namespace_param(self): 'forbidden_dpc': self._get_forbidden_dpc_param(), 'storage_pool_id': self.storage_pool_id, 'account_id': self.account_id, - 'atime_update_mode': constants.ATIME_UPDATE_HOURS + 'atime_update_mode': constants.ATIME_UPDATE_HOURS, + 'case_sensitive': constants.CASE_INSENSITIVE } self.tier_info = self._get_all_share_tier_policy() hot_data_size = self.tier_info.get('hot_data_size') diff --git a/Manila/file_driver_dir/huawei/oceanstorPacific/plugin/plugin_factory.py b/Manila/file_driver_dir/huawei/oceanstorPacific/plugin/plugin_factory.py index 6cebe58..2980f30 100644 --- a/Manila/file_driver_dir/huawei/oceanstorPacific/plugin/plugin_factory.py +++ b/Manila/file_driver_dir/huawei/oceanstorPacific/plugin/plugin_factory.py @@ -27,16 +27,20 @@ class PluginFactory(object): - def __init__(self, configuration, impl_type): + def __init__(self, configuration, impl_func): self.config = configuration # 初始化配置文件 self.driver_config = DriverConfig(self.config) - self.impl_type = impl_type(self.config.product) + self.impl_func = impl_func + self.impl_type = None + self.client = None + def reset_client(self): + # 配置文件校验 + self.driver_config.update_configs() # 实例化client self.client = self._get_client() - - def reset_client(self): + self.impl_type = self.impl_func(self.config.product) return self.client.login().get('system_esn') def disconnect_client(self): diff --git a/Manila/file_driver_dir/huawei/oceanstorPacific/plugin/suyan_gfs/suyan_gfs_change_access.py b/Manila/file_driver_dir/huawei/oceanstorPacific/plugin/suyan_gfs/suyan_gfs_change_access.py index 3af74b3..2b125d7 100644 --- a/Manila/file_driver_dir/huawei/oceanstorPacific/plugin/suyan_gfs/suyan_gfs_change_access.py +++ b/Manila/file_driver_dir/huawei/oceanstorPacific/plugin/suyan_gfs/suyan_gfs_change_access.py @@ -58,9 +58,8 @@ def deny_access(self, access): def _sync_access(self): gfs_param = { - 'cluster_classification_name': self.storage_pool_name, - 'name': self.namespace_name, - 'is_remove_all': True + 'gfs_name_locator': self.namespace_name + "@" + self.storage_pool_name, + 'auth_clients': ['*'] } result = self.client.remove_ipaddress_from_gfs(gfs_param) self.client.wait_task_until_complete(result.get('task_id')) @@ -88,16 +87,23 @@ def _deal_access_for_dpc(self, action): dpc_access_ips_list = self._get_dpc_access_ips_list() for dpc_ips in dpc_access_ips_list: - gfs_param = { - 'cluster_classification_name': self.storage_pool_name, - 'name': self.namespace_name, - 'ip_addresses': dpc_ips + ips = [] + for ip in dpc_ips: + ips.append({'ip': ip}) + + gfs_add_ip_param = { + 'gfs_name_locator': self.namespace_name + "@" + self.storage_pool_name, + 'auth_clients': ips + } + gfs_remove_ip_param = { + 'gfs_name_locator': self.namespace_name + "@" + self.storage_pool_name, + 'auth_clients': dpc_ips } if action == "allow": LOG.info("Will be add dpc access.(nums: {0})".format(len(dpc_ips))) - result = self.client.add_ipaddress_to_gfs(gfs_param) + result = self.client.add_ipaddress_to_gfs(gfs_add_ip_param) self.client.wait_task_until_complete(result.get('task_id')) elif dpc_ips: LOG.info("Will be remove dpc access.(nums: {0})".format(len(dpc_ips))) - result = self.client.remove_ipaddress_from_gfs(gfs_param) + result = self.client.remove_ipaddress_from_gfs(gfs_remove_ip_param) self.client.wait_task_until_complete(result.get('task_id')) diff --git a/Manila/file_driver_dir/huawei/oceanstorPacific/plugin/suyan_gfs/suyan_gfs_check_update_storage.py b/Manila/file_driver_dir/huawei/oceanstorPacific/plugin/suyan_gfs/suyan_gfs_check_update_storage.py index e6521d6..196ea7f 100644 --- a/Manila/file_driver_dir/huawei/oceanstorPacific/plugin/suyan_gfs/suyan_gfs_check_update_storage.py +++ b/Manila/file_driver_dir/huawei/oceanstorPacific/plugin/suyan_gfs/suyan_gfs_check_update_storage.py @@ -107,28 +107,29 @@ def get_all_share_usage(self): name_key = 'name' space_used_key = 'space_used' LOG.info("begin to query all share usages") - self._get_storage_pool_name() all_share_usages = {} - gfs_capacities_infos = self.client.get_all_gfs_capacities_info(self.storage_pool_name) - dtrees_capacities_infos = self.client.get_all_gfs_dtree_capacities_info(self.storage_pool_name) - for gfs_capacity in gfs_capacities_infos: - gfs_name = gfs_capacity.get(name_key) - quota = gfs_capacity.get('quota').get('directory_quota', {}) - unit_type = quota.get('unit_type', constants.CAP_KB) - all_share_usages[gfs_name] = { - space_used_key: self._get_tier_capacity(quota.get(space_used_key, 0), unit_type), - 'space_hard_quota': self._get_tier_capacity(quota.get('hard_quota', 0), unit_type) - } - self._check_and_set_tier_quota(gfs_capacity, all_share_usages, name_key) - - for dtree_capacities in dtrees_capacities_infos: - dtree_name = dtree_capacities.get(name_key) - quota = dtree_capacities.get('quota').get('directory_quota', {}) - unit_type = quota.get('unit_type', constants.CAP_KB) - all_share_usages[dtree_name] = { - space_used_key: self._get_tier_capacity(quota.get(space_used_key, 0), unit_type), - 'space_hard_quota': self._get_tier_capacity(quota.get('hard_quota', 0), unit_type), - } + for pool in self.driver_config.pool_list: + self.storage_pool_name = pool + gfs_capacities_infos = self.client.get_all_gfs_capacities_info(self.storage_pool_name) + dtrees_capacities_infos = self.client.get_all_gfs_dtree_capacities_info(self.storage_pool_name) + for gfs_capacity in gfs_capacities_infos: + gfs_name = gfs_capacity.get(name_key) + quota = gfs_capacity.get('quota').get('directory_quota', {}) + unit_type = quota.get('unit_type', constants.CAP_KB) + all_share_usages[gfs_name] = { + space_used_key: self._get_tier_capacity(quota.get(space_used_key, 0), unit_type), + 'space_hard_quota': self._get_tier_capacity(quota.get('hard_quota', 0), unit_type) + } + self._check_and_set_tier_quota(gfs_capacity, all_share_usages, name_key) + + for dtree_capacities in dtrees_capacities_infos: + dtree_name = dtree_capacities.get(name_key) + quota = dtree_capacities.get('quota').get('directory_quota', {}) + unit_type = quota.get('unit_type', constants.CAP_KB) + all_share_usages[dtree_name] = { + space_used_key: self._get_tier_capacity(quota.get(space_used_key, 0), unit_type), + 'space_hard_quota': self._get_tier_capacity(quota.get('hard_quota', 0), unit_type), + } LOG.info("successfully get all share usages") return all_share_usages diff --git a/Manila/file_driver_dir/huawei/oceanstorPacific/plugin/suyan_gfs/suyan_gfs_operate_share.py b/Manila/file_driver_dir/huawei/oceanstorPacific/plugin/suyan_gfs/suyan_gfs_operate_share.py index dddd11a..06ad15d 100644 --- a/Manila/file_driver_dir/huawei/oceanstorPacific/plugin/suyan_gfs/suyan_gfs_operate_share.py +++ b/Manila/file_driver_dir/huawei/oceanstorPacific/plugin/suyan_gfs/suyan_gfs_operate_share.py @@ -108,7 +108,7 @@ def delete_gfs(self): self._get_storage_pool_name() self.namespace_name = 'share-' + self.share.get('share_id') gfs_delete_param = { - 'name_locator': self.storage_pool_name + '@' + self.namespace_name + 'name_locator': self.namespace_name + '@' + self.storage_pool_name } # if gfs not exist, no need to query task, delete success @@ -129,10 +129,9 @@ def delete_gfs(self): def delete_gfs_dtree(self): name_locator_list = [] self._get_storage_pool_name() - name_locator_list.append(self.storage_pool_name) - name_locator_list.append('share-' + self.share_parent_id) name_locator_list.append('share-' + self.share.get('share_id')) - + name_locator_list.append('share-' + self.share_parent_id) + name_locator_list.append(self.storage_pool_name) gfs_dtree_delete_param = { 'name_locator': '@'.join(name_locator_list) } @@ -164,7 +163,7 @@ def change_share(self, new_size, action): # gfs场景 new_hot_size = self._get_all_share_tier_policy().get('hot_data_size') gfs_name = constants.SHARE_PREFIX + self.share.get('share_id') - name_locator = '@'.join([cluster_name, gfs_name]) + name_locator = '@'.join([gfs_name, cluster_name]) # 修改GFS分级容量 gfs_tier_cap_modify_result = self._check_and_update_gfs_tier_size( name_locator, new_size, new_hot_size) @@ -177,7 +176,7 @@ def change_share(self, new_size, action): # dtree场景 gfs_name = constants.SHARE_PREFIX + self.share_parent_id dtree_name = constants.SHARE_PREFIX + self.share.get('share_id') - name_locator = '@'.join([cluster_name, gfs_name, dtree_name]) + name_locator = '@'.join([dtree_name, gfs_name, cluster_name]) self._check_space_for_dtree(name_locator, new_size) modify_param = self._set_quota_param(name_locator, new_size) result = self.client.change_gfs_dtree_size(modify_param) @@ -204,6 +203,7 @@ def update_qos(self, qos_specs): 根据传递的qos_specs,刷新share的qos信息, 如果没有则创建对应qos, 此接口的share不是share_instance对象是share对象 """ + LOG.info("Begin to update gfs qos") if not self.share.get('export_locations')[0]: err_msg = _("update share qos fail for invalid export location.") raise exception.InvalidShare(reason=err_msg) @@ -211,13 +211,15 @@ def update_qos(self, qos_specs): self.namespace_name = constants.SHARE_PREFIX + self.share.get('id') self._get_storage_pool_name() qos_query_param = { - 'gfs_names': [self.storage_pool_name + "@" + self.namespace_name] + 'gfs_name_locator': self.namespace_name + "@" + self.storage_pool_name } update_and_create_qos_param = { - 'gfs_name': self.storage_pool_name + "@" + self.namespace_name, - 'name': self.namespace_name, - 'max_ops': self.qos_config.get('max_iops'), - 'max_mbps': self.qos_config.get('max_band_width') + 'gfs_name_locator': self.namespace_name + "@" + self.storage_pool_name, + 'qos_list': [{ + 'name': self.namespace_name, + 'max_ops': self.qos_config.get('max_iops'), + 'max_mbps': self.qos_config.get('max_band_width') + }] } qos_info = self.client.query_gfs_qos_policy(qos_query_param) if qos_info: @@ -234,6 +236,7 @@ def update_qos(self, qos_specs): except Exception as err: LOG.error("Create GFS qos task failed, reason is %s", err) raise err + LOG.info("Success to update gfs qos") def _check_and_update_gfs_tier_size(self, name_locator, new_hard_size, new_hot_size): gfs_detail = self.client.query_gfs_detail(name_locator) @@ -328,13 +331,15 @@ def _create_gfs_smart_features(self): manner and wait until all tasks are complete. :return: """ - self.gfs_name_locator = '@'.join([self.storage_pool_name, self.namespace_name]) + self.gfs_name_locator = '@'.join([self.namespace_name, self.storage_pool_name]) gfs_tier_grade_param, gfs_tier_migrate_param = self._check_and_get_tier_param() qos_param = { - 'gfs_name': self.gfs_name_locator, - 'name': self.namespace_name, - 'max_ops': constants.QOS_UNLIMITED, - 'max_mbps': constants.QOS_UNLIMITED + 'gfs_name_locator': self.gfs_name_locator, + 'qos_list': [{ + 'name': self.namespace_name, + 'max_ops': constants.QOS_UNLIMITED, + 'max_mbps': constants.QOS_UNLIMITED + }] } gfs_delete_param = { 'name_locator': self.gfs_name_locator @@ -502,7 +507,7 @@ def _set_gfs_dtree_create_param(self): self._get_storage_pool_name() self.namespace_name = 'share-' + self.share_parent_id self.gfs_dtree_param = { - 'gfs_name_locator': self.storage_pool_name + '@' + self.namespace_name, + 'gfs_name_locator': self.namespace_name + '@' + self.storage_pool_name, 'dtree_name': 'share-' + self.share.get('share_id'), 'quota': { 'directory_quota': { diff --git a/Manila/file_driver_dir/huawei/oceanstorPacific/plugin/suyan_gfs/suyan_gfs_share_tier.py b/Manila/file_driver_dir/huawei/oceanstorPacific/plugin/suyan_gfs/suyan_gfs_share_tier.py index ff2f969..60cbd9e 100644 --- a/Manila/file_driver_dir/huawei/oceanstorPacific/plugin/suyan_gfs/suyan_gfs_share_tier.py +++ b/Manila/file_driver_dir/huawei/oceanstorPacific/plugin/suyan_gfs/suyan_gfs_share_tier.py @@ -59,8 +59,8 @@ def initialize_share_tier(self, file_path, init_type): raise exception.InvalidShare(reason=err_msg) result = self.client.create_gfs_tier_migration_policy({ - 'gfs_name_locator': name_locator.get('gfs_name_locator'), - 'name': name_locator_info.get('migrate_policy_name'), + 'gfs_name_locator': name_locator_info.get('gfs_name_locator'), + 'name': name_locator_info.get('once_migrate_policy_name'), 'migration_type': constants.DME_MIGRATE_ONCE, "tier_grade": strategy, 'file_name_filter': { @@ -285,10 +285,10 @@ def _combine_name_locator(self): once_migrate_policy_name = gfs_name + constants.ONCE_MIGRATE_NAME periodicity_migrate_policy_name = gfs_name + constants.PERIODICITY_NAME grade_policy_name = gfs_name + constants.GRADE_NAME - gfs_name_locator = '@'.join([self.storage_pool_name, gfs_name]) - once_migrate_policy_name_locator = '@'.join([gfs_name_locator, once_migrate_policy_name]) - periodicity_migrate_policy_name_locator = '@'.join([gfs_name_locator, periodicity_migrate_policy_name]) - grade_policy_name_locator = '@'.join([gfs_name_locator, grade_policy_name]) + gfs_name_locator = '@'.join([gfs_name, self.storage_pool_name]) + once_migrate_policy_name_locator = '@'.join([once_migrate_policy_name, gfs_name_locator]) + periodicity_migrate_policy_name_locator = '@'.join([periodicity_migrate_policy_name, gfs_name_locator]) + grade_policy_name_locator = '@'.join([grade_policy_name, gfs_name_locator]) return { 'gfs_name': gfs_name, 'once_migrate_policy_name': once_migrate_policy_name, diff --git a/Manila/file_driver_dir/huawei/oceanstorPacific/utils/constants.py b/Manila/file_driver_dir/huawei/oceanstorPacific/utils/constants.py index b1e06ab..2835288 100644 --- a/Manila/file_driver_dir/huawei/oceanstorPacific/utils/constants.py +++ b/Manila/file_driver_dir/huawei/oceanstorPacific/utils/constants.py @@ -94,6 +94,8 @@ NOT_FORBIDDEN_DPC = 0 FORBIDDEN_DPC = 1 MULTI_PROTO_SEPARATOR = '_' +CASE_INSENSITIVE = False +CASE_SENSITIVE = True # BASE_VALUE = 1024 diff --git a/Manila/file_driver_dir/huawei/oceanstorPacific/utils/driver_config.py b/Manila/file_driver_dir/huawei/oceanstorPacific/utils/driver_config.py index 4a6e26f..6923225 100644 --- a/Manila/file_driver_dir/huawei/oceanstorPacific/utils/driver_config.py +++ b/Manila/file_driver_dir/huawei/oceanstorPacific/utils/driver_config.py @@ -35,7 +35,6 @@ class DriverConfig(object): def __init__(self, config): self.config = config self.last_modify_time = None - self.update_configs() @staticmethod def check_config_exist(text, config_param): @@ -214,6 +213,7 @@ def _hot_disk_type(self, xml_root): err_msg = _("Storage/HotDiskType configuration:%s " "must in %s") % (text.strip(), constants.SUPPORT_DISK_TYPES) LOG.error(err_msg) + raise exception.BadConfigurationException(reason=err_msg) else: setattr(self.config, 'hot_disk_type', text.strip()) @@ -225,6 +225,7 @@ def _warm_disk_type(self, xml_root): err_msg = _("Storage/WarmDiskType configuration:%s " "must in %s") % (text.strip(), constants.SUPPORT_DISK_TYPES) LOG.error(err_msg) + raise exception.BadConfigurationException(reason=err_msg) else: setattr(self.config, 'warm_disk_type', text.strip()) @@ -236,6 +237,7 @@ def _cold_disk_type(self, xml_root): err_msg = _("Storage/ColdDiskType configuration:%s " "must in %s") % (text.strip(), constants.SUPPORT_DISK_TYPES) LOG.error(err_msg) + raise exception.BadConfigurationException(reason=err_msg) else: setattr(self.config, 'cold_disk_type', text.strip())