'This function will do or ensure the following:
-Create volume on main array (already done in create_volume)
-Create volume on secondary array
-Make volume remote on secondary array
-Create the snapshot schedule
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, client, optional=None):

    schedule_name = (volume['name'] + self.REP_SCHEDULE_SUFFIX)
    if self._does_snapshot_schedule_exist((schedule_name + '_Pri'), client):
        try:
            client.startRemoteSnapshotSchedule((schedule_name + '_Pri'))
        except Exception:
            pass
        return True
    volume_type = self._get_volume_type(volume['volume_type_id'])
    extra_specs = volume_type.get('extra_specs')
    replication_sync_period = extra_specs.get(self.EXTRA_SPEC_REP_SYNC_PERIOD)
    if replication_sync_period:
        replication_sync_period = int(replication_sync_period)
        if (replication_sync_period < self.MIN_REP_SYNC_PERIOD):
            msg = (_('The    replication    sync    period    must    be    at    least    %s    seconds.') % self.MIN_REP_SYNC_PERIOD)
            LOG.error(msg)
            raise exception.VolumeBackendAPIException(data=msg)
    else:
        replication_sync_period = self.MIN_REP_SYNC_PERIOD
        LOG.warning('There    was    no    extra_spec    value    for    %(spec_name)s,    so    the    default    value    of    %(def_val)s    will    be    used.    To    overwrite    this,    set    this    value    in    the    volume    type    extra_specs.', {'spec_name': self.EXTRA_SPEC_REP_SYNC_PERIOD, 'def_val': self.MIN_REP_SYNC_PERIOD})
    retention_count = extra_specs.get(self.EXTRA_SPEC_REP_RETENTION_COUNT)
    if retention_count:
        retention_count = int(retention_count)
        if (retention_count > self.MAX_RETENTION_COUNT):
            msg = (_('The    retention    count    must    be    %s    or    less.') % self.MAX_RETENTION_COUNT)
            LOG.error(msg)
            raise exception.VolumeBackendAPIException(data=msg)
    else:
        retention_count = self.DEFAULT_RETENTION_COUNT
        LOG.warning('There    was    no    extra_spec    value    for    %(spec_name)s,    so    the    default    value    of    %(def_val)s    will    be    used.    To    overwrite    this,    set    this    value    in    the    volume    type    extra_specs.', {'spec_name': self.EXTRA_SPEC_REP_RETENTION_COUNT, 'def_val': self.DEFAULT_RETENTION_COUNT})
    remote_retention_count = extra_specs.get(self.EXTRA_SPEC_REP_REMOTE_RETENTION_COUNT)
    if remote_retention_count:
        remote_retention_count = int(remote_retention_count)
        if (remote_retention_count > self.MAX_REMOTE_RETENTION_COUNT):
            msg = (_('The    remote    retention    count    must    be    %s    or    less.') % self.MAX_REMOTE_RETENTION_COUNT)
            LOG.error(msg)
            raise exception.VolumeBackendAPIException(data=msg)
    else:
        remote_retention_count = self.DEFAULT_REMOTE_RETENTION_COUNT
        spec_name = self.EXTRA_SPEC_REP_REMOTE_RETENTION_COUNT
        LOG.warning('There    was    no    extra_spec    value    for    %(spec_name)s,    so    the    default    value    of    %(def_val)s    will    be    used.    To    overwrite    this,    set    this    value    in    the    volume    type    extra_specs.', {'spec_name': spec_name, 'def_val': self.DEFAULT_REMOTE_RETENTION_COUNT})
    cl = None
    try:
        for remote_target in self._replication_targets:
            cl = self._create_replication_client(remote_target)
            if optional:
                optional['clusterName'] = remote_target['hpelefthand_clustername']
            cl.createVolume(volume['name'], remote_target['cluster_id'], (volume['size'] * units.Gi), optional)
            snap_name = (volume['name'] + self.REP_SNAPSHOT_SUFFIX)
            cl.makeVolumeRemote(volume['name'], snap_name)
            remote_ip = cl.getIPFromCluster(remote_target['hpelefthand_clustername'])
            self._destroy_replication_client(cl)
            start_date = '1970-01-01T00:00:00Z'
            remote_vol_name = volume['name']
            client.createRemoteSnapshotSchedule(volume['name'], schedule_name, replication_sync_period, start_date, retention_count, remote_target['hpelefthand_clustername'], remote_retention_count, remote_vol_name, remote_ip, remote_target['hpelefthand_username'], remote_target['hpelefthand_password'])
        return True
    except Exception as ex:
        self._destroy_replication_client(cl)
        self._do_volume_replication_destroy(volume, client)
        msg = (_("There    was    an    error    setting    up    a    remote    schedule    on    the    LeftHand    arrays:    ('%s').    The    volume    will    not    be    recognized    as    replication    type.") % six.text_type(ex))
        LOG.error(msg)
        raise exception.VolumeBackendAPIException(data=msg)
