Huawei: Use versionedObject

Since the core code has been changed to use
versionedObject, Huawei drivers now changes to
use versionedObject too.

Implements: blueprint huawei-use-versionedobject
Change-Id: I4d0e7ac804a9d42754e7f7ce70cdd8af132e173a
This commit is contained in:
Wilson Liu 2016-06-28 21:24:38 +08:00
parent afb81cd022
commit 15ed23df11
6 changed files with 378 additions and 534 deletions

File diff suppressed because it is too large Load Diff

View File

@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import collections
import json import json
import math import math
import re import re
@ -71,6 +72,9 @@ huawei_opts = [
CONF = cfg.CONF CONF = cfg.CONF
CONF.register_opts(huawei_opts) CONF.register_opts(huawei_opts)
snap_attrs = ('id', 'volume_id', 'volume', 'provider_location')
Snapshot = collections.namedtuple('Snapshot', snap_attrs)
class HuaweiBaseDriver(driver.VolumeDriver): class HuaweiBaseDriver(driver.VolumeDriver):
@ -176,7 +180,7 @@ class HuaweiBaseDriver(driver.VolumeDriver):
def _get_volume_type(self, volume): def _get_volume_type(self, volume):
volume_type = None volume_type = None
type_id = volume['volume_type_id'] type_id = volume.volume_type_id
if type_id: if type_id:
ctxt = context.get_admin_context() ctxt = context.get_admin_context()
volume_type = volume_types.get_volume_type(ctxt, type_id) volume_type = volume_types.get_volume_type(ctxt, type_id)
@ -195,7 +199,7 @@ class HuaweiBaseDriver(driver.VolumeDriver):
def _get_consistencygroup_type(self, group): def _get_consistencygroup_type(self, group):
specs = {} specs = {}
opts = {} opts = {}
type_id = group['volume_type_id'].split(",") type_id = group.volume_type_id.split(",")
if type_id[0] and len(type_id) == 2: if type_id[0] and len(type_id) == 2:
ctxt = context.get_admin_context() ctxt = context.get_admin_context()
volume_type = volume_types.get_volume_type(ctxt, type_id[0]) volume_type = volume_types.get_volume_type(ctxt, type_id[0])
@ -279,13 +283,13 @@ class HuaweiBaseDriver(driver.VolumeDriver):
return opts return opts
def _get_lun_params(self, volume, opts): def _get_lun_params(self, volume, opts):
pool_name = volume_utils.extract_host(volume['host'], level='pool') pool_name = volume_utils.extract_host(volume.host, level='pool')
params = { params = {
'TYPE': '11', 'TYPE': '11',
'NAME': huawei_utils.encode_name(volume['id']), 'NAME': huawei_utils.encode_name(volume.id),
'PARENTTYPE': '216', 'PARENTTYPE': '216',
'PARENTID': self.client.get_pool_id(pool_name), 'PARENTID': self.client.get_pool_id(pool_name),
'DESCRIPTION': volume['name'], 'DESCRIPTION': volume.name,
'ALLOCTYPE': opts.get('LUNType', self.configuration.lun_type), 'ALLOCTYPE': opts.get('LUNType', self.configuration.lun_type),
'CAPACITY': huawei_utils.get_volume_size(volume), 'CAPACITY': huawei_utils.get_volume_size(volume),
'WRITEPOLICY': self.configuration.lun_write_type, 'WRITEPOLICY': self.configuration.lun_write_type,
@ -298,7 +302,7 @@ class HuaweiBaseDriver(driver.VolumeDriver):
'WRITECACHEPOLICY': self.configuration.lun_write_cache_policy, } 'WRITECACHEPOLICY': self.configuration.lun_write_cache_policy, }
LOG.info(_LI('volume: %(volume)s, lun params: %(params)s.'), LOG.info(_LI('volume: %(volume)s, lun params: %(params)s.'),
{'volume': volume['id'], 'params': params}) {'volume': volume.id, 'params': params})
return params return params
def _create_volume(self, volume, lun_params): def _create_volume(self, volume, lun_params):
@ -393,7 +397,7 @@ class HuaweiBaseDriver(driver.VolumeDriver):
return model_update return model_update
def _delete_volume(self, volume): def _delete_volume(self, volume):
lun_id = volume.get('provider_location') lun_id = volume.provider_location
if not lun_id: if not lun_id:
return return
@ -436,7 +440,7 @@ class HuaweiBaseDriver(driver.VolumeDriver):
raise raise
# Delete a replication volume # Delete a replication volume
replica_data = volume.get('replication_driver_data') replica_data = volume.replication_driver_data
if replica_data: if replica_data:
try: try:
self.replica.delete_replica(volume) self.replica.delete_replica(volume)
@ -533,19 +537,19 @@ class HuaweiBaseDriver(driver.VolumeDriver):
wait_interval * 10) wait_interval * 10)
def _get_original_status(self, volume): def _get_original_status(self, volume):
return 'in-use' if volume.get('volume_attachment') else 'available' return 'in-use' if volume.volume_attachment else 'available'
def update_migrated_volume(self, ctxt, volume, new_volume, def update_migrated_volume(self, ctxt, volume, new_volume,
original_volume_status=None): original_volume_status=None):
original_name = huawei_utils.encode_name(volume['id']) original_name = huawei_utils.encode_name(volume.id)
current_name = huawei_utils.encode_name(new_volume['id']) current_name = huawei_utils.encode_name(new_volume.id)
lun_id = self.client.get_lun_id_by_name(current_name) lun_id = self.client.get_lun_id_by_name(current_name)
try: try:
self.client.rename_lun(lun_id, original_name) self.client.rename_lun(lun_id, original_name)
except exception.VolumeBackendAPIException: except exception.VolumeBackendAPIException:
LOG.error(_LE('Unable to rename lun %s on array.'), current_name) LOG.error(_LE('Unable to rename lun %s on array.'), current_name)
return {'_name_id': new_volume['_name_id'] or new_volume['id']} return {'_name_id': new_volume.name_id}
LOG.debug("Rename lun from %(current_name)s to %(original_name)s " LOG.debug("Rename lun from %(current_name)s to %(original_name)s "
"successfully.", "successfully.",
@ -597,7 +601,7 @@ class HuaweiBaseDriver(driver.VolumeDriver):
if not self._check_migration_valid(host, volume): if not self._check_migration_valid(host, volume):
return (False, None) return (False, None)
type_id = volume['volume_type_id'] type_id = volume.volume_type_id
volume_type = None volume_type = None
if type_id: if type_id:
@ -606,9 +610,9 @@ class HuaweiBaseDriver(driver.VolumeDriver):
pool_name = host['capabilities']['pool_name'] pool_name = host['capabilities']['pool_name']
pools = self.client.get_all_pools() pools = self.client.get_all_pools()
pool_info = self.client.get_pool_info(pool_name, pools) pool_info = self.client.get_pool_info(pool_name, pools)
src_volume_name = huawei_utils.encode_name(volume['id']) src_volume_name = huawei_utils.encode_name(volume.id)
dst_volume_name = six.text_type(hash(src_volume_name)) dst_volume_name = six.text_type(hash(src_volume_name))
src_id = volume.get('provider_location') src_id = volume.provider_location
opts = None opts = None
qos = None qos = None
@ -680,8 +684,8 @@ class HuaweiBaseDriver(driver.VolumeDriver):
LOG.error(err_msg) LOG.error(err_msg)
raise exception.VolumeBackendAPIException(data=err_msg) raise exception.VolumeBackendAPIException(data=err_msg)
snapshotname = huawei_utils.encode_name(snapshot['id']) snapshotname = huawei_utils.encode_name(snapshot.id)
snapshot_id = snapshot.get('provider_location') snapshot_id = snapshot.provider_location
if snapshot_id is None: if snapshot_id is None:
snapshot_id = self.client.get_snapshot_id_by_name(snapshotname) snapshot_id = self.client.get_snapshot_id_by_name(snapshotname)
if snapshot_id is None: if snapshot_id is None:
@ -696,7 +700,7 @@ class HuaweiBaseDriver(driver.VolumeDriver):
self._create_base_type_volume(opts, volume, volume_type)) self._create_base_type_volume(opts, volume, volume_type))
tgt_lun_id = model_update['provider_location'] tgt_lun_id = model_update['provider_location']
luncopy_name = huawei_utils.encode_name(volume['id']) luncopy_name = huawei_utils.encode_name(volume.id)
LOG.info(_LI( LOG.info(_LI(
'create_volume_from_snapshot: src_lun_id: %(src_lun_id)s, ' 'create_volume_from_snapshot: src_lun_id: %(src_lun_id)s, '
'tgt_lun_id: %(tgt_lun_id)s, copy_name: %(copy_name)s.'), 'tgt_lun_id: %(tgt_lun_id)s, copy_name: %(copy_name)s.'),
@ -733,9 +737,10 @@ class HuaweiBaseDriver(driver.VolumeDriver):
constants.VOLUME_NOT_EXISTS_RAISE) constants.VOLUME_NOT_EXISTS_RAISE)
# Form the snapshot structure. # Form the snapshot structure.
snapshot = {'id': uuid.uuid4().__str__(), snapshot = Snapshot(id=uuid.uuid4().__str__(),
'volume_id': src_vref['id'], volume_id=src_vref.id,
'volume': src_vref} volume=src_vref,
provider_location=None)
# Create snapshot. # Create snapshot.
self.create_snapshot(snapshot) self.create_snapshot(snapshot)
@ -751,8 +756,8 @@ class HuaweiBaseDriver(driver.VolumeDriver):
LOG.warning(_LW( LOG.warning(_LW(
'Failure deleting the snapshot %(snapshot_id)s ' 'Failure deleting the snapshot %(snapshot_id)s '
'of volume %(volume_id)s.'), 'of volume %(volume_id)s.'),
{'snapshot_id': snapshot['id'], {'snapshot_id': snapshot.id,
'volume_id': src_vref['id']},) 'volume_id': src_vref.id},)
return model_update return model_update
@ -762,15 +767,15 @@ class HuaweiBaseDriver(driver.VolumeDriver):
If the volume exists on the array, return the LUN ID. If the volume exists on the array, return the LUN ID.
If not exists, raise or log warning. If not exists, raise or log warning.
""" """
# Firstly, try to find LUN ID by volume['provider_location']. # Firstly, try to find LUN ID by volume.provider_location.
lun_id = volume.get('provider_location') lun_id = volume.provider_location
# If LUN ID not recorded, find LUN ID by LUN NAME. # If LUN ID not recorded, find LUN ID by LUN NAME.
if not lun_id: if not lun_id:
volume_name = huawei_utils.encode_name(volume['id']) volume_name = huawei_utils.encode_name(volume.id)
lun_id = self.client.get_lun_id_by_name(volume_name) lun_id = self.client.get_lun_id_by_name(volume_name)
if not lun_id: if not lun_id:
msg = (_("Volume %s does not exist on the array.") msg = (_("Volume %s does not exist on the array.")
% volume['id']) % volume.id)
if action == constants.VOLUME_NOT_EXISTS_WARN: if action == constants.VOLUME_NOT_EXISTS_WARN:
LOG.warning(msg) LOG.warning(msg)
if action == constants.VOLUME_NOT_EXISTS_RAISE: if action == constants.VOLUME_NOT_EXISTS_RAISE:
@ -780,11 +785,11 @@ class HuaweiBaseDriver(driver.VolumeDriver):
metadata = huawei_utils.get_admin_metadata(volume) metadata = huawei_utils.get_admin_metadata(volume)
lun_wwn = metadata.get('huawei_lun_wwn') if metadata else None lun_wwn = metadata.get('huawei_lun_wwn') if metadata else None
if not lun_wwn: if not lun_wwn:
LOG.debug("No LUN WWN recorded for volume %s.", volume['id']) LOG.debug("No LUN WWN recorded for volume %s.", volume.id)
if not self.client.check_lun_exist(lun_id, lun_wwn): if not self.client.check_lun_exist(lun_id, lun_wwn):
msg = (_("Volume %s does not exist on the array.") msg = (_("Volume %s does not exist on the array.")
% volume['id']) % volume.id)
if action == constants.VOLUME_NOT_EXISTS_WARN: if action == constants.VOLUME_NOT_EXISTS_WARN:
LOG.warning(msg) LOG.warning(msg)
if action == constants.VOLUME_NOT_EXISTS_RAISE: if action == constants.VOLUME_NOT_EXISTS_RAISE:
@ -801,7 +806,7 @@ class HuaweiBaseDriver(driver.VolumeDriver):
opts = self._get_volume_params(volume_type) opts = self._get_volume_params(volume_type)
if opts.get('replication_enabled') == 'true': if opts.get('replication_enabled') == 'true':
msg = (_("Can't extend replication volume, volume: %(id)s") % msg = (_("Can't extend replication volume, volume: %(id)s") %
{"id": volume['id']}) {"id": volume.id})
LOG.error(msg) LOG.error(msg)
raise exception.VolumeBackendAPIException(data=msg) raise exception.VolumeBackendAPIException(data=msg)
@ -825,7 +830,7 @@ class HuaweiBaseDriver(driver.VolumeDriver):
'newsize': new_size}) 'newsize': new_size})
LOG.error(msg) LOG.error(msg)
raise exception.VolumeBackendAPIException(data=msg) raise exception.VolumeBackendAPIException(data=msg)
volume_name = huawei_utils.encode_name(volume['id']) volume_name = huawei_utils.encode_name(volume.id)
LOG.info(_LI( LOG.info(_LI(
'Extend volume: %(volumename)s, ' 'Extend volume: %(volumename)s, '
@ -837,17 +842,17 @@ class HuaweiBaseDriver(driver.VolumeDriver):
self.client.extend_lun(lun_id, new_size) self.client.extend_lun(lun_id, new_size)
def create_snapshot(self, snapshot): def create_snapshot(self, snapshot):
volume = snapshot.get('volume') volume = snapshot.volume
if not volume: if not volume:
msg = (_("Can't get volume id from snapshot, snapshot: %(id)s") msg = (_("Can't get volume id from snapshot, snapshot: %(id)s")
% {"id": snapshot['id']}) % {"id": snapshot.id})
LOG.error(msg) LOG.error(msg)
raise exception.VolumeBackendAPIException(data=msg) raise exception.VolumeBackendAPIException(data=msg)
volume_name = huawei_utils.encode_name(snapshot['volume_id']) volume_name = huawei_utils.encode_name(snapshot.volume_id)
lun_id = self.client.get_lun_id(volume, volume_name) lun_id = self.client.get_lun_id(volume, volume_name)
snapshot_name = huawei_utils.encode_name(snapshot['id']) snapshot_name = huawei_utils.encode_name(snapshot.id)
snapshot_description = snapshot['id'] snapshot_description = snapshot.id
snapshot_info = self.client.create_snapshot(lun_id, snapshot_info = self.client.create_snapshot(lun_id,
snapshot_name, snapshot_name,
snapshot_description) snapshot_description)
@ -858,8 +863,8 @@ class HuaweiBaseDriver(driver.VolumeDriver):
'lun_info': snapshot_info} 'lun_info': snapshot_info}
def delete_snapshot(self, snapshot): def delete_snapshot(self, snapshot):
snapshotname = huawei_utils.encode_name(snapshot['id']) snapshotname = huawei_utils.encode_name(snapshot.id)
volume_name = huawei_utils.encode_name(snapshot['volume_id']) volume_name = huawei_utils.encode_name(snapshot.volume_id)
LOG.info(_LI( LOG.info(_LI(
'stop_snapshot: snapshot name: %(snapshot)s, ' 'stop_snapshot: snapshot name: %(snapshot)s, '
@ -867,7 +872,7 @@ class HuaweiBaseDriver(driver.VolumeDriver):
{'snapshot': snapshotname, {'snapshot': snapshotname,
'volume': volume_name},) 'volume': volume_name},)
snapshot_id = snapshot.get('provider_location') snapshot_id = snapshot.provider_location
if snapshot_id is None: if snapshot_id is None:
snapshot_id = self.client.get_snapshot_id_by_name(snapshotname) snapshot_id = self.client.get_snapshot_id_by_name(snapshotname)
@ -880,7 +885,7 @@ class HuaweiBaseDriver(driver.VolumeDriver):
def retype(self, ctxt, volume, new_type, diff, host): def retype(self, ctxt, volume, new_type, diff, host):
"""Convert the volume to be of the new type.""" """Convert the volume to be of the new type."""
LOG.debug("Enter retype: id=%(id)s, new_type=%(new_type)s, " LOG.debug("Enter retype: id=%(id)s, new_type=%(new_type)s, "
"diff=%(diff)s, host=%(host)s.", {'id': volume['id'], "diff=%(diff)s, host=%(host)s.", {'id': volume.id,
'new_type': new_type, 'new_type': new_type,
'diff': diff, 'diff': diff,
'host': host}) 'host': host})
@ -1089,7 +1094,7 @@ class HuaweiBaseDriver(driver.VolumeDriver):
'replication_type': None, 'replication_type': None,
} }
lun_id = volume.get('provider_location') lun_id = volume.provider_location
old_opts = self.get_lun_specs(lun_id) old_opts = self.get_lun_specs(lun_id)
new_specs = new_type['extra_specs'] new_specs = new_type['extra_specs']
@ -1098,9 +1103,9 @@ class HuaweiBaseDriver(driver.VolumeDriver):
if 'LUNType' not in new_opts: if 'LUNType' not in new_opts:
new_opts['LUNType'] = self.configuration.lun_type new_opts['LUNType'] = self.configuration.lun_type
if volume['host'] != host['host']: if volume.host != host['host']:
migration = True migration = True
change_opts['host'] = (volume['host'], host['host']) change_opts['host'] = (volume.host, host['host'])
if old_opts['LUNType'] != new_opts['LUNType']: if old_opts['LUNType'] != new_opts['LUNType']:
migration = True migration = True
change_opts['LUNType'] = (old_opts['LUNType'], new_opts['LUNType']) change_opts['LUNType'] = (old_opts['LUNType'], new_opts['LUNType'])
@ -1299,14 +1304,14 @@ class HuaweiBaseDriver(driver.VolumeDriver):
def manage_existing(self, volume, external_ref): def manage_existing(self, volume, external_ref):
"""Manage an existing volume on the backend storage.""" """Manage an existing volume on the backend storage."""
# Check whether the LUN is belonged to the specified pool. # Check whether the LUN is belonged to the specified pool.
pool = volume_utils.extract_host(volume['host'], 'pool') pool = volume_utils.extract_host(volume.host, 'pool')
LOG.debug("Pool specified is: %s.", pool) LOG.debug("Pool specified is: %s.", pool)
lun_info = self._get_lun_info_by_ref(external_ref) lun_info = self._get_lun_info_by_ref(external_ref)
lun_id = lun_info.get('ID') lun_id = lun_info.get('ID')
description = lun_info.get('DESCRIPTION', '') description = lun_info.get('DESCRIPTION', '')
if len(description) <= ( if len(description) <= (
constants.MAX_VOL_DESCRIPTION - len(volume['name']) - 1): constants.MAX_VOL_DESCRIPTION - len(volume.name) - 1):
description = volume['name'] + ' ' + description description = volume.name + ' ' + description
lun_pool = lun_info.get('PARENTNAME') lun_pool = lun_info.get('PARENTNAME')
LOG.debug("Storage pool of existing LUN %(lun)s is %(pool)s.", LOG.debug("Storage pool of existing LUN %(lun)s is %(pool)s.",
@ -1319,7 +1324,7 @@ class HuaweiBaseDriver(driver.VolumeDriver):
# Check other stuffs to determine whether this LUN can be imported. # Check other stuffs to determine whether this LUN can be imported.
self._check_lun_valid_for_manage(lun_info, external_ref) self._check_lun_valid_for_manage(lun_info, external_ref)
type_id = volume.get('volume_type_id') type_id = volume.volume_type_id
new_opts = None new_opts = None
if type_id: if type_id:
# Handle volume type if specified. # Handle volume type if specified.
@ -1341,7 +1346,7 @@ class HuaweiBaseDriver(driver.VolumeDriver):
self.modify_lun(lun_id, change_opts) self.modify_lun(lun_id, change_opts)
# Rename the LUN to make it manageable for Cinder. # Rename the LUN to make it manageable for Cinder.
new_name = huawei_utils.encode_name(volume['id']) new_name = huawei_utils.encode_name(volume.id)
LOG.debug("Rename LUN %(old_name)s to %(new_name)s.", LOG.debug("Rename LUN %(old_name)s to %(new_name)s.",
{'old_name': lun_info.get('NAME'), {'old_name': lun_info.get('NAME'),
'new_name': new_name}) 'new_name': new_name})
@ -1387,14 +1392,14 @@ class HuaweiBaseDriver(driver.VolumeDriver):
def unmanage(self, volume): def unmanage(self, volume):
"""Export Huawei volume from Cinder.""" """Export Huawei volume from Cinder."""
LOG.debug("Unmanage volume: %s.", volume['id']) LOG.debug("Unmanage volume: %s.", volume.id)
lun_id = self._check_volume_exist_on_array( lun_id = self._check_volume_exist_on_array(
volume, constants.VOLUME_NOT_EXISTS_WARN) volume, constants.VOLUME_NOT_EXISTS_WARN)
if not lun_id: if not lun_id:
return return
lun_name = huawei_utils.encode_name(volume['id']) lun_name = huawei_utils.encode_name(volume.id)
new_name = 'unmged_' + lun_name new_name = 'unmged_' + lun_name
LOG.debug("Rename LUN %(lun_name)s to %(new_name)s.", LOG.debug("Rename LUN %(lun_name)s to %(new_name)s.",
{'lun_name': lun_name, {'lun_name': lun_name,
@ -1404,7 +1409,7 @@ class HuaweiBaseDriver(driver.VolumeDriver):
except Exception: except Exception:
LOG.warning(_LW("Rename lun %(lun_id)s fails when " LOG.warning(_LW("Rename lun %(lun_id)s fails when "
"unmanaging volume %(volume)s."), "unmanaging volume %(volume)s."),
{"lun_id": lun_id, "volume": volume['id']}) {"lun_id": lun_id, "volume": volume.id})
def manage_existing_get_size(self, volume, external_ref): def manage_existing_get_size(self, volume, external_ref):
"""Get the size of the existing volume.""" """Get the size of the existing volume."""
@ -1452,8 +1457,8 @@ class HuaweiBaseDriver(driver.VolumeDriver):
def manage_existing_snapshot(self, snapshot, existing_ref): def manage_existing_snapshot(self, snapshot, existing_ref):
snapshot_info = self._get_snapshot_info_by_ref(existing_ref) snapshot_info = self._get_snapshot_info_by_ref(existing_ref)
snapshot_id = snapshot_info.get('ID') snapshot_id = snapshot_info.get('ID')
volume = snapshot.get('volume') volume = snapshot.volume
lun_id = volume.get('provider_location') lun_id = volume.provider_location
if lun_id != snapshot_info.get('PARENTID'): if lun_id != snapshot_info.get('PARENTID'):
msg = (_("Can't import snapshot %s to Cinder. " msg = (_("Can't import snapshot %s to Cinder. "
"Snapshot doesn't belong to volume."), snapshot_id) "Snapshot doesn't belong to volume."), snapshot_id)
@ -1464,8 +1469,8 @@ class HuaweiBaseDriver(driver.VolumeDriver):
self._check_snapshot_valid_for_manage(snapshot_info, existing_ref) self._check_snapshot_valid_for_manage(snapshot_info, existing_ref)
# Rename the snapshot to make it manageable for Cinder. # Rename the snapshot to make it manageable for Cinder.
description = snapshot['id'] description = snapshot.id
snapshot_name = huawei_utils.encode_name(snapshot['id']) snapshot_name = huawei_utils.encode_name(snapshot.id)
self.client.rename_snapshot(snapshot_id, snapshot_name, description) self.client.rename_snapshot(snapshot_id, snapshot_name, description)
if snapshot_info.get('RUNNINGSTATUS') != constants.STATUS_ACTIVE: if snapshot_info.get('RUNNINGSTATUS') != constants.STATUS_ACTIVE:
self.client.activate_snapshot(snapshot_id) self.client.activate_snapshot(snapshot_id)
@ -1490,8 +1495,8 @@ class HuaweiBaseDriver(driver.VolumeDriver):
def unmanage_snapshot(self, snapshot): def unmanage_snapshot(self, snapshot):
"""Unmanage the specified snapshot from Cinder management.""" """Unmanage the specified snapshot from Cinder management."""
LOG.debug("Unmanage snapshot: %s.", snapshot['id']) LOG.debug("Unmanage snapshot: %s.", snapshot.id)
snapshot_name = huawei_utils.encode_name(snapshot['id']) snapshot_name = huawei_utils.encode_name(snapshot.id)
snapshot_id = self.client.get_snapshot_id_by_name(snapshot_name) snapshot_id = self.client.get_snapshot_id_by_name(snapshot_name)
if not snapshot_id: if not snapshot_id:
LOG.warning(_LW("Can't find snapshot on the array: %s."), LOG.warning(_LW("Can't find snapshot on the array: %s."),
@ -1507,7 +1512,7 @@ class HuaweiBaseDriver(driver.VolumeDriver):
except Exception: except Exception:
LOG.warning(_LW("Failed to rename snapshot %(snapshot_id)s, " LOG.warning(_LW("Failed to rename snapshot %(snapshot_id)s, "
"snapshot name on array is %(snapshot_name)s."), "snapshot name on array is %(snapshot_name)s."),
{'snapshot_id': snapshot['id'], {'snapshot_id': snapshot.id,
'snapshot_name': snapshot_name}) 'snapshot_name': snapshot_name})
def remove_host_with_check(self, host_id): def remove_host_with_check(self, host_id):
@ -1544,16 +1549,16 @@ class HuaweiBaseDriver(driver.VolumeDriver):
model_update = {} model_update = {}
volumes_model_update = [] volumes_model_update = []
model_update.update({'status': group['status']}) model_update.update({'status': group.status})
for volume_ref in volumes: for volume_ref in volumes:
try: try:
self.delete_volume(volume_ref) self.delete_volume(volume_ref)
volumes_model_update.append( volumes_model_update.append(
{'id': volume_ref['id'], 'status': 'deleted'}) {'id': volume_ref.id, 'status': 'deleted'})
except Exception: except Exception:
volumes_model_update.append( volumes_model_update.append(
{'id': volume_ref['id'], 'status': 'error_deleting'}) {'id': volume_ref.id, 'status': 'error_deleting'})
return model_update, volumes_model_update return model_update, volumes_model_update
@ -1579,7 +1584,7 @@ class HuaweiBaseDriver(driver.VolumeDriver):
"""Create cgsnapshot.""" """Create cgsnapshot."""
LOG.info(_LI('Create cgsnapshot for consistency group' LOG.info(_LI('Create cgsnapshot for consistency group'
': %(group_id)s'), ': %(group_id)s'),
{'group_id': cgsnapshot['consistencygroup_id']}) {'group_id': cgsnapshot.consistencygroup_id})
model_update = {} model_update = {}
snapshots_model_update = [] snapshots_model_update = []
@ -1587,22 +1592,22 @@ class HuaweiBaseDriver(driver.VolumeDriver):
try: try:
for snapshot in snapshots: for snapshot in snapshots:
volume = snapshot.get('volume') volume = snapshot.volume
if not volume: if not volume:
msg = (_("Can't get volume id from snapshot, " msg = (_("Can't get volume id from snapshot, "
"snapshot: %(id)s") % {"id": snapshot['id']}) "snapshot: %(id)s") % {"id": snapshot.id})
LOG.error(msg) LOG.error(msg)
raise exception.VolumeBackendAPIException(data=msg) raise exception.VolumeBackendAPIException(data=msg)
volume_name = huawei_utils.encode_name(volume['id']) volume_name = huawei_utils.encode_name(volume.id)
lun_id = self.client.get_lun_id(volume, volume_name) lun_id = self.client.get_lun_id(volume, volume_name)
snapshot_name = huawei_utils.encode_name(snapshot['id']) snapshot_name = huawei_utils.encode_name(snapshot.id)
snapshot_description = snapshot['id'] snapshot_description = snapshot.id
info = self.client.create_snapshot(lun_id, info = self.client.create_snapshot(lun_id,
snapshot_name, snapshot_name,
snapshot_description) snapshot_description)
snapshot_model_update = {'id': snapshot['id'], snapshot_model_update = {'id': snapshot.id,
'status': 'available', 'status': 'available',
'provider_location': info['ID']} 'provider_location': info['ID']}
snapshots_model_update.append(snapshot_model_update) snapshots_model_update.append(snapshot_model_update)
@ -1610,7 +1615,7 @@ class HuaweiBaseDriver(driver.VolumeDriver):
except Exception: except Exception:
with excutils.save_and_reraise_exception(): with excutils.save_and_reraise_exception():
LOG.error(_LE("Create cgsnapshots failed. " LOG.error(_LE("Create cgsnapshots failed. "
"Cgsnapshot id: %s."), cgsnapshot['id']) "Cgsnapshot id: %s."), cgsnapshot.id)
snapshot_ids = [added_snapshot['ID'] snapshot_ids = [added_snapshot['ID']
for added_snapshot in added_snapshots_info] for added_snapshot in added_snapshots_info]
try: try:
@ -1618,7 +1623,7 @@ class HuaweiBaseDriver(driver.VolumeDriver):
except Exception: except Exception:
with excutils.save_and_reraise_exception(): with excutils.save_and_reraise_exception():
LOG.error(_LE("Active cgsnapshots failed. " LOG.error(_LE("Active cgsnapshots failed. "
"Cgsnapshot id: %s."), cgsnapshot['id']) "Cgsnapshot id: %s."), cgsnapshot.id)
model_update['status'] = 'available' model_update['status'] = 'available'
@ -1628,22 +1633,22 @@ class HuaweiBaseDriver(driver.VolumeDriver):
"""Delete consistency group snapshot.""" """Delete consistency group snapshot."""
LOG.info(_LI('Delete cgsnapshot %(snap_id)s for consistency group: ' LOG.info(_LI('Delete cgsnapshot %(snap_id)s for consistency group: '
'%(group_id)s'), '%(group_id)s'),
{'snap_id': cgsnapshot['id'], {'snap_id': cgsnapshot.id,
'group_id': cgsnapshot['consistencygroup_id']}) 'group_id': cgsnapshot.consistencygroup_id})
model_update = {} model_update = {}
snapshots_model_update = [] snapshots_model_update = []
model_update['status'] = cgsnapshot['status'] model_update['status'] = cgsnapshot.status
for snapshot in snapshots: for snapshot in snapshots:
try: try:
self.delete_snapshot(snapshot) self.delete_snapshot(snapshot)
snapshots_model_update.append({'id': snapshot['id'], snapshots_model_update.append({'id': snapshot.id,
'status': 'deleted'}) 'status': 'deleted'})
except Exception: except Exception:
with excutils.save_and_reraise_exception(): with excutils.save_and_reraise_exception():
LOG.error(_LE("Delete cg snapshots failed. " LOG.error(_LE("Delete cg snapshots failed. "
"Cgsnapshot id: %s"), cgsnapshot['id']) "Cgsnapshot id: %s"), cgsnapshot.id)
return model_update, snapshots_model_update return model_update, snapshots_model_update
@ -1665,7 +1670,7 @@ class HuaweiBaseDriver(driver.VolumeDriver):
volumes_update = [] volumes_update = []
for v in volumes: for v in volumes:
v_update = {} v_update = {}
v_update['volume_id'] = v['id'] v_update['volume_id'] = v.id
metadata = huawei_utils.get_volume_metadata(v) metadata = huawei_utils.get_volume_metadata(v)
old_status = 'available' old_status = 'available'
if 'old_status' in metadata: if 'old_status' in metadata:
@ -1705,9 +1710,9 @@ class HuaweiBaseDriver(driver.VolumeDriver):
for v in volumes: for v in volumes:
v_update = {} v_update = {}
v_update['volume_id'] = v['id'] v_update['volume_id'] = v.id
metadata = huawei_utils.get_volume_metadata(v) metadata = huawei_utils.get_volume_metadata(v)
metadata.update({'old_status': v['status']}) metadata.update({'old_status': v.status})
v_update['updates'] = {'status': 'error', v_update['updates'] = {'status': 'error',
'metadata': metadata} 'metadata': metadata}
volumes_update.append(v_update) volumes_update.append(v_update)
@ -1845,7 +1850,7 @@ class HuaweiISCSIDriver(HuaweiBaseDriver, driver.ISCSIDriver):
# Return iSCSI properties. # Return iSCSI properties.
properties = {} properties = {}
properties['target_discovered'] = False properties['target_discovered'] = False
properties['volume_id'] = volume['id'] properties['volume_id'] = volume.id
multipath = connector.get('multipath', False) multipath = connector.get('multipath', False)
hostlun_id = int(hostlun_id) hostlun_id = int(hostlun_id)
if not multipath: if not multipath:
@ -2068,7 +2073,7 @@ class HuaweiFCDriver(HuaweiBaseDriver, driver.FibreChannelDriver):
'data': {'target_lun': int(host_lun_id), 'data': {'target_lun': int(host_lun_id),
'target_discovered': True, 'target_discovered': True,
'target_wwn': tgt_port_wwns, 'target_wwn': tgt_port_wwns,
'volume_id': volume['id'], 'volume_id': volume.id,
'initiator_target_map': init_targ_map, 'initiator_target_map': init_targ_map,
'map_info': map_info}, } 'map_info': map_info}, }

View File

@ -74,8 +74,8 @@ def get_volume_size(volume):
calculates volume size with sectors, which is 512 bytes. calculates volume size with sectors, which is 512 bytes.
""" """
volume_size = units.Gi / 512 # 1G volume_size = units.Gi / 512 # 1G
if int(volume['size']) != 0: if int(volume.size) != 0:
volume_size = int(volume['size']) * units.Gi / 512 volume_size = int(volume.size) * units.Gi / 512
return volume_size return volume_size
@ -94,13 +94,13 @@ def get_volume_metadata(volume):
def get_admin_metadata(volume): def get_admin_metadata(volume):
admin_metadata = {} admin_metadata = {}
if 'admin_metadata' in volume: if 'admin_metadata' in volume:
admin_metadata = volume['admin_metadata'] admin_metadata = volume.admin_metadata
elif 'volume_admin_metadata' in volume: elif 'volume_admin_metadata' in volume:
metadata = volume.get('volume_admin_metadata', []) metadata = volume.get('volume_admin_metadata', [])
admin_metadata = {item['key']: item['value'] for item in metadata} admin_metadata = {item['key']: item['value'] for item in metadata}
LOG.debug("Volume ID: %(id)s, admin_metadata: %(admin_metadata)s.", LOG.debug("Volume ID: %(id)s, admin_metadata: %(admin_metadata)s.",
{"id": volume['id'], "admin_metadata": admin_metadata}) {"id": volume.id, "admin_metadata": admin_metadata})
return admin_metadata return admin_metadata
@ -109,7 +109,7 @@ def get_snapshot_metadata_value(snapshot):
return snapshot.metadata return snapshot.metadata
if 'snapshot_metadata' in snapshot: if 'snapshot_metadata' in snapshot:
metadata = snapshot.get('snapshot_metadata') metadata = snapshot.snapshot_metadata
return {item['key']: item['value'] for item in metadata} return {item['key']: item['value'] for item in metadata}
return {} return {}

View File

@ -103,7 +103,7 @@ class HuaweiHyperMetro(object):
def connect_volume_fc(self, volume, connector): def connect_volume_fc(self, volume, connector):
"""Create map between a volume and a host for FC.""" """Create map between a volume and a host for FC."""
wwns = connector['wwpns'] wwns = connector['wwpns']
volume_name = huawei_utils.encode_name(volume['id']) volume_name = huawei_utils.encode_name(volume.id)
LOG.info(_LI( LOG.info(_LI(
'initialize_connection_fc, initiator: %(wwpns)s,' 'initialize_connection_fc, initiator: %(wwpns)s,'
@ -172,7 +172,7 @@ class HuaweiHyperMetro(object):
'data': {'target_lun': int(host_lun_id), 'data': {'target_lun': int(host_lun_id),
'target_discovered': True, 'target_discovered': True,
'target_wwn': tgt_port_wwns, 'target_wwn': tgt_port_wwns,
'volume_id': volume['id'], 'volume_id': volume.id,
'initiator_target_map': init_targ_map, 'initiator_target_map': init_targ_map,
'map_info': map_info}, 'map_info': map_info},
} }
@ -184,7 +184,7 @@ class HuaweiHyperMetro(object):
def disconnect_volume_fc(self, volume, connector): def disconnect_volume_fc(self, volume, connector):
"""Delete map between a volume and a host for FC.""" """Delete map between a volume and a host for FC."""
wwns = connector['wwpns'] wwns = connector['wwpns']
volume_name = huawei_utils.encode_name(volume['id']) volume_name = huawei_utils.encode_name(volume.id)
metadata = huawei_utils.get_volume_metadata(volume) metadata = huawei_utils.get_volume_metadata(volume)
lun_id = metadata['remote_lun_id'] lun_id = metadata['remote_lun_id']
host_name = connector['host'] host_name = connector['host']
@ -270,8 +270,8 @@ class HuaweiHyperMetro(object):
def create_consistencygroup(self, group): def create_consistencygroup(self, group):
LOG.info(_LI("Create Consistency Group: %(group)s."), LOG.info(_LI("Create Consistency Group: %(group)s."),
{'group': group['id']}) {'group': group.id})
group_name = huawei_utils.encode_name(group['id']) group_name = huawei_utils.encode_name(group.id)
domain_name = self.configuration.metro_domain_name domain_name = self.configuration.metro_domain_name
domain_id = self.client.get_hyper_domain_id(domain_name) domain_id = self.client.get_hyper_domain_id(domain_name)
if not domain_name or not domain_id: if not domain_name or not domain_id:
@ -279,21 +279,21 @@ class HuaweiHyperMetro(object):
LOG.error(msg) LOG.error(msg)
raise exception.VolumeBackendAPIException(data=msg) raise exception.VolumeBackendAPIException(data=msg)
self.client.create_metrogroup(group_name, group['id'], domain_id) self.client.create_metrogroup(group_name, group.id, domain_id)
def delete_consistencygroup(self, context, group, volumes): def delete_consistencygroup(self, context, group, volumes):
LOG.info(_LI("Delete Consistency Group: %(group)s."), LOG.info(_LI("Delete Consistency Group: %(group)s."),
{'group': group['id']}) {'group': group.id})
model_update = {} model_update = {}
volumes_model_update = [] volumes_model_update = []
model_update['status'] = group['status'] model_update['status'] = group.status
metrogroup_id = self.check_consistencygroup_need_to_stop(group) metrogroup_id = self.check_consistencygroup_need_to_stop(group)
if metrogroup_id: if metrogroup_id:
self.client.delete_metrogroup(metrogroup_id) self.client.delete_metrogroup(metrogroup_id)
# Deal with the return volumes info # Deal with the return volumes info
for volume_ref in volumes: for volume_ref in volumes:
volume_update = {'id': volume_ref['id']} volume_update = {'id': volume_ref.id}
volume_update['status'] = 'deleted' volume_update['status'] = 'deleted'
volumes_model_update.append(volume_update) volumes_model_update.append(volume_update)
@ -303,9 +303,9 @@ class HuaweiHyperMetro(object):
add_volumes, remove_volumes): add_volumes, remove_volumes):
LOG.info(_LI("Update Consistency Group: %(group)s. " LOG.info(_LI("Update Consistency Group: %(group)s. "
"This adds or removes volumes from a CG."), "This adds or removes volumes from a CG."),
{'group': group['id']}) {'group': group.id})
model_update = {} model_update = {}
model_update['status'] = group['status'] model_update['status'] = group.status
metrogroup_id = self.check_consistencygroup_need_to_stop(group) metrogroup_id = self.check_consistencygroup_need_to_stop(group)
if metrogroup_id: if metrogroup_id:
# Deal with add volumes to CG # Deal with add volumes to CG
@ -350,7 +350,7 @@ class HuaweiHyperMetro(object):
return metro_id return metro_id
def check_consistencygroup_need_to_stop(self, group): def check_consistencygroup_need_to_stop(self, group):
group_name = huawei_utils.encode_name(group['id']) group_name = huawei_utils.encode_name(group.id)
metrogroup_id = self.client.get_metrogroup_by_name(group_name) metrogroup_id = self.client.get_metrogroup_by_name(group_name)
if metrogroup_id: if metrogroup_id:

View File

@ -314,8 +314,8 @@ class ReplicaCommonDriver(object):
def get_replication_driver_data(volume): def get_replication_driver_data(volume):
if volume.get('replication_driver_data'): if volume.replication_driver_data:
return json.loads(volume['replication_driver_data']) return json.loads(volume.replication_driver_data)
return {} return {}
@ -531,7 +531,7 @@ class ReplicaPairManager(object):
1. delete replication pair 1. delete replication pair
2. delete remote_lun 2. delete remote_lun
""" """
LOG.debug('Delete replication, volume: %s.', volume['id']) LOG.debug('Delete replication, volume: %s.', volume.id)
info = get_replication_driver_data(volume) info = get_replication_driver_data(volume)
pair_id = info.get('pair_id') pair_id = info.get('pair_id')
if pair_id: if pair_id:
@ -555,18 +555,18 @@ class ReplicaPairManager(object):
volumes_update = [] volumes_update = []
for v in volumes: for v in volumes:
v_update = {} v_update = {}
v_update['volume_id'] = v['id'] v_update['volume_id'] = v.id
drv_data = get_replication_driver_data(v) drv_data = get_replication_driver_data(v)
pair_id = drv_data.get('pair_id') pair_id = drv_data.get('pair_id')
if not pair_id: if not pair_id:
LOG.warning(_LW("No pair id in volume %s."), v['id']) LOG.warning(_LW("No pair id in volume %s."), v.id)
v_update['updates'] = {'replication_status': 'error'} v_update['updates'] = {'replication_status': 'error'}
volumes_update.append(v_update) volumes_update.append(v_update)
continue continue
rmt_lun_id = drv_data.get('rmt_lun_id') rmt_lun_id = drv_data.get('rmt_lun_id')
if not rmt_lun_id: if not rmt_lun_id:
LOG.warning(_LW("No remote lun id in volume %s."), v['id']) LOG.warning(_LW("No remote lun id in volume %s."), v.id)
v_update['updates'] = {'replication_status': 'error'} v_update['updates'] = {'replication_status': 'error'}
volumes_update.append(v_update) volumes_update.append(v_update)
continue continue
@ -587,7 +587,7 @@ class ReplicaPairManager(object):
admin_metadata = huawei_utils.get_admin_metadata(v) admin_metadata = huawei_utils.get_admin_metadata(v)
admin_metadata.update({'huawei_lun_wwn': lun_info['WWN']}) admin_metadata.update({'huawei_lun_wwn': lun_info['WWN']})
new_drv_data = {'pair_id': pair_id, new_drv_data = {'pair_id': pair_id,
'rmt_lun_id': v['provider_location']} 'rmt_lun_id': v.provider_location}
new_drv_data = to_string(new_drv_data) new_drv_data = to_string(new_drv_data)
v_update['updates'] = {'provider_location': rmt_lun_id, v_update['updates'] = {'provider_location': rmt_lun_id,
'replication_status': 'available', 'replication_status': 'available',
@ -605,18 +605,18 @@ class ReplicaPairManager(object):
volumes_update = [] volumes_update = []
for v in volumes: for v in volumes:
v_update = {} v_update = {}
v_update['volume_id'] = v['id'] v_update['volume_id'] = v.id
drv_data = get_replication_driver_data(v) drv_data = get_replication_driver_data(v)
pair_id = drv_data.get('pair_id') pair_id = drv_data.get('pair_id')
if not pair_id: if not pair_id:
LOG.warning(_LW("No pair id in volume %s."), v['id']) LOG.warning(_LW("No pair id in volume %s."), v.id)
v_update['updates'] = {'replication_status': 'error'} v_update['updates'] = {'replication_status': 'error'}
volumes_update.append(v_update) volumes_update.append(v_update)
continue continue
rmt_lun_id = drv_data.get('rmt_lun_id') rmt_lun_id = drv_data.get('rmt_lun_id')
if not rmt_lun_id: if not rmt_lun_id:
LOG.warning(_LW("No remote lun id in volume %s."), v['id']) LOG.warning(_LW("No remote lun id in volume %s."), v.id)
v_update['updates'] = {'replication_status': 'error'} v_update['updates'] = {'replication_status': 'error'}
volumes_update.append(v_update) volumes_update.append(v_update)
continue continue
@ -628,7 +628,7 @@ class ReplicaPairManager(object):
admin_metadata.update({'huawei_lun_wwn': lun_info['WWN']}) admin_metadata.update({'huawei_lun_wwn': lun_info['WWN']})
new_drv_data = {'pair_id': pair_id, new_drv_data = {'pair_id': pair_id,
'rmt_lun_id': v['provider_location']} 'rmt_lun_id': v.provider_location}
new_drv_data = to_string(new_drv_data) new_drv_data = to_string(new_drv_data)
v_update['updates'] = {'provider_location': rmt_lun_id, v_update['updates'] = {'provider_location': rmt_lun_id,
'replication_status': 'failed-over', 'replication_status': 'failed-over',

View File

@ -308,12 +308,12 @@ class RestClient(object):
return result['data'] return result['data']
def get_lun_id(self, volume, volume_name): def get_lun_id(self, volume, volume_name):
lun_id = (volume.get('provider_location') or lun_id = (volume.provider_location or
self.get_lun_id_by_name(volume_name)) self.get_lun_id_by_name(volume_name))
if not lun_id: if not lun_id:
msg = (_("Can't find lun info on the array. " msg = (_("Can't find lun info on the array. "
"volume: %(id)s, lun name: %(name)s.") % "volume: %(id)s, lun name: %(name)s.") %
{'id': volume['id'], 'name': volume_name}) {'id': volume.id, 'name': volume_name})
LOG.error(msg) LOG.error(msg)
raise exception.VolumeBackendAPIException(data=msg) raise exception.VolumeBackendAPIException(data=msg)
return lun_id return lun_id