def run_rsync_remote_replication(remote_replication_id):
    fail_audit_str = ''
    try:
        rr, err = remote_replication.get_remote_replications(
            remote_replication_id)
        if err:
            raise Exception('Could not fetch replication details: %s' % err)

        replication = rr[0]
        mode = replication['mode']
	fail_audit_str = 'Replication description: %s\n' % replication['description']
	fail_audit_str += 'Schedule description: %s\n' % replication['schedule_description']
        if mode != 'rsync':
            raise Exception('Invalid replication mode')

        ret, err = remote_replication.run_rsync_remote_replication(
            remote_replication_id)
        if err:
            raise Exception(err)


    except Exception, e:
        audit.audit("task_fail", "Did not initiate replication:\n%s - %s" % (fail_audit_str, e),
                    None, system_initiated=True)
        return False, 'Error adding rsync remote replication task: %s' % e
def run_zfs_remote_replication(remote_replication_id):
    try:
        rr, err = remote_replication.get_remote_replications(
            remote_replication_id)
        if err:
            raise Exception('Could not fetch replication details: %s' % err)
        replication = rr[0]
        mode = replication['mode']
        if mode == 'zfs':
            now_local_epoch, err = datetime_utils.get_epoch(when='now')
            if err:
                raise Exception(err)
            now_local_str, err = datetime_utils.convert_from_epoch(
                now_local_epoch,
                return_format='str',
                str_format='%Y%m%d%H%M',
                to='local')
            if err:
                raise Exception(err)

            source_dataset = replication['zfs'][0]['source_dataset']
            ret, err = zfs.create_snapshot(
                source_dataset,
                'zrr_%s_%s' % (remote_replication_id, now_local_str))
            if err:
                raise Exception(err)
            ret, err = remote_replication.run_zfs_remote_replication(
                remote_replication_id)
            if err:
                raise Exception(err)
        else:
            raise Exception('Invalid remote replication mode')

    except Exception, e:
        return False, 'Error adding ZFS remote replication task : %s' % e
Ejemplo n.º 3
0
def run_rsync_remote_replication(remote_replication_id):
    fail_audit_str = ''
    try:
        rr, err = remote_replication.get_remote_replications(
            remote_replication_id)
        if err:
            raise Exception('Could not fetch replication details: %s' % err)

        replication = rr[0]
        mode = replication['mode']
        fail_audit_str = 'Replication description: %s\n' % replication[
            'description']
        fail_audit_str += 'Schedule description: %s\n' % replication[
            'schedule_description']
        if mode != 'rsync':
            raise Exception('Invalid replication mode')

        ret, err = remote_replication.run_rsync_remote_replication(
            remote_replication_id)
        if err:
            raise Exception(err)

    except Exception, e:
        audit.audit("task_fail",
                    "Did not initiate replication:\n%s - %s" %
                    (fail_audit_str, e),
                    None,
                    system_initiated=True)
        return False, 'Error adding rsync remote replication task: %s' % e
def run_zfs_remote_replication(remote_replication_id):
    try:
        rr, err = remote_replication.get_remote_replications(
            remote_replication_id)
        if err:
            raise Exception('Could not fetch replication details: %s' % err)
        replication = rr[0]
        mode = replication['mode']
        if mode == 'zfs':
            now_local_epoch, err = datetime_utils.get_epoch(when='now')
            if err:
                raise Exception(err)
            now_local_str, err = datetime_utils.convert_from_epoch(
                now_local_epoch, return_format='str', str_format='%Y%m%d%H%M', to='local')
            if err:
                raise Exception(err)

            source_dataset = replication['zfs'][0]['source_dataset']
            ret, err = zfs.create_snapshot(
                source_dataset, 'zrr_%s_%s' % (remote_replication_id, now_local_str))
            if err:
                raise Exception(err)
            ret, err = remote_replication.run_zfs_remote_replication(
                remote_replication_id)
            if err:
                raise Exception(err)
        else:
            raise Exception('Invalid remote replication mode')

    except Exception, e:
        return False, 'Error adding ZFS remote replication task : %s' % e
