'Manage an existing volume on the backend storage.'

def manage_existing(self, volume, external_ref):

    pool = volume_utils.extract_host(volume.host, 'pool')
    LOG.debug('Pool    specified    is:    %s.', pool)
    lun_info = self._get_lun_info_by_ref(external_ref)
    lun_id = lun_info.get('ID')
    description = lun_info.get('DESCRIPTION', '')
    if (len(description) <= ((constants.MAX_VOL_DESCRIPTION - len(volume.name)) - 1)):
        description = ((volume.name + '    ') + description)
    lun_pool = lun_info.get('PARENTNAME')
    LOG.debug('Storage    pool    of    existing    LUN    %(lun)s    is    %(pool)s.', {'lun': lun_id, 'pool': lun_pool})
    if (pool != lun_pool):
        msg = (_('The    specified    LUN    does    not    belong    to    the    given    pool:    %s.') % pool)
        raise exception.ManageExistingInvalidReference(existing_ref=external_ref, reason=msg)
    self._check_lun_valid_for_manage(lun_info, external_ref)
    type_id = volume.volume_type_id
    new_opts = None
    if type_id:
        old_opts = self.get_lun_specs(lun_id)
        volume_type = volume_types.get_volume_type(None, type_id)
        new_specs = volume_type.get('extra_specs')
        new_opts = self._get_volume_params_from_specs(new_specs)
        if (('LUNType' in new_opts) and (old_opts['LUNType'] != new_opts['LUNType'])):
            msg = (_("Can't    import    LUN    %(lun_id)s    to    Cinder.    LUN    type    mismatched.") % lun_id)
            raise exception.ManageExistingVolumeTypeMismatch(reason=msg)
        if volume_type:
            self._check_capability_support(new_opts, volume_type)
            change_opts = {'policy': None, 'partitionid': None, 'cacheid': None, 'qos': None}
            change_opts = self._check_needed_changes(lun_id, old_opts, new_opts, change_opts, volume_type)
            self.modify_lun(lun_id, change_opts)
    new_name = huawei_utils.encode_name(volume.id)
    LOG.debug('Rename    LUN    %(old_name)s    to    %(new_name)s.', {'old_name': lun_info.get('NAME'), 'new_name': new_name})
    self.client.rename_lun(lun_id, new_name, description)
    location = huawei_utils.to_string(huawei_lun_id=lun_id, huawei_lun_wwn=lun_info['WWN'])
    model_update = {'provider_location': location}
    if (new_opts and new_opts.get('replication_enabled')):
        LOG.debug('Manage    volume    need    to    create    replication.')
        try:
            lun_info = self.client.get_lun_info(lun_id)
            replica_info = self.replica.create_replica(lun_info, new_opts.get('replication_type'))
            model_update.update(replica_info)
        except exception.VolumeBackendAPIException:
            with excutils.save_and_reraise_exception():
                LOG.exception('Manage    exist    volume    failed.')
    return model_update
