Skip to content

Commit

Permalink
Merge pull request #45 from huangpeng5/cloud_cinder_815_master
Browse files Browse the repository at this point in the history
815 version release
  • Loading branch information
yunqifeng authored Aug 17, 2023
2 parents 1ee90e3 + ee9f3e2 commit 74ebb97
Show file tree
Hide file tree
Showing 66 changed files with 1,248 additions and 221 deletions.
55 changes: 55 additions & 0 deletions Cinder/Newton/customization_driver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Copyright (c) 2023 Huawei Technologies Co., Ltd.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, 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.

import logging

from cinder.volume.drivers.fusionstorage import fs_utils

LOG = logging.getLogger(__name__)


class DriverForZTE(object):
"""
ZTE Cloud Platform Customization Class
"""
def __init__(self, *args, **kwargs):
super(DriverForZTE, self).__init__(*args, **kwargs)

def reload_qos(self, volume, qos_vals=None):
"""
ZTE Cloud Platform Customization Interface
QoS policies can be dynamically modified,remove,add
and take effect on volumes in real time.
"""
self._check_volume_exist_on_array(volume)
volume_name = self._get_vol_name(volume)
if not qos_vals:
LOG.info("qos_vals is None, remove qos from volume %s", volume_name)
self.fs_qos.remove(volume_name)
return

qos_vals = fs_utils.get_qos_param(qos_vals, self.client)
vol_qos = self.client.get_qos_by_vol_name(volume_name)
qos_name = vol_qos.get("qosName")
if qos_name:
LOG.info("volume already had qos, "
"update qos:%s of volume %s", qos_name, volume_name)
self.client.modify_qos(qos_name, qos_vals)
return

LOG.info("volume did not have qos, "
"add qos to volume %s", volume_name)
self.fs_qos.add(qos_vals, volume_name)
return
24 changes: 17 additions & 7 deletions Cinder/Newton/dsware.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from cinder.volume.drivers.fusionstorage import fs_flow
from cinder.volume.drivers.fusionstorage import fs_qos
from cinder.volume.drivers.fusionstorage import fs_utils
from cinder.volume.drivers.fusionstorage import customization_driver
from cinder.volume.drivers.san import san
from cinder.volume import utils as volume_utils

Expand Down Expand Up @@ -110,14 +111,18 @@
cfg.BoolOpt('full_clone',
default=False,
help='Whether use full clone.'),
cfg.IntOpt('rest_timeout',
default=constants.DEFAULT_TIMEOUT,
help='timeout when call storage restful api.'),
]

CONF = cfg.CONF
CONF.register_opts(volume_opts)


@interface.volumedriver
class DSWAREBaseDriver(driver.VolumeDriver):
class DSWAREBaseDriver(customization_driver.DriverForZTE,
driver.VolumeDriver):
VERSION = "2.6.2"
CI_WIKI_NAME = 'Huawei_FusionStorage_CI'

Expand Down Expand Up @@ -156,7 +161,8 @@ def do_setup(self, context):
}

extend_conf = {
"mutual_authentication": mutual_authentication
"mutual_authentication": mutual_authentication,
"rest_timeout": self.configuration.rest_timeout
}

self.client = fs_client.RestCommon(fs_address=url_str,
Expand All @@ -167,7 +173,7 @@ def do_setup(self, context):
self.fs_qos = fs_qos.FusionStorageQoS(self.client)

def check_for_setup_error(self):
all_pools = self.client.query_pool_info()
all_pools = self.client.query_storage_pool_info()
all_pools_name = [p['poolName'] for p in all_pools
if p.get('poolName')]

Expand All @@ -186,7 +192,7 @@ def _update_pool_stats(self):
"pools": [],
"vendor_name": "Huawei"
}
all_pools = self.client.query_pool_info()
all_pools = self.client.query_storage_pool_info()

for pool in all_pools:
if pool['poolName'] in self.configuration.pools_name:
Expand Down Expand Up @@ -260,7 +266,7 @@ def _get_pool_id(self, volume):

def _get_pool_id_by_name(self, pool_name):
pool_id_list = []
all_pools = self.client.query_pool_info()
all_pools = self.client.query_storage_pool_info()
for pool in all_pools:
if pool_name == pool['poolName']:
pool_id_list.append(pool['poolId'])
Expand Down Expand Up @@ -712,6 +718,7 @@ def retype(self, context, volume, new_type, diff, host):
volume, new_type, host, vol_name)
if migrate:
src_lun_id = self._check_volume_exist_on_array(volume)
self._check_volume_snapshot_exist(volume)
LOG.debug("Begin to migrate LUN(id: %(lun_id)s) with "
"change %(change_opts)s.",
{"lun_id": src_lun_id, "change_opts": change_opts})
Expand All @@ -731,6 +738,7 @@ def migrate_volume(self, context, volume, host):
{"volume": volume.id,
"host": host})
src_lun_id = self._check_volume_exist_on_array(volume)
self._check_volume_snapshot_exist(volume)

moved = self._migrate_volume(volume, host, src_lun_id)
return moved, {}
Expand Down Expand Up @@ -856,7 +864,6 @@ def _check_migration_valid(self, host):
return True

def _check_volume_exist_on_array(self, volume):
volume_name = self._get_vol_name(volume)
result = self._check_volume_exist(volume)
if not result:
msg = _("Volume %s does not exist on the array."
Expand All @@ -873,11 +880,14 @@ def _check_volume_exist_on_array(self, volume):
) % volume.id
self._raise_exception(msg)

