コード例 #1
0
ファイル: huawei_driver.py プロジェクト: potsmaster/cinder
    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, {}
コード例 #2
0
    def create_volume(self, volume):
        """Create a volume."""
        opts = huawei_utils.get_volume_params(volume)
        smartx_opts = smartx.SmartX().get_smartx_specs_opts(opts)
        params = huawei_utils.get_lun_params(self.xml_file_path, smartx_opts)
        pool_name = volume_utils.extract_host(volume['host'], level='pool')
        pools = self.restclient.find_all_pools()
        pool_info = self.restclient.find_pool_info(pool_name, pools)
        if not pool_info:
            # The following code is to keep compatibility with old version of
            # Huawei driver.
            pool_names = huawei_utils.get_pools(self.xml_file_path)
            for pool_name in pool_names.split(";"):
                pool_info = self.restclient.find_pool_info(pool_name, pools)
                if pool_info:
                    break

        volume_name = huawei_utils.encode_name(volume['id'])
        volume_description = volume['name']
        volume_size = huawei_utils.get_volume_size(volume)

        LOG.info(_LI('Create volume: %(volume)s, size: %(size)s.'), {
            'volume': volume_name,
            'size': volume_size
        })

        params['pool_id'] = pool_info['ID']
        params['volume_size'] = volume_size
        params['volume_description'] = volume_description

        # Prepare LUN parameters.
        lun_param = huawei_utils.init_lun_parameters(volume_name, params)

        # Create LUN on the array.
        lun_info = self.restclient.create_volume(lun_param)
        lun_id = lun_info['ID']

        try:
            qos = huawei_utils.get_volume_qos(volume)
            if qos:
                smart_qos = smartx.SmartQos(self.restclient)
                smart_qos.create_qos(qos, lun_id)
            smartpartition = smartx.SmartPartition(self.restclient)
            smartpartition.add(opts, lun_id)

            smartcache = smartx.SmartCache(self.restclient)
            smartcache.add(opts, lun_id)
        except Exception as err:
            self._delete_lun_with_check(lun_id)
            raise exception.InvalidInput(
                reason=_('Create volume error. Because %s.') % err)

        return {
            'provider_location': lun_info['ID'],
            'ID': lun_id,
            'lun_info': lun_info
        }
コード例 #3
0
ファイル: huawei_driver.py プロジェクト: potsmaster/cinder
    def create_volume(self, volume):
        """Create a volume."""
        opts = huawei_utils.get_volume_params(volume)
        smartx_opts = smartx.SmartX().get_smartx_specs_opts(opts)
        params = huawei_utils.get_lun_params(self.xml_file_path,
                                             smartx_opts)
        pool_name = volume_utils.extract_host(volume['host'],
                                              level='pool')
        pools = self.restclient.find_all_pools()
        pool_info = self.restclient.find_pool_info(pool_name, pools)
        if not pool_info:
            msg = (_('Error in getting pool information for the pool: %s.')
                   % pool_name)
            LOG.error(msg)
            raise exception.VolumeBackendAPIException(data=msg)
        volume_name = huawei_utils.encode_name(volume['id'])
        volume_description = volume['name']
        volume_size = huawei_utils.get_volume_size(volume)

        LOG.info(_LI(
            'Create volume: %(volume)s, size: %(size)s.'),
            {'volume': volume_name,
             'size': volume_size})

        params['pool_id'] = pool_info['ID']
        params['volume_size'] = volume_size
        params['volume_description'] = volume_description

        # Prepare LUN parameters.
        lun_param = huawei_utils.init_lun_parameters(volume_name, params)

        # Create LUN on the array.
        lun_info = self.restclient.create_volume(lun_param)
        lun_id = lun_info['ID']

        try:
            qos = huawei_utils.get_volume_qos(volume)
            if qos:
                smart_qos = smartx.SmartQos(self.restclient)
                smart_qos.create_qos(qos, lun_id)
            smartpartition = smartx.SmartPartition(self.restclient)
            smartpartition.add(opts, lun_id)

            smartcache = smartx.SmartCache(self.restclient)
            smartcache.add(opts, lun_id)
        except Exception as err:
            if lun_id:
                self._delete_lun_with_check(lun_id)
            raise exception.InvalidInput(
                reason=_('Create volume error. Because %s.') % err)

        return {'provider_location': lun_info['ID'],
                'ID': lun_id,
                'lun_info': lun_info}
コード例 #4
0
    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