def _migrate_volume(self, volume, host, new_type=None): if not self._check_migration_valid(host, volume): return (False, None) type_id = volume['volume_type_id'] volume_type = None if type_id: volume_type = volume_types.get_volume_type(None, type_id) pool_name = host['capabilities']['pool_name'] pools = self.restclient.find_all_pools() pool_info = self.restclient.find_pool_info(pool_name, pools) src_volume_name = huawei_utils.encode_name(volume['id']) dst_volume_name = six.text_type(hash(src_volume_name)) src_id = volume.get('provider_location', None) src_lun_params = self.restclient.get_lun_info(src_id) opts = None qos = None if new_type: # If new type exists, use new type. opts = huawei_utils._get_extra_spec_value( new_type['extra_specs']) opts = smartx.SmartX().get_smartx_specs_opts(opts) if 'LUNType' not in opts: opts['LUNType'] = huawei_utils.find_luntype_in_xml( self.xml_file_path) qos = huawei_utils.get_qos_by_volume_type(new_type) elif volume_type: qos = huawei_utils.get_qos_by_volume_type(volume_type) if not opts: opts = huawei_utils.get_volume_params(volume) opts = smartx.SmartX().get_smartx_specs_opts(opts) lun_info = self._create_lun_with_extra_feature(pool_info, dst_volume_name, src_lun_params, opts) lun_id = lun_info['ID'] if qos: LOG.info(_LI('QoS: %s.'), qos) SmartQos = smartx.SmartQos(self.restclient) SmartQos.create_qos(qos, lun_id) if opts: smartpartition = smartx.SmartPartition(self.restclient) smartpartition.add(opts, lun_id) smartcache = smartx.SmartCache(self.restclient) smartcache.add(opts, lun_id) dst_id = lun_info['ID'] self._wait_volume_ready(dst_id) moved = self._migrate_lun(src_id, dst_id) return moved, {}
def determine_changes_when_retype(self, volume, new_type, host): migration = False change_opts = { 'policy': None, 'partitionid': None, 'cacheid': None, 'qos': None, 'host': None, 'LUNType': None, } lun_id = volume.get('provider_location') old_opts = self.get_lun_specs(lun_id) new_specs = new_type['extra_specs'] new_opts = huawei_utils._get_extra_spec_value(new_specs) new_opts = smartx.SmartX().get_smartx_specs_opts(new_opts) if 'LUNType' not in new_opts: new_opts['LUNType'] = huawei_utils.find_luntype_in_xml( self.xml_file_path) if volume['host'] != host['host']: migration = True change_opts['host'] = (volume['host'], host['host']) if old_opts['LUNType'] != new_opts['LUNType']: migration = True change_opts['LUNType'] = (old_opts['LUNType'], new_opts['LUNType']) new_cache_id = None new_cache_name = new_opts['cachename'] if new_cache_name: new_cache_id = self.restclient.get_cache_id_by_name(new_cache_name) if new_cache_id is None: msg = (_("Can't find cache name on the array, cache name is: " "%(name)s.") % { 'name': new_cache_name }) LOG.error(msg) raise exception.VolumeBackendAPIException(data=msg) new_partition_id = None new_partition_name = new_opts['partitionname'] if new_partition_name: new_partition_id = self.restclient.get_partition_id_by_name( new_partition_name) if new_partition_id is None: msg = ( _("Can't find partition name on the array, partition name " "is: %(name)s.") % { 'name': new_partition_name }) LOG.error(msg) raise exception.VolumeBackendAPIException(data=msg) # smarttier if old_opts['policy'] != new_opts['policy']: change_opts['policy'] = (old_opts['policy'], new_opts['policy']) # smartcache old_cache_id = old_opts['cacheid'] if old_cache_id != new_cache_id: old_cache_name = None if old_cache_id: cache_info = self.restclient.get_cache_info_by_id(old_cache_id) old_cache_name = cache_info['NAME'] change_opts['cacheid'] = ([old_cache_id, old_cache_name], [new_cache_id, new_cache_name]) # smartpartition old_partition_id = old_opts['partitionid'] if old_partition_id != new_partition_id: old_partition_name = None if old_partition_id: partition_info = self.restclient.get_partition_info_by_id( old_partition_id) old_partition_name = partition_info['NAME'] change_opts['partitionid'] = ([ old_partition_id, old_partition_name ], [new_partition_id, new_partition_name]) # smartqos new_qos = huawei_utils.get_qos_by_volume_type(new_type) old_qos_id = self.restclient.get_qosid_by_lunid(lun_id) old_qos = self._get_qos_specs_from_array(old_qos_id) if old_qos != new_qos: change_opts['qos'] = ([old_qos_id, old_qos], new_qos) LOG.debug( "Determine changes when retype. Migration: " "%(migration)s, change_opts: %(change_opts)s.", { 'migration': migration, 'change_opts': change_opts }) return migration, change_opts, lun_id
def determine_changes_when_retype(self, volume, new_type, host): migration = False change_opts = { 'policy': None, 'partitionid': None, 'cacheid': None, 'qos': None, 'host': None, 'LUNType': None, } lun_id = volume.get('provider_location', None) old_opts = self.get_lun_specs(lun_id) new_specs = new_type['extra_specs'] new_opts = huawei_utils._get_extra_spec_value(new_specs) new_opts = smartx.SmartX().get_smartx_specs_opts(new_opts) if 'LUNType' not in new_opts: new_opts['LUNType'] = huawei_utils.find_luntype_in_xml( self.xml_file_path) if volume['host'] != host['host']: migration = True change_opts['host'] = (volume['host'], host['host']) if old_opts['LUNType'] != new_opts['LUNType']: migration = True change_opts['LUNType'] = (old_opts['LUNType'], new_opts['LUNType']) new_cache_id = None new_cache_name = new_opts['cachename'] if new_cache_name: new_cache_id = self.restclient.get_cache_id_by_name(new_cache_name) if new_cache_id is None: msg = (_( "Can't find cache name on the array, cache name is: " "%(name)s.") % {'name': new_cache_name}) LOG.error(msg) raise exception.VolumeBackendAPIException(data=msg) new_partition_id = None new_partition_name = new_opts['partitionname'] if new_partition_name: new_partition_id = self.restclient.get_partition_id_by_name( new_partition_name) if new_partition_id is None: msg = (_( "Can't find partition name on the array, partition name " "is: %(name)s.") % {'name': new_partition_name}) LOG.error(msg) raise exception.VolumeBackendAPIException(data=msg) # smarttier if old_opts['policy'] != new_opts['policy']: change_opts['policy'] = (old_opts['policy'], new_opts['policy']) # smartcache old_cache_id = old_opts['cacheid'] if old_cache_id != new_cache_id: old_cache_name = None if old_cache_id: cache_info = self.restclient.get_cache_info_by_id(old_cache_id) old_cache_name = cache_info['NAME'] change_opts['cacheid'] = ([old_cache_id, old_cache_name], [new_cache_id, new_cache_name]) # smartpartition old_partition_id = old_opts['partitionid'] if old_partition_id != new_partition_id: old_partition_name = None if old_partition_id: partition_info = self.restclient.get_partition_info_by_id( old_partition_id) old_partition_name = partition_info['NAME'] change_opts['partitionid'] = ([old_partition_id, old_partition_name], [new_partition_id, new_partition_name]) # smartqos new_qos = huawei_utils.get_qos_by_volume_type(new_type) old_qos_id = self.restclient.get_qosid_by_lunid(lun_id) old_qos = self._get_qos_specs_from_array(old_qos_id) if old_qos != new_qos: change_opts['qos'] = ([old_qos_id, old_qos], new_qos) LOG.debug("Determine changes when retype. Migration: " "%(migration)s, change_opts: %(change_opts)s.", {'migration': migration, 'change_opts': change_opts}) return migration, change_opts, lun_id
def determine_changes_when_retype(self, volume, new_type, host): migration = False change_opts = {"policy": None, "partitionid": None, "cacheid": None, "qos": None, "host": None, "LUNType": None} lun_id = volume.get("provider_location", None) old_opts = self.get_lun_specs(lun_id) new_specs = new_type["extra_specs"] new_opts = huawei_utils._get_extra_spec_value(new_specs) new_opts = smartx.SmartX().get_smartx_specs_opts(new_opts) if "LUNType" not in new_opts: new_opts["LUNType"] = huawei_utils.find_luntype_in_xml(self.xml_file_path) if volume["host"] != host["host"]: migration = True change_opts["host"] = (volume["host"], host["host"]) if old_opts["LUNType"] != new_opts["LUNType"]: migration = True change_opts["LUNType"] = (old_opts["LUNType"], new_opts["LUNType"]) new_cache_id = None new_cache_name = new_opts["cachename"] if new_cache_name: new_cache_id = self.restclient.get_cache_id_by_name(new_cache_name) if new_cache_id is None: msg = _("Can't find cache name on the array, cache name is: " "%(name)s.") % {"name": new_cache_name} LOG.error(msg) raise exception.VolumeBackendAPIException(data=msg) new_partition_id = None new_partition_name = new_opts["partitionname"] if new_partition_name: new_partition_id = self.restclient.get_partition_id_by_name(new_partition_name) if new_partition_id is None: msg = _("Can't find partition name on the array, partition name " "is: %(name)s.") % { "name": new_partition_name } LOG.error(msg) raise exception.VolumeBackendAPIException(data=msg) # smarttier if old_opts["policy"] != new_opts["policy"]: change_opts["policy"] = (old_opts["policy"], new_opts["policy"]) # smartcache old_cache_id = old_opts["cacheid"] if old_cache_id != new_cache_id: old_cache_name = None if old_cache_id: cache_info = self.restclient.get_cache_info_by_id(old_cache_id) old_cache_name = cache_info["NAME"] change_opts["cacheid"] = ([old_cache_id, old_cache_name], [new_cache_id, new_cache_name]) # smartpartition old_partition_id = old_opts["partitionid"] if old_partition_id != new_partition_id: old_partition_name = None if old_partition_id: partition_info = self.restclient.get_partition_info_by_id(old_partition_id) old_partition_name = partition_info["NAME"] change_opts["partitionid"] = ( [old_partition_id, old_partition_name], [new_partition_id, new_partition_name], ) # smartqos new_qos = huawei_utils.get_qos_by_volume_type(new_type) old_qos_id = self.restclient.get_qosid_by_lunid(lun_id) old_qos = self._get_qos_specs_from_array(old_qos_id) if old_qos != new_qos: change_opts["qos"] = ([old_qos_id, old_qos], new_qos) LOG.debug( "Determine changes when retype. Migration: " "%(migration)s, change_opts: %(change_opts)s.", {"migration": migration, "change_opts": change_opts}, ) return migration, change_opts, lun_id