Skip to content

Commit

Permalink
Merge pull request #70 from huangpeng5/suyan_730
Browse files Browse the repository at this point in the history
1.set case_sensitive to false. 2.check config when do set_up
  • Loading branch information
huangpeng5 authored Jul 30, 2024
2 parents 5eaec36 + 22fb354 commit 03a7261
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 79 deletions.
38 changes: 19 additions & 19 deletions Manila/file_driver_dir/huawei/oceanstorPacific/client/dme_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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

Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down Expand Up @@ -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'))
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -204,20 +203,23 @@ 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)
self._get_update_qos_config(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:
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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': {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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': {
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@
NOT_FORBIDDEN_DPC = 0
FORBIDDEN_DPC = 1
MULTI_PROTO_SEPARATOR = '_'
CASE_INSENSITIVE = False
CASE_SENSITIVE = True

#
BASE_VALUE = 1024
Expand Down
Loading

0 comments on commit 03a7261

Please sign in to comment.