'Manages an existing vdisk.
Renames the vdisk to match the expected name for the volume.
Error checking done by manage_existing_get_size is not repeated -
if we got here then we have a vdisk that isn\'t in use (or we don\'t
care if it is in use.'

def manage_existing(self, volume, ref):

    vdisk = self._manage_input_check(ref)
    vdisk_io_grp = self._helpers.get_volume_io_group(vdisk['name'])
    if (vdisk_io_grp not in self._state['available_iogrps']):
        msg = _('Failed    to    manage    existing    volume    due    to    the    volume    to    be    managed    is    not    in    a    valid    I/O    group.')
        raise exception.ManageExistingVolumeTypeMismatch(reason=msg)
    ctxt = context.get_admin_context()
    rep_type = self._get_volume_replicated_type(ctxt, volume)
    vol_rep_type = None
    rel_info = self._helpers.get_relationship_info(vdisk['name'])
    copies = self._helpers.get_vdisk_copies(vdisk['name'])
    if rel_info:
        vol_rep_type = (storwize_const.GMCV if (storwize_const.GMCV_MULTI == rel_info['cycling_mode']) else rel_info['copy_type'])
        aux_info = self._aux_backend_helpers.get_system_info()
        if (rel_info['aux_cluster_id'] != aux_info['system_id']):
            msg = (_('Failed    to    manage    existing    volume    due    to    the    aux    cluster    for    volume    %(volume)s    is    %(aux_id)s.    The    configured    cluster    id    is    %(cfg_id)s') % {'volume': vdisk['name'], 'aux_id': rel_info['aux_cluster_id'], 'cfg_id': aux_info['system_id']})
            raise exception.ManageExistingVolumeTypeMismatch(reason=msg)
    if (vol_rep_type != rep_type):
        msg = _('Failed    to    manage    existing    volume    due    to    the    replication    type    of    the    volume    to    be    managed    is    mismatch    with    the    provided    replication    type.')
        raise exception.ManageExistingVolumeTypeMismatch(reason=msg)
    elif (storwize_const.GMCV == rep_type):
        if volume['volume_type_id']:
            rep_opts = self._get_vdisk_params(volume['volume_type_id'], volume_metadata=volume.get('volume_metadata'))
            rep_cps = six.text_type(rep_opts.get('cycle_period_seconds'))
        if (rel_info['cycle_period_seconds'] != rep_cps):
            msg = (_('Failed    to    manage    existing    volume    due    to    the    cycle_period_seconds    %(vol_cps)s    of    the    volume    to    be    managed    is    mismatch    with    cycle_period_seconds    %(type_cps)s    in    the    provided    gmcv    replication    type.') % {'vol_cps': rel_info['cycle_period_seconds'], 'type_cps': rep_cps})
            raise exception.ManageExistingVolumeTypeMismatch(reason=msg)
    if volume['volume_type_id']:
        opts = self._get_vdisk_params(volume['volume_type_id'], volume_metadata=volume.get('volume_metadata'))
        resp = self._helpers.lsvdiskcopy(vdisk['name'])
        expected_copy_num = (2 if opts['mirror_pool'] else 1)
        if (len(resp) != expected_copy_num):
            msg = (_('Failed    to    manage    existing    volume    due    to    mirror    type    mismatch.    Volume    to    be    managed    has    %(resp_len)s    copies.    mirror_pool    of    the    chosen    type    is    %(mirror_pool)s.') % {'resp_len': len(resp), 'mirror_pool': opts['mirror_pool']})
            raise exception.ManageExistingVolumeTypeMismatch(reason=msg)
        if (opts['mirror_pool'] and (opts['mirror_pool'] != copies['secondary']['mdisk_grp_name'])):
            msg = (_('Failed    to    manage    existing    volume    due    to    mirror    pool    mismatch.    The    secondary    pool    of    the    volume    to    be    managed    is    %(sec_copy_pool)s.    mirror_pool    of    the    chosen    type    is    %(mirror_pool)s.') % {'sec_copy_pool': copies['secondary']['mdisk_grp_name'], 'mirror_pool': opts['mirror_pool']})
            raise exception.ManageExistingVolumeTypeMismatch(reason=msg)
        vdisk_copy = self._helpers.get_vdisk_copy_attrs(vdisk['name'], '0')
        if ((vdisk_copy['autoexpand'] == 'on') and (opts['rsize'] == (-1))):
            msg = _('Failed    to    manage    existing    volume    due    to    the    volume    to    be    managed    is    thin,    but    the    volume    type    chosen    is    thick.')
            raise exception.ManageExistingVolumeTypeMismatch(reason=msg)
        if ((not vdisk_copy['autoexpand']) and (opts['rsize'] != (-1))):
            msg = _('Failed    to    manage    existing    volume    due    to    the    volume    to    be    managed    is    thick,    but    the    volume    type    chosen    is    thin.')
            raise exception.ManageExistingVolumeTypeMismatch(reason=msg)
        if ((vdisk_copy['compressed_copy'] == 'no') and opts['compression']):
            msg = _('Failed    to    manage    existing    volume    due    to    the    volume    to    be    managed    is    not    compress,    but    the    volume    type    chosen    is    compress.')
            raise exception.ManageExistingVolumeTypeMismatch(reason=msg)
        if ((vdisk_copy['compressed_copy'] == 'yes') and (not opts['compression'])):
            msg = _('Failed    to    manage    existing    volume    due    to    the    volume    to    be    managed    is    compress,    but    the    volume    type    chosen    is    not    compress.')
            raise exception.ManageExistingVolumeTypeMismatch(reason=msg)
        if (vdisk_io_grp not in StorwizeHelpers._get_valid_requested_io_groups(self._state, opts)):
            msg = (_('Failed    to    manage    existing    volume    due    to    I/O    group    mismatch.    The    I/O    group    of    the    volume    to    be    managed    is    %(vdisk_iogrp)s.    I/O    groupof    the    chosen    type    is    %(opt_iogrp)s.') % {'vdisk_iogrp': vdisk['IO_group_name'], 'opt_iogrp': opts['iogrp']})
            raise exception.ManageExistingVolumeTypeMismatch(reason=msg)
    pool = utils.extract_host(volume['host'], 'pool')
    if (copies['primary']['mdisk_grp_name'] != pool):
        msg = (_('Failed    to    manage    existing    volume    due    to    the    pool    of    the    volume    to    be    managed    does    not    match    the    backend    pool.    Pool    of    the    volume    to    be    managed    is    %(vdisk_pool)s.    Pool    of    the    backend    is    %(backend_pool)s.') % {'vdisk_pool': copies['primary']['mdisk_grp_name'], 'backend_pool': pool})
        raise exception.ManageExistingVolumeTypeMismatch(reason=msg)
    model_update = {}
    self._helpers.rename_vdisk(vdisk['name'], volume['name'])
    if vol_rep_type:
        aux_vol = (storwize_const.REPLICA_AUX_VOL_PREFIX + volume['name'])
        self._aux_backend_helpers.rename_vdisk(rel_info['aux_vdisk_name'], aux_vol)
        if (storwize_const.GMCV == vol_rep_type):
            self._helpers.rename_vdisk(rel_info['master_change_vdisk_name'], (storwize_const.REPLICA_CHG_VOL_PREFIX + volume['name']))
            self._aux_backend_helpers.rename_vdisk(rel_info['aux_change_vdisk_name'], (storwize_const.REPLICA_CHG_VOL_PREFIX + aux_vol))
        model_update = {'replication_status': fields.ReplicationStatus.ENABLED}
    return model_update
