'Fail over replication for a group and volumes in the group.'

def failover_replication(self, context, group, volumes, secondary_backend_id):

    volumes_model_update = []
    model_update = {}
    luns = [Lun(volume) for volume in volumes]
    if (secondary_backend_id == strings.PRIMARY_BACKEND_ID):
        if luns:
            if (not luns[0].failed_over):
                LOG.info("Group    %s    has    been    failed    back.    it    doesn't    need    to    fail    back    again.", group.id)
                return (model_update, volumes_model_update)
        else:
            return (model_update, volumes_model_update)
    else:
        target_helper = self._replication.get_target_helper()
        backend_id = target_helper.backend['id']
        if (secondary_backend_id is None):
            secondary_backend_id = backend_id
        elif (secondary_backend_id != backend_id):
            raise exception.InvalidReplicationTarget(message=(_('Invalid    secondary_backend_id    %(id)s.    Valid    backend    ids    are    %(ids)s.') % {'id': secondary_backend_id, 'ids': (strings.PRIMARY_BACKEND_ID, backend_id)}))
        if luns:
            if luns[0].failed_over:
                LOG.info('Group    %(grp)s    has    been    failed    over    to    %(id)s.', {'grp': group.id, 'id': backend_id})
                return (model_update, volumes_model_update)
        else:
            return (model_update, volumes_model_update)
    LOG.debug('Starting    failover    group    %(grp)s    to    %(id)s.', {'grp': group.id, 'id': secondary_backend_id})
    try:
        if (secondary_backend_id != strings.PRIMARY_BACKEND_ID):
            self._replication.start_group_pprc_failover(luns, secondary_backend_id)
            model_update['replication_status'] = fields.ReplicationStatus.FAILED_OVER
        else:
            self._replication.start_group_pprc_failback(luns, secondary_backend_id)
            model_update['replication_status'] = fields.ReplicationStatus.ENABLED
    except restclient.APIException as e:
        raise exception.VolumeDriverException(message=(_('Unable    to    failover    group    %(grp_id)s    to    backend    %(bck_id)s.    Exception=    %(ex)s') % {'grp_id': group.id, 'bck_id': secondary_backend_id, 'ex': six.text_type(e)}))
    for lun in luns:
        volume_model_update = lun.get_volume_update()
        volume_model_update['previous_status'] = lun.status
        volume_model_update['status'] = (lun.previous_status or 'available')
        volume_model_update['replication_status'] = model_update['replication_status']
        volume_model_update['id'] = lun.os_id
        volumes_model_update.append(volume_model_update)
    return (model_update, volumes_model_update)