def update_remote_replication_user_comment(request):
    """Modifies only the user comment, not any other field

    """
    return_dict = {}
    try:

        ret, err = django_utils.get_request_parameter_values(
            request, ['remote_replication_id'])
        if err:
            raise Exception(err)
        if 'remote_replication_id' not in ret:
            raise Exception(
                "Requested remote replication not found, please use the menus.")
        remote_replication_id = ret['remote_replication_id']
        replications, err = remote_replication.get_remote_replications(
            remote_replication_id)
        if err:
            raise Exception(err)
        if not replications:
            raise Exception('Specified replication definition not found')

        if request.method == "GET":
            return_dict['replication'] = replications[0]
            if return_dict['replication']['mode'] == 'rsync':
                rsync_switches = {}
                rsync_switches['long'] = return_dict['replication']['rsync'][0]['long_switches']
                rsync_switches['short'] = return_dict['replication']['rsync'][0]['short_switches']

                return_dict['rsync_switches_description'], err = rsync.form_switches_description(rsync_switches)
                if err:
                    raise Exception('Could not parse rsync switches description: %s' % err)

            return django.shortcuts.render_to_response('update_remote_replication_user_comment.html', return_dict, context_instance=django.template.context.RequestContext(request))
        elif request.method == "POST":
            if ('user_comment') not in request.POST:
                raise Exception("Incomplete request.")
            user_comment = request.POST.get('user_comment')
            description = ''
            description += 'User comment: %s' % user_comment
            description += '\nDescription: %s' % replications[0]['description']

            # update comment
            is_update, err = remote_replication.update_remote_replication_user_comment(
                remote_replication_id, user_comment)
            if err:
                raise Exception(err)

            audit.audit("update_remote_replication_user_comment", description, request)

            return django.http.HttpResponseRedirect('/replication/view_remote_replications?ack=user_comment_updated')

    except Exception as e:
        return_dict['base_template'] = "replication_base.html"
        return_dict["page_title"] = 'Update remote replication user comment'
        return_dict['tab'] = 'view_remote_replications_tab'
        return_dict["error"] = 'Error updating replication comment'
        return_dict["error_details"] = str(e)
        return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def view_remote_replications(request):
    return_dict = {}
    try:
        modes, err = remote_replication.get_replication_modes()
        if err:
            raise Exception(
                'Could not read available replication modes: %s' % err)

        if 'mode' in request.GET:
            mode = str(request.GET['mode'])
            if mode not in modes:
                raise Exception("Malformed request. Please use the menus")
        else:
            mode = modes[0]
        select_mode = mode

        if "ack" in request.GET:
            if request.GET["ack"] == "cancelled":
                return_dict['ack_message'] = 'Selected replication successfully cancelled.'
            elif request.GET["ack"] == "created":
                return_dict['ack_message'] = 'Replication successfully scheduled.'
            elif request.GET["ack"] == "updated":
                return_dict['ack_message'] = 'Selected replication parameters successfully updated.'
            elif request.GET["ack"] == "pause_schedule_updated":
                return_dict['ack_message'] = 'Replication pause schedule successfully updated.'
            elif request.GET["ack"] == "user_comment_updated":
                return_dict['ack_message'] = 'Replication user comment successfully updated.'

        replications, err = remote_replication.get_remote_replications()
        if err:
            raise Exception(err)
        is_zfs = False
        is_rsync = False
        for replication in replications:
            if replication.get('mode') == 'zfs':
                is_zfs = True
            elif replication.get('mode') == 'rsync':
                is_rsync = True

        return_dict["replications"] = replications
        return_dict["modes"] = modes
        return_dict["select_mode"] = select_mode
        return_dict["is_zfs"] = is_zfs
        return_dict["is_rsync"] = is_rsync
        return django.shortcuts.render_to_response('view_remote_replications.html', return_dict, context_instance=django.template.context.RequestContext(request))
    except Exception as e:
        return_dict['base_template'] = "replication_base.html"
        return_dict["page_title"] = 'View Remote Replication'
        return_dict['tab'] = 'view_remote_replications_tab'
        return_dict["error"] = 'Error retrieving replication informat'
        return_dict["error_details"] = str(e)
        return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def delete_remote_replication(request):
    return_dict = {}
    try:
        ret, err = django_utils.get_request_parameter_values(
            request, ['remote_replication_id'])
        if err:
            raise Exception(err)
        if 'remote_replication_id' not in ret:
            raise Exception(
                "Requested remote replication not found, please use the menus."
            )
        remote_replication_id = ret['remote_replication_id']
        return_dict['remote_replication_id'] = remote_replication_id
        replications, err = remote_replication.get_remote_replications(
            remote_replication_id)
        if err:
            raise Exception(err)
        if not replications:
            raise Exception(
                'Specified remote replication definition not found')

        if request.method == "GET":
            return_dict['replication'] = replications[0]
            return django.shortcuts.render_to_response(
                "delete_remote_replication_conf.html",
                return_dict,
                context_instance=django.template.context.RequestContext(
                    request))
        else:
            ret, err = remote_replication.delete_remote_replication(
                remote_replication_id)
            if err:
                raise Exception(err)

            audit.audit("remove_remote_replication",
                        replications[0]['description'], request)
            return django.http.HttpResponseRedirect(
                '/replication/view_remote_replications?ack=cancelled')
    except Exception as e:
        return_dict['base_template'] = "replication_base.html"
        return_dict["page_title"] = 'Remove remote replication'
        return_dict['tab'] = 'view_remote_replications_tab'
        return_dict["error"] = 'Error removing remote replication'
        return_dict["error_details"] = str(e)
        return django.shortcuts.render_to_response(
            "logged_in_error.html",
            return_dict,
            context_instance=django.template.context.RequestContext(request))
