Esempio n. 1
0
    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, {}
Esempio n. 2
0
 def remove_qos_lun(self, lun_id, qos_id):
     lun_list = self.restclient.get_lun_list_in_qos(qos_id)
     lun_count = len(lun_list)
     if lun_count <= 1:
         qos = smartx.SmartQos(self.restclient)
         qos.delete_qos(qos_id)
     else:
         self.restclient.remove_lun_from_qos(lun_id, lun_list, qos_id)
Esempio n. 3
0
 def _delete_lun_with_check(self, dst_id):
     LOG.info(_LI("Try to delete lun %s if it exists."), dst_id)
     if self.restclient.check_lun_exist(dst_id):
         qos_id = self.restclient.get_qosid_by_lunid(dst_id)
         if qos_id:
             qos = smartx.SmartQos(self.restclient)
             qos.delete_qos(qos_id)
         self.restclient.delete_lun(dst_id)
Esempio n. 4
0
    def modify_lun(self, lun_id, change_opts):
        if change_opts.get('partitionid', None):
            old, new = change_opts['partitionid']
            old_id = old[0]
            old_name = old[1]
            new_id = new[0]
            new_name = new[1]
            if old_id:
                self.restclient.remove_lun_from_partition(lun_id, old_id)
            if new_id:
                self.restclient.add_lun_to_partition(lun_id, new_id)
            LOG.info(_LI("Retype LUN(id: %(lun_id)s) smartpartition from "
                         "(name: %(old_name)s, id: %(old_id)s) to "
                         "(name: %(new_name)s, id: %(new_id)s) success."),
                     {"lun_id": lun_id,
                      "old_id": old_id, "old_name": old_name,
                      "new_id": new_id, "new_name": new_name})

        if change_opts.get('cacheid', None):
            old, new = change_opts['cacheid']
            old_id = old[0]
            old_name = old[1]
            new_id = new[0]
            new_name = new[1]
            if old_id:
                self.restclient.remove_lun_from_cache(lun_id, old_id)
            if new_id:
                self.restclient.add_lun_to_cache(lun_id, new_id)
            LOG.info(_LI("Retype LUN(id: %(lun_id)s) smartcache from "
                         "(name: %(old_name)s, id: %(old_id)s) to "
                         "(name: %(new_name)s, id: %(new_id)s) successfully."),
                     {'lun_id': lun_id,
                      'old_id': old_id, "old_name": old_name,
                      'new_id': new_id, "new_name": new_name})

        if change_opts.get('policy', None):
            old_policy, new_policy = change_opts['policy']
            self.restclient.change_lun_smarttier(lun_id, new_policy)
            LOG.info(_LI("Retype LUN(id: %(lun_id)s) smarttier policy from "
                         "%(old_policy)s to %(new_policy)s success."),
                     {'lun_id': lun_id,
                      'old_policy': old_policy,
                      'new_policy': new_policy})

        if change_opts.get('qos', None):
            old_qos, new_qos = change_opts['qos']
            old_qos_id = old_qos[0]
            old_qos_value = old_qos[1]
            if old_qos_id:
                self.remove_qos_lun(lun_id, old_qos_id)
            if new_qos:
                smart_qos = smartx.SmartQos(self.restclient)
                smart_qos.create_qos(new_qos, lun_id)
            LOG.info(_LI("Retype LUN(id: %(lun_id)s) smartqos from "
                         "%(old_qos_value)s to %(new_qos)s success."),
                     {'lun_id': lun_id,
                      'old_qos_value': old_qos_value,
                      'new_qos': new_qos})
Esempio n. 5
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
        }
Esempio n. 6
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:
            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}