return lun_id

def _check_volume_snapshot_exist(self, volume):
volume_name = self._get_vol_name(volume)
if self.client.get_volume_snapshot(volume_name):
msg = _("Volume %s which have snapshot cannot do lun migration"
) % volume.id
self._raise_exception(msg)
return lun_id

def _rollback_snapshot(self, vol_name, snap_name):
def _snapshot_rollback_finish():
Expand Down
14 changes: 12 additions & 2 deletions Cinder/Newton/fs_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def __init__(self, fs_address, fs_user, fs_password, **extend_conf):
self.token = None
self.version = None
self.esn = None
self.rest_timeout = extend_conf.get(
"rest_timeout", constants.DEFAULT_TIMEOUT)
mutual_authentication = extend_conf.get("mutual_authentication", {})
self.init_http_head(mutual_authentication)

Expand Down Expand Up @@ -93,11 +95,13 @@ def _deal_call_result(result, filter_flag, json_flag, req_dict):
return result.json() if json_flag else result

def call(self, url, method, data=None,
call_timeout=constants.DEFAULT_TIMEOUT, **input_kwargs):
call_timeout=None, **input_kwargs):
filter_flag = input_kwargs.get("filter_flag")
json_flag = input_kwargs.get("json_flag", True)
get_version = input_kwargs.get("get_version")
get_system_time = input_kwargs.get("get_system_time")
if call_timeout is None:
call_timeout = self.rest_timeout

kwargs = {'timeout': call_timeout}
if data is not None:
Expand All @@ -110,7 +114,7 @@ def call(self, url, method, data=None,
result = func(call_url, **kwargs)
except Exception as err:
LOG.error('Bad response from server: %(url)s. '
'Error: %(err)s'), {'url': call_url, 'err': err}
'Error: %(err)s', {'url': call_url, 'err': err})
return {"error": {
"code": constants.CONNECT_ERROR,
"description": "Connect to server error."}}
Expand Down Expand Up @@ -201,6 +205,12 @@ def query_pool_info(self, pool_id=None):
self._assert_rest_result(result, _("Query pool session error."))
return result['storagePools']

def query_storage_pool_info(self):
url = "/cluster/storagepool/queryStoragePool"
result = self.call(url, 'GET', get_version=True, filter_flag=True)
self._assert_rest_result(result, _("Query pool session error."))
return result.get('storagePools', [])

def _get_volume_num_by_pool(self, pool_id):
pool_info = self.query_pool_info(pool_id)
return pool_info[0].get('volumeNum', 0)
Expand Down
2 changes: 1 addition & 1 deletion Cinder/Newton/fs_qos.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def add(self, qos, vol_name):
raise

def _is_qos_associate_to_volume(self, qos_name):
all_pools = self.client.query_pool_info()
all_pools = self.client.query_storage_pool_info()
volumes = None
for pool in all_pools:
volumes = self.client.get_qos_volume_info(
Expand Down
18 changes: 11 additions & 7 deletions Cinder/Newton/fs_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,16 +215,20 @@ def _get_qos_specs(qos_specs_id, client):
kvs = specs.get('specs', {})
LOG.info('The QoS specs is: %s.', kvs)

qos = dict()
for k, v in kvs.items():
return get_qos_param(kvs, client)


def get_qos_param(qos_vals, client):
qos_param = dict()
for k, v in qos_vals.items():
_raise_qos_is_invalid(k)
qos = _set_qos(qos, k, v)
qos_param = _set_qos(qos_param, k, v)

_raise_qos_not_set(qos)
_set_default_qos(qos)
qos = _get_trigger_qos(qos, client)
_raise_qos_not_set(qos_param)
_set_default_qos(qos_param)
qos_param = _get_trigger_qos(qos_param, client)

return qos
return qos_param


def _deal_date_increase_or_decrease(is_date_decrease, is_date_increase, qos):
Expand Down
55 changes: 55 additions & 0 deletions Cinder/Ocata/customization_driver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Copyright (c) 2023 Huawei Technologies Co., Ltd.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, 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.

import logging

from cinder.volume.drivers.fusionstorage import fs_utils

LOG = logging.getLogger(__name__)


class DriverForZTE(object):
"""
ZTE Cloud Platform Customization Class
"""
def __init__(self, *args, **kwargs):
super(DriverForZTE, self).__init__(*args, **kwargs)

def reload_qos(self, volume, qos_vals=None):
"""
ZTE Cloud Platform Customization Interface
QoS policies can be dynamically modified,remove,add
and take effect on volumes in real time.
"""
self._check_volume_exist_on_array(volume)
volume_name = self._get_vol_name(volume)
if not qos_vals:
LOG.info("qos_vals is None, remove qos from volume %s", volume_name)
self.fs_qos.remove(volume_name)
return

qos_vals = fs_utils.get_qos_param(qos_vals, self.client)
vol_qos = self.client.get_qos_by_vol_name(volume_name)
qos_name = vol_qos.get("qosName")
if qos_name:
LOG.info("volume already had qos, "
"update qos:%s of volume %s", qos_name, volume_name)
self.client.modify_qos(qos_name, qos_vals)
return

LOG.info("volume did not have qos, "
"add qos to volume %s", volume_name)
self.fs_qos.add(qos_vals, volume_name)
return
Loading

0 comments on commit 74ebb97

Please sign in to comment.