def delete_remote_replication(request):
    return_dict = {}
    try:
        ret, err = django_utils.get_request_parameter_values(
            request, ['remote_replication_id'])
        if err:
            raise Exception(err)
        if 'remote_replication_id' not in ret:
            raise Exception(
                "Requested remote replication not found, please use the menus.")
        remote_replication_id = ret['remote_replication_id']
        return_dict['remote_replication_id'] = remote_replication_id
        replications, err = remote_replication.get_remote_replications(
            remote_replication_id)
        if err:
            raise Exception(err)
        if not replications:
            raise Exception(
                'Specified remote replication definition not found')

        if request.method == "GET":
            return_dict['replication'] = replications[0]
            return django.shortcuts.render_to_response("delete_remote_replication_conf.html", return_dict, context_instance=django.template.context.RequestContext(request))
        else:
            ret, err = remote_replication.delete_remote_replication(
                remote_replication_id)
            if err:
                raise Exception(err)

            audit.audit("remove_remote_replication",
                        replications[0]['description'], request)
            return django.http.HttpResponseRedirect('/replication/view_remote_replications?ack=cancelled')
    except Exception as e:
        return_dict['base_template'] = "replication_base.html"
        return_dict["page_title"] = 'Remove remote replication'
        return_dict['tab'] = 'view_remote_replications_tab'
        return_dict["error"] = 'Error removing remote replication'
        return_dict["error_details"] = str(e)
        return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def pause_rsync_remote_replication(remote_replication_id):
    try:
        audit_str = ''
        rr, err = remote_replication.get_remote_replications(
            remote_replication_id)
        if err:
            raise Exception('Could not fetch replication details: %s' % err)

        replication = rr[0]
        mode = replication['mode']
        if mode != 'rsync':
            raise Exception('Invalid replication mode')

        # since the intention is to prevent any further retries as well, check
        # for 'error-retrying' status also.
        running_tasks, err = tasks_utils.get_tasks_by_cron_task_id(
            replication['cron_task_id'],
            get_last_by=False,
            status_list=['running', 'error-retrying'])
        if err:
            raise Exception
        if running_tasks:
            # To prevent re-attempts, mark it 'failed'
            ret, err = tasks_utils.stop_task(running_tasks[0]['task_id'],
                                             mark_failed=True)
            if err:
                raise Exception
            audit_str = "%s has been paused, it will resume at the next run schedule" % running_tasks[
                0]['description']

            audit.audit("stop_background_task",
                        audit_str,
                        None,
                        system_initiated=True)
    except Exception, e:
        return False, 'Error pausing rsync remote replication task: %s' % e
