'Fail over the volume back and forth.
if secondary_id is \'default\', volumes will be failed back,
otherwize failed over.'

@proxy.logger
@proxy._trace_time
def failover_host(self, ctxt, volumes, secondary_id, groups=None):

    volume_update_list = []
    if (secondary_id == strings.PRIMARY_BACKEND_ID):
        if (not self._active_backend_id):
            LOG.info("Host    has    been    failed    back.    doesn't    need    to    fail    back    again.")
            return (self._active_backend_id, volume_update_list, [])
    else:
        if self._active_backend_id:
            LOG.info('Host    has    been    failed    over    to    %s.', self._active_backend_id)
            return (self._active_backend_id, volume_update_list, [])
        target_helper = self._replication.get_target_helper()
        if (secondary_id is None):
            secondary_id = target_helper.backend['id']
        elif (secondary_id != target_helper.backend['id']):
            raise exception.InvalidReplicationTarget(message=(_('Invalid    secondary_backend_id    specified.    Valid    backend    id    is    %s.') % target_helper.backend['id']))
    LOG.debug('Starting    failover    host    to    %s.', secondary_id)
    replicated_luns = [Lun(volume) for volume in volumes if (volume.status in ('available', 'in-use'))]
    if (secondary_id != strings.PRIMARY_BACKEND_ID):
        failover_luns = [lun for lun in replicated_luns if (not lun.failed_over)]
    else:
        failover_luns = [lun for lun in replicated_luns if lun.failed_over]
    if failover_luns:
        try:
            if (secondary_id != strings.PRIMARY_BACKEND_ID):
                self._replication.start_host_pprc_failover(failover_luns, secondary_id)
                self._active_backend_id = secondary_id
            else:
                self._replication.start_host_pprc_failback(failover_luns, secondary_id)
                self._active_backend_id = ''
            self._helper = self._replication.get_source_helper()
        except restclient.APIException as e:
            raise exception.UnableToFailOver(reason=(_('Unable    to    failover    host    to    %(id)s.    Exception=    %(ex)s') % {'id': secondary_id, 'ex': six.text_type(e)}))
        for lun in failover_luns:
            volume_update = lun.get_volume_update()
            volume_update['status'] = (lun.previous_status or 'available')
            volume_update['replication_status'] = (fields.ReplicationStatus.FAILED_OVER if self._active_backend_id else fields.ReplicationStatus.ENABLED)
            model_update = {'volume_id': lun.os_id, 'updates': volume_update}
            volume_update_list.append(model_update)
    else:
        LOG.info('No    volume    has    replication    capability.')
        if (secondary_id != strings.PRIMARY_BACKEND_ID):
            LOG.info('Switch    to    the    target    %s', secondary_id)
            self._replication.switch_source_and_target_client()
            self._active_backend_id = secondary_id
        else:
            LOG.info('Switch    to    the    primary    %s', secondary_id)
            self._replication.switch_source_and_target_client()
            self._active_backend_id = ''
    group_update_list = []
    groups = [grp for grp in groups if (grp.status == 'available')]
    if groups:
        if (secondary_id != strings.PRIMARY_BACKEND_ID):
            update_groups = [grp for grp in groups if (grp.replication_status == fields.ReplicationStatus.ENABLED)]
            repl_status = fields.ReplicationStatus.FAILED_OVER
        else:
            update_groups = [grp for grp in groups if (grp.replication_status == fields.ReplicationStatus.FAILED_OVER)]
            repl_status = fields.ReplicationStatus.ENABLED
        if update_groups:
            for group in update_groups:
                group_update = {'group_id': group.id, 'updates': {'replication_status': repl_status}}
                group_update_list.append(group_update)
    return (secondary_id, volume_update_list, group_update_list)
