'Force failover to a secondary replication target.'

def failover_host(self, context, volumes, secondary_backend_id):

    if (not self._replication_enabled):
        msg = _('Issuing    a    fail-over    failed    because    replication    is    not    properly    configured.')
        LOG.error(msg)
        raise exception.VolumeBackendAPIException(data=msg)
    if (secondary_backend_id and (secondary_backend_id == self.FAILBACK_VALUE)):
        volume_update_list = self._replication_failback(volumes)
        target_id = None
    else:
        failover_target = None
        for target in self._replication_targets:
            if (target['backend_id'] == secondary_backend_id):
                failover_target = target
                break
        if (not failover_target):
            msg = _('A    valid    secondary    target    MUST    be    specified    in    order    to    failover.')
            LOG.error(msg)
            raise exception.InvalidReplicationTarget(reason=msg)
        target_id = failover_target['backend_id']
        volume_update_list = []
        for volume in volumes:
            if self._volume_of_replicated_type(volume):
                try:
                    rcg_name = self._get_3par_rcg_name(volume['id'])
                    self.client.stopRemoteCopy(rcg_name)
                except Exception:
                    pass
                try:
                    remote_rcg_name = self._get_3par_remote_rcg_name(volume['id'], volume['provider_location'])
                    cl = self._create_replication_client(failover_target)
                    cl.recoverRemoteCopyGroupFromDisaster(remote_rcg_name, self.RC_ACTION_CHANGE_TO_PRIMARY)
                    volume_update_list.append({'volume_id': volume['id'], 'updates': {'replication_status': 'failed-over'}})
                except Exception as ex:
                    LOG.error("There    was    a    problem    with    the    failover    (%(error)s)    and    it    was    unsuccessful.    Volume    '%(volume)s    will    not    be    available    on    the    failed    over    target.", {'error': ex, 'volume': volume['id']})
                    LOG.error(msg)
                    volume_update_list.append({'volume_id': volume['id'], 'updates': {'replication_status': 'error'}})
                finally:
                    self._destroy_replication_client(cl)
            else:
                volume_update_list.append({'volume_id': volume['id'], 'updates': {'status': 'error'}})
    return (target_id, volume_update_list)