def view_remote_replications(request):
    return_dict = {}
    try:
        modes, err = remote_replication.get_replication_modes()
        if err:
            raise Exception('Could not read available replication modes: %s' %
                            err)

        if 'mode' in request.GET:
            mode = str(request.GET['mode'])
            if mode not in modes:
                raise Exception("Malformed request. Please use the menus")
        else:
            mode = modes[0]
        select_mode = mode

        if "ack" in request.GET:
            if request.GET["ack"] == "cancelled":
                return_dict[
                    'ack_message'] = 'Selected replication successfully cancelled.'
            elif request.GET["ack"] == "created":
                return_dict[
                    'ack_message'] = 'Replication successfully scheduled.'
            elif request.GET["ack"] == "updated":
                return_dict[
                    'ack_message'] = 'Selected replication parameters successfully updated.'
            elif request.GET["ack"] == "pause_schedule_updated":
                return_dict[
                    'ack_message'] = 'Replication pause schedule successfully updated.'
            elif request.GET["ack"] == "user_comment_updated":
                return_dict[
                    'ack_message'] = 'Replication user comment successfully updated.'

        replications, err = remote_replication.get_remote_replications()
        if err:
            raise Exception(err)
        is_zfs = False
        is_rsync = False
        for replication in replications:
            if replication.get('mode') == 'zfs':
                is_zfs = True
            elif replication.get('mode') == 'rsync':
                is_rsync = True

        return_dict["replications"] = replications
        return_dict["modes"] = modes
        return_dict["select_mode"] = select_mode
        return_dict["is_zfs"] = is_zfs
        return_dict["is_rsync"] = is_rsync
        return django.shortcuts.render_to_response(
            'view_remote_replications.html',
            return_dict,
            context_instance=django.template.context.RequestContext(request))
    except Exception as e:
        return_dict['base_template'] = "replication_base.html"
        return_dict["page_title"] = 'View Remote Replication'
        return_dict['tab'] = 'view_remote_replications_tab'
        return_dict["error"] = 'Error retrieving replication informat'
        return_dict["error_details"] = str(e)
        return django.shortcuts.render_to_response(
            "logged_in_error.html",
            return_dict,
            context_instance=django.template.context.RequestContext(request))
