'This function will do or ensure the following:
-Create volume on main array (already done in create_volume)
-Create Remote Copy Group on main array
-Add volume to Remote Copy Group on main array
-Start remote copy
If anything here fails, we will need to clean everything up in
reverse order, including the original volume.'

def _do_volume_replication_setup(self, volume, retype=False, dist_type_id=None):

    rcg_name = self._get_3par_rcg_name(volume['id'])
    if self._is_volume_in_remote_copy_group(volume):
        try:
            self.client.startRemoteCopy(rcg_name)
        except Exception:
            pass
        return True
    try:
        volume_type = self._get_volume_type(volume['volume_type_id'])
        if (retype and (dist_type_id is not None)):
            dist_type = self._get_volume_type(dist_type_id)
            extra_specs = dist_type.get('extra_specs')
        else:
            extra_specs = volume_type.get('extra_specs')
        replication_mode = extra_specs.get(self.EXTRA_SPEC_REP_MODE, self.DEFAULT_REP_MODE)
        replication_mode_num = self._get_remote_copy_mode_num(replication_mode)
        replication_sync_period = extra_specs.get(self.EXTRA_SPEC_REP_SYNC_PERIOD, self.DEFAULT_SYNC_PERIOD)
        if replication_sync_period:
            replication_sync_period = int(replication_sync_period)
        if (not self._is_replication_mode_correct(replication_mode, replication_sync_period)):
            msg = _('The    replication    mode    was    not    configured    correctly    in    the    volume    type    extra_specs.    If    replication:mode    is    periodic,    replication:sync_period    must    also    be    specified    and    be    between    300    and    31622400    seconds.')
            LOG.error(msg)
            raise exception.VolumeBackendAPIException(data=msg)
        vol_settings = self.get_volume_settings_from_type(volume)
        local_cpg = vol_settings['cpg']
        vol_name = self._get_3par_vol_name(volume['id'])
        rcg_targets = []
        sync_targets = []
        for target in self._replication_targets:
            if (target['replication_mode'] == replication_mode_num):
                cpg = self._get_cpg_from_cpg_map(target['cpg_map'], local_cpg)
                rcg_target = {'targetName': target['backend_id'], 'mode': replication_mode_num, 'snapCPG': cpg, 'userCPG': cpg}
                rcg_targets.append(rcg_target)
                sync_target = {'targetName': target['backend_id'], 'syncPeriod': replication_sync_period}
                sync_targets.append(sync_target)
        optional = {'localSnapCPG': vol_settings['snap_cpg'], 'localUserCPG': local_cpg}
        pool = volume_utils.extract_host(volume['host'], level='pool')
        domain = self.get_domain(pool)
        if domain:
            optional['domain'] = domain
        try:
            self.client.createRemoteCopyGroup(rcg_name, rcg_targets, optional)
        except Exception as ex:
            msg = (_('There    was    an    error    creating    the    remote    copy    group:    %s.') % six.text_type(ex))
            LOG.error(msg)
            raise exception.VolumeBackendAPIException(data=msg)
        rcg_targets = []
        for target in self._replication_targets:
            if (target['replication_mode'] == replication_mode_num):
                rcg_target = {'targetName': target['backend_id'], 'secVolumeName': vol_name}
                rcg_targets.append(rcg_target)
        optional = {'volumeAutoCreation': True}
        try:
            self.client.addVolumeToRemoteCopyGroup(rcg_name, vol_name, rcg_targets, optional=optional)
        except Exception as ex:
            msg = (_('There    was    an    error    adding    the    volume    to    the    remote    copy    group:    %s.') % six.text_type(ex))
            LOG.error(msg)
            raise exception.VolumeBackendAPIException(data=msg)
        if (replication_sync_period and (replication_mode_num == self.PERIODIC)):
            opt = {'targets': sync_targets}
            try:
                self.client.modifyRemoteCopyGroup(rcg_name, opt)
            except Exception as ex:
                msg = (_('There    was    an    error    setting    the    sync    period    for    the    remote    copy    group:    %s.') % six.text_type(ex))
                LOG.error(msg)
                raise exception.VolumeBackendAPIException(data=msg)
        try:
            self.client.startRemoteCopy(rcg_name)
        except Exception as ex:
            msg = (_('There    was    an    error    starting    remote    copy:    %s.') % six.text_type(ex))
            LOG.error(msg)
            raise exception.VolumeBackendAPIException(data=msg)
        return True
    except Exception as ex:
        self._do_volume_replication_destroy(volume)
        msg = (_("There    was    an    error    setting    up    a    remote    copy    group    on    the    3PAR    arrays:    ('%s').    The    volume    will    not    be    recognized    as    replication    type.") % six.text_type(ex))
        LOG.error(msg)
        raise exception.VolumeBackendAPIException(data=msg)