def update_rsync_remote_replication_pause_schedule(request):
    """Modifies only the pause schedule, not any other field

    TODO: shorten this ridiculously large name when cleaning up
    """
    return_dict = {}
    try:

        ret, err = django_utils.get_request_parameter_values(
            request, ['remote_replication_id'])
        if err:
            raise Exception(err)
        if 'remote_replication_id' not in ret:
            raise Exception(
                "Requested remote replication not found, please use the menus."
            )
        remote_replication_id = ret['remote_replication_id']
        replications, err = remote_replication.get_remote_replications(
            remote_replication_id)
        if err:
            raise Exception(err)
        if not replications:
            raise Exception('Specified replication definition not found')
        if replications[0]['mode'] != 'rsync':
            raise Exception('Unsupported replication mode')

        if request.method == "GET":
            return_dict['replication'] = replications[0]
            if return_dict['replication']['mode'] == 'rsync':
                rsync_switches = {}
                rsync_switches['long'] = return_dict['replication']['rsync'][
                    0]['long_switches']
                rsync_switches['short'] = return_dict['replication']['rsync'][
                    0]['short_switches']

                return_dict[
                    'rsync_switches_description'], err = rsync.form_switches_description(
                        rsync_switches)
                if err:
                    raise Exception(
                        'Could not parse rsync switches description: %s' % err)

            return django.shortcuts.render_to_response(
                'update_remote_replication_pause_schedule.html',
                return_dict,
                context_instance=django.template.context.RequestContext(
                    request))
        elif request.method == "POST":
            scheduler = None
            schedule = None
            is_disabled = True
            if ('pause_cron_task_id' and 'is_disabled') not in request.POST:
                raise Exception("Incomplete request.")
            is_disabled = request.POST.get('is_disabled')
            if str(is_disabled) == 'False':
                if ('scheduler') not in request.POST:
                    raise Exception("Incomplete request.")
                scheduler = request.POST.get('scheduler')
                schedule = scheduler.split()
            pause_cron_task_id = request.POST.get('pause_cron_task_id')
            description = ''
            description += replications[0]['description']

            # update the schedule of the cron entry in-place
            pause_cron_task_id, err = remote_replication.update_rsync_remote_replication_pause_schedule(
                remote_replication_id, schedule)
            if err:
                raise Exception(err)

            audit_tag = ''
            if schedule:
                crons, err = scheduler_utils.get_cron_tasks(pause_cron_task_id)
                if err:
                    raise Exception(err)
                if 'schedule_description' in crons[0] and crons[0][
                        'schedule_description']:
                    description += '\nSchedule: %s' % crons[0][
                        'schedule_description']
                audit_tag = 'update_rsync_remote_replication_pause_schedule'
            else:
                audit_tag = 'remove_rsync_remote_replication_pause_schedule'

            audit.audit(audit_tag, description, request)
            return django.http.HttpResponseRedirect(
                '/replication/view_remote_replications?ack=pause_schedule_updated'
            )
    except Exception as e:
        return_dict['base_template'] = "replication_base.html"
        return_dict[
            "page_title"] = 'Update rsync remote replication pause schedule'
        return_dict['tab'] = 'view_remote_replications_tab'
        return_dict[
            "error"] = 'Error updating rsync remote replication pause schedule'
        return_dict["error_details"] = str(e)
        return django.shortcuts.render_to_response(
            "logged_in_error.html",
            return_dict,
            context_instance=django.template.context.RequestContext(request))
def update_remote_replication(request):
    """Modifies only the schedule, not any other field

    """
    return_dict = {}
    try:

        ret, err = django_utils.get_request_parameter_values(
            request, ['remote_replication_id'])
        if err:
            raise Exception(err)
        if 'remote_replication_id' not in ret:
            raise Exception(
                "Requested remote replication not found, please use the menus."
            )
        remote_replication_id = ret['remote_replication_id']
        replications, err = remote_replication.get_remote_replications(
            remote_replication_id)
        if err:
            raise Exception(err)
        if not replications:
            raise Exception('Specified replication definition not found')

        if request.method == "GET":
            return_dict['replication'] = replications[0]
            if return_dict['replication']['mode'] == 'rsync':
                rsync_switches = {}
                rsync_switches['long'] = return_dict['replication']['rsync'][
                    0]['long_switches']
                rsync_switches['short'] = return_dict['replication']['rsync'][
                    0]['short_switches']

                return_dict[
                    'rsync_switches_description'], err = rsync.form_switches_description(
                        rsync_switches)
                if err:
                    raise Exception(
                        'Could not parse rsync switches description: %s' % err)

            return django.shortcuts.render_to_response(
                'update_remote_replication.html',
                return_dict,
                context_instance=django.template.context.RequestContext(
                    request))
        elif request.method == "POST":
            if ('scheduler' and 'cron_task_id') not in request.POST:
                raise Exception("Incomplete request.")
            cron_task_id = request.POST.get('cron_task_id')
            scheduler = request.POST.get('scheduler')
            schedule = scheduler.split()
            description = ''
            description += replications[0]['description']

            # update the schedule of the cron entry in-place
            is_update, err = remote_replication.update_remote_replication_schedule(
                remote_replication_id, schedule)
            if err:
                raise Exception(err)

            crons, err = scheduler_utils.get_cron_tasks(cron_task_id)
            if err:
                raise Exception(err)
            description += '\nSchedule: %s' % crons[0]['schedule_description']

            audit.audit("modify_remote_replication", description, request)
            return django.http.HttpResponseRedirect(
                '/replication/view_remote_replications?ack=updated')
    except Exception as e:
        return_dict['base_template'] = "replication_base.html"
        return_dict["page_title"] = 'Configure remote replication'
        return_dict['tab'] = 'view_remote_replications_tab'
        return_dict["error"] = 'Error configuring replication'
        return_dict["error_details"] = str(e)
        return django.shortcuts.render_to_response(
            "logged_in_error.html",
            return_dict,
            context_instance=django.template.context.RequestContext(request))
def update_remote_replication_user_comment(request):
    """Modifies only the user comment, not any other field

    """
    return_dict = {}
    try:

        ret, err = django_utils.get_request_parameter_values(
            request, ['remote_replication_id'])
        if err:
            raise Exception(err)
        if 'remote_replication_id' not in ret:
            raise Exception(
                "Requested remote replication not found, please use the menus."
            )
        remote_replication_id = ret['remote_replication_id']
        replications, err = remote_replication.get_remote_replications(
            remote_replication_id)
        if err:
            raise Exception(err)
        if not replications:
            raise Exception('Specified replication definition not found')

        if request.method == "GET":
            return_dict['replication'] = replications[0]
            if return_dict['replication']['mode'] == 'rsync':
                rsync_switches = {}
                rsync_switches['long'] = return_dict['replication']['rsync'][
                    0]['long_switches']
                rsync_switches['short'] = return_dict['replication']['rsync'][
                    0]['short_switches']

                return_dict[
                    'rsync_switches_description'], err = rsync.form_switches_description(
                        rsync_switches)
                if err:
                    raise Exception(
                        'Could not parse rsync switches description: %s' % err)

            return django.shortcuts.render_to_response(
                'update_remote_replication_user_comment.html',
                return_dict,
                context_instance=django.template.context.RequestContext(
                    request))
        elif request.method == "POST":
            if ('user_comment') not in request.POST:
                raise Exception("Incomplete request.")
            user_comment = request.POST.get('user_comment')
            description = ''
            description += 'User comment: %s' % user_comment
            description += '\nDescription: %s' % replications[0]['description']

            # update comment
            is_update, err = remote_replication.update_remote_replication_user_comment(
                remote_replication_id, user_comment)
            if err:
                raise Exception(err)

            audit.audit("update_remote_replication_user_comment", description,
                        request)

            return django.http.HttpResponseRedirect(
                '/replication/view_remote_replications?ack=user_comment_updated'
            )

    except Exception as e:
        return_dict['base_template'] = "replication_base.html"
        return_dict["page_title"] = 'Update remote replication user comment'
        return_dict['tab'] = 'view_remote_replications_tab'
        return_dict["error"] = 'Error updating replication comment'
        return_dict["error_details"] = str(e)
        return django.shortcuts.render_to_response(
            "logged_in_error.html",
            return_dict,
            context_instance=django.template.context.RequestContext(request))
def update_rsync_remote_replication_pause_schedule(request):
    """Modifies only the pause schedule, not any other field

    TODO: shorten this ridiculously large name when cleaning up
    """
    return_dict = {}
    try:

        ret, err = django_utils.get_request_parameter_values(
            request, ['remote_replication_id'])
        if err:
            raise Exception(err)
        if 'remote_replication_id' not in ret:
            raise Exception(
                "Requested remote replication not found, please use the menus.")
        remote_replication_id = ret['remote_replication_id']
        replications, err = remote_replication.get_remote_replications(
            remote_replication_id)
        if err:
            raise Exception(err)
        if not replications:
            raise Exception('Specified replication definition not found')
        if replications[0]['mode'] != 'rsync':
            raise Exception('Unsupported replication mode')

        if request.method == "GET":
            return_dict['replication'] = replications[0]
            if return_dict['replication']['mode'] == 'rsync':
                rsync_switches = {}
                rsync_switches['long'] = return_dict['replication']['rsync'][0]['long_switches']
                rsync_switches['short'] = return_dict['replication']['rsync'][0]['short_switches']

                return_dict['rsync_switches_description'], err = rsync.form_switches_description(rsync_switches)
                if err:
                    raise Exception('Could not parse rsync switches description: %s' % err)

            return django.shortcuts.render_to_response('update_remote_replication_pause_schedule.html', return_dict, context_instance=django.template.context.RequestContext(request))
        elif request.method == "POST":
            scheduler = None
            schedule = None
            is_disabled = True
            if ('pause_cron_task_id' and 'is_disabled') not in request.POST:
                raise Exception("Incomplete request.")
            is_disabled = request.POST.get('is_disabled')
            if str(is_disabled) == 'False':
                if ('scheduler') not in request.POST:
                    raise Exception("Incomplete request.")
                scheduler = request.POST.get('scheduler')
                schedule = scheduler.split()
            pause_cron_task_id = request.POST.get('pause_cron_task_id')
            description = ''
            description += replications[0]['description']

            # update the schedule of the cron entry in-place
            pause_cron_task_id, err = remote_replication.update_rsync_remote_replication_pause_schedule(
                remote_replication_id, schedule)
            if err:
                raise Exception(err)

            audit_tag = ''
            if schedule:
                crons, err = scheduler_utils.get_cron_tasks(pause_cron_task_id)
                if err:
                    raise Exception(err)
                if 'schedule_description' in crons[0] and crons[0]['schedule_description']:
                    description += '\nSchedule: %s' % crons[0]['schedule_description']
                audit_tag = 'update_rsync_remote_replication_pause_schedule'
            else:
                audit_tag = 'remove_rsync_remote_replication_pause_schedule'

            audit.audit(audit_tag, description, request)
            return django.http.HttpResponseRedirect('/replication/view_remote_replications?ack=pause_schedule_updated')
    except Exception as e:
        return_dict['base_template'] = "replication_base.html"
        return_dict["page_title"] = 'Update rsync remote replication pause schedule'
        return_dict['tab'] = 'view_remote_replications_tab'
        return_dict["error"] = 'Error updating rsync remote replication pause schedule'
        return_dict["error_details"] = str(e)
        return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def update_remote_replication(request):
    """Modifies only the schedule, not any other field

    """
    return_dict = {}
    try:

        ret, err = django_utils.get_request_parameter_values(
            request, ['remote_replication_id'])
        if err:
            raise Exception(err)
        if 'remote_replication_id' not in ret:
            raise Exception(
                "Requested remote replication not found, please use the menus.")
        remote_replication_id = ret['remote_replication_id']
        replications, err = remote_replication.get_remote_replications(
            remote_replication_id)
        if err:
            raise Exception(err)
        if not replications:
            raise Exception('Specified replication definition not found')

        if request.method == "GET":
            return_dict['replication'] = replications[0]
            if return_dict['replication']['mode'] == 'rsync':
                rsync_switches = {}
                rsync_switches['long'] = return_dict['replication']['rsync'][0]['long_switches']
                rsync_switches['short'] = return_dict['replication']['rsync'][0]['short_switches']

                return_dict['rsync_switches_description'], err = rsync.form_switches_description(rsync_switches)
                if err:
                    raise Exception('Could not parse rsync switches description: %s' % err)

            return django.shortcuts.render_to_response('update_remote_replication.html', return_dict, context_instance=django.template.context.RequestContext(request))
        elif request.method == "POST":
            if ('scheduler' and 'cron_task_id') not in request.POST:
                raise Exception("Incomplete request.")
            cron_task_id = request.POST.get('cron_task_id')
            scheduler = request.POST.get('scheduler')
            schedule = scheduler.split()
            description = ''
            description += replications[0]['description']

            # update the schedule of the cron entry in-place
            is_update, err = remote_replication.update_remote_replication_schedule(
                remote_replication_id, schedule)
            if err:
                raise Exception(err)

            crons, err = scheduler_utils.get_cron_tasks(cron_task_id)
            if err:
                raise Exception(err)
            description += '\nSchedule: %s' % crons[0]['schedule_description']

            audit.audit("modify_remote_replication", description, request)
            return django.http.HttpResponseRedirect('/replication/view_remote_replications?ack=updated')
    except Exception as e:
        return_dict['base_template'] = "replication_base.html"
        return_dict["page_title"] = 'Configure remote replication'
        return_dict['tab'] = 'view_remote_replications_tab'
        return_dict["error"] = 'Error configuring replication'
        return_dict["error_details"] = str(e)
        return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))