def update_scheduled_task_schedule(request):
    return_dict = {}
    try:
        req_ret, err = django_utils.get_request_parameter_values(
            request, ['cron_task_id'])
        if err:
            raise Exception(err)

        if 'cron_task_id' not in req_ret:
            raise Exception("Invalid request, please use the menus.")

        cron_task_id = req_ret['cron_task_id']
        return_dict['cron_task_id'] = cron_task_id

        cron_task_list, err = scheduler_utils.get_cron_tasks(
            cron_task_id=cron_task_id)
        if err:
            raise Exception(err)
        if request.method == "GET":
            # Return the conf page
            return_dict['schedule_description'] = cron_task_list[0][
                'schedule_description'].lower()
            return django.shortcuts.render_to_response(
                "update_scheduled_task_schedule.html",
                return_dict,
                context_instance=django.template.context.RequestContext(
                    request))
        else:
            scheduler = request.POST.get('scheduler')
            schedule = scheduler.split()
            ret, err = scheduler_utils.update_cron_schedule(
                cron_task_id, 'root', schedule[0], schedule[1], schedule[2],
                schedule[3], schedule[4])
            if err:
                raise Exception(err)
            #Get the new entry now..
            cron_task_list, err = scheduler_utils.get_cron_tasks(
                cron_task_id=cron_task_id)
            if err:
                raise Exception(err)
            audit_str = 'Modified the schedule for "%s" to "%s"' % (
                cron_task_list[0]['description'].lower(),
                cron_task_list[0]['schedule_description'].lower())
            audit.audit("update_schedule_task_schedule", audit_str, request)
            return django.http.HttpResponseRedirect(
                '/tasks/view_scheduled_tasks?ack=modified')
    except Exception, e:
        return_dict['base_template'] = "tasks_base.html"
        return_dict["page_title"] = 'Scheduled tasks'
        return_dict['tab'] = 'view_scheduled_tasks_tab'
        return_dict["error"] = 'Error modifying task 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 view_scheduled_tasks(request):
    return_dict = {}
    try:
        if "ack" in request.GET:
            if request.GET["ack"] == "deleted":
                return_dict['ack_message'] = "Scheduled task successfully removed"
            if request.GET["ack"] == "modified":
                return_dict['ack_message'] = "Scheduled task successfully modified"
        tasks, err = scheduler_utils.get_cron_tasks()
        if err:
            raise Exception(err)
        snapshot_schedules, err = zfs.get_all_snapshot_schedules()
        if err:
            raise Exception(err)
        return_dict["snapshot_schedules"] = snapshot_schedules

        return_dict["tasks"] = tasks
        return django.shortcuts.render_to_response("view_scheduled_tasks.html", return_dict, context_instance=django.template.context.RequestContext(request))
    except Exception, e:
        return_dict['base_template'] = "tasks_base.html"
        return_dict["page_title"] = 'Scheduled tasks'
        return_dict['tab'] = 'view_scheduled_tasks_tab'
        return_dict["error"] = 'Error retriving scheduled tasks'
        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_scan_configurations(request):
    return_dict = {}
    try:
        if "ack" in request.GET:
            if request.GET["ack"] == "updated_scan_schedule":
                return_dict['ack_message'] = "Folder scan successfully scheduled"
            elif request.GET["ack"] == "created_scan_configuration":
                return_dict['ack_message'] = "Folder scan configuration successfully created"
            elif request.GET["ack"] == "deleted_scan_schedule":
                return_dict['ack_message'] = "Folder scan schedule successfully removed"
            elif request.GET["ack"] == "deleted_scan_configuration":
                return_dict['ack_message'] = "Folder scan configuration successfully removed"

        configurations, err = scan_utils.get_scan_configurations(standalone=False, include_deleted=True)
        if err:
            raise Exception(err)

        if configurations:
            for c in configurations:
                #print c
                if c['cron_task_id']:
                    ct_list, err = scheduler_utils.get_cron_tasks(cron_task_id=c['cron_task_id'])
                    if err:
                        raise Exception(err)
                    if ct_list:
                        c['schedule_description'] = ct_list[0]['schedule_description']
        return_dict['configurations'] = configurations
        return django.shortcuts.render_to_response('view_scan_configurations.html', return_dict, context_instance=django.template.context.RequestContext(request))
    except Exception, e:
        return_dict['base_template'] = "storage_insights_base.html"
        return_dict["page_title"] = 'View scan configurations'
        return_dict['tab'] = 'scan_configurations_tab'
        return_dict["error"] = 'Error loading Storage Insight scan configurations'
        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))
Esempio n. 4
0
def get_event_notification_trigger(ent_id):
    """Get the trigger entry corresponding to the passed trigger id

    """
    return_dict = None
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        query = 'select * from event_notification_triggers where ent_id=%d' % int(
            ent_id)
        return_dict, err = db.get_single_row(db_path, query)
        if err:
            raise Exception(err)
        if return_dict:
            cron_list, err = scheduler_utils.get_cron_tasks(
                return_dict['cron_task_id'])
            if err:
                raise Exception(err)
            if cron_list:
                return_dict['schedule_description'] = cron_list[0][
                    'schedule_description']
                return_dict['description'] = cron_list[0]['description']
    except Exception, e:
        return None, 'Error retrieving event notification trigger : %s' % str(
            e)
def view_scheduled_tasks(request):
    return_dict = {}
    try:
        if "ack" in request.GET:
            if request.GET["ack"] == "deleted":
                return_dict[
                    'ack_message'] = "Scheduled task successfully removed"
            if request.GET["ack"] == "modified":
                return_dict[
                    'ack_message'] = "Scheduled task successfully modified"
        tasks, err = scheduler_utils.get_cron_tasks()
        if err:
            raise Exception(err)
        snapshot_schedules, err = zfs.get_all_snapshot_schedules()
        if err:
            raise Exception(err)
        return_dict["snapshot_schedules"] = snapshot_schedules

        return_dict["tasks"] = tasks
        return django.shortcuts.render_to_response(
            "view_scheduled_tasks.html",
            return_dict,
            context_instance=django.template.context.RequestContext(request))
    except Exception, e:
        return_dict['base_template'] = "tasks_base.html"
        return_dict["page_title"] = 'Scheduled tasks'
        return_dict['tab'] = 'view_scheduled_tasks_tab'
        return_dict["error"] = 'Error retriving scheduled tasks'
        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_scheduled_task_schedule(request):
    return_dict = {}
    try:
        req_ret, err = django_utils.get_request_parameter_values(request, [
                                                                 'cron_task_id'])
        if err:
            raise Exception(err)

        if 'cron_task_id' not in req_ret:
            raise Exception("Invalid request, please use the menus.")

        cron_task_id = req_ret['cron_task_id']
        return_dict['cron_task_id'] = cron_task_id

        cron_task_list, err = scheduler_utils.get_cron_tasks(cron_task_id=cron_task_id)
        if err:
            raise Exception(err)
        if request.method == "GET":
            # Return the conf page
            return_dict['schedule_description'] = cron_task_list[0]['schedule_description'].lower()
            return django.shortcuts.render_to_response("update_scheduled_task_schedule.html", return_dict, context_instance=django.template.context.RequestContext(request))
        else:
            scheduler = request.POST.get('scheduler')
            schedule = scheduler.split()
            ret, err = scheduler_utils.update_cron_schedule(
                        cron_task_id, 'root', schedule[0], schedule[1], schedule[2], schedule[3], schedule[4])
            if err:
                raise Exception(err)
            #Get the new entry now..
            cron_task_list, err = scheduler_utils.get_cron_tasks(cron_task_id=cron_task_id)
            if err:
                raise Exception(err)
            audit_str = 'Modified the schedule for "%s" to "%s"' % (cron_task_list[0]['description'].lower(), cron_task_list[0]['schedule_description'].lower())
            audit.audit("update_schedule_task_schedule", audit_str, request)
            return django.http.HttpResponseRedirect('/tasks/view_scheduled_tasks?ack=modified')
    except Exception, e:
        return_dict['base_template'] = "tasks_base.html"
        return_dict["page_title"] = 'Scheduled tasks'
        return_dict['tab'] = 'view_scheduled_tasks_tab'
        return_dict["error"] = 'Error modifying task 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_scan_schedule(request):
    return_dict = {}
    try:
        req_ret, err = django_utils.get_request_parameter_values(request, ['scan_configuration_id', 'scheduler'])
        if err:
            raise Exception(err)
        if 'scan_configuration_id' not in req_ret:
            raise Exception('Malformed request. Please use the menus.')
        scan_configuration_id = int(req_ret['scan_configuration_id'])
        if request.method == "GET":
            # Return the conf page
            configurations, err = scan_utils.get_scan_configurations(scan_configuration_id=scan_configuration_id)
            if err:
                raise Exception(err)
            if not configurations:
                raise Exception('Invalid configuration specified. Please us the menus.')

            return_dict['configuration'] = configurations[0]
            return_dict['scan_configuration_id'] = req_ret['scan_configuration_id']
            return django.shortcuts.render_to_response("schedule_scan.html", return_dict, context_instance=django.template.context.RequestContext(request))
        else:
            if 'scheduler' not in req_ret:
                raise Exception("Invalid request, please use the menus.")
            scheduler = req_ret['scheduler']
            schedule = scheduler.split()
            app_root, err = config.get_application_root(app_tag='storage_insights')
            if err:
                raise Exception(err)
            cmd = 'python %s/scripts/python/storage_insights_scanner.py -d -s %d'%(app_root, scan_configuration_id)

            cron_description = 'Storage Insights scanner'
    
            cron_task_id, err = scheduler_utils.create_cron_task(
                cmd, cron_description, schedule[0], schedule[1], schedule[2], schedule[3], schedule[4], task_type_id=6)
            if err:
                raise Exception(err)
            ret, err = scan_utils.update_cron_schedule(scan_configuration_id, cron_task_id)
            if err:
                raise Exception(err)

            cron_task_list, err = scheduler_utils.get_cron_tasks(cron_task_id, task_type_id=6)
            if err:
                raise Exception(err)

            audit_str = "Application Storage Insights scan process scheduled for %s." % cron_task_list[0]['schedule_description'].lower()
            audit.audit("application_action", audit_str, request)
            return django.http.HttpResponseRedirect('/applications/storage_insights/view_scan_configurations?ack=updated_scan_schedule')
    except Exception, e:
        return_dict['base_template'] = "storage_insights_base.html"
        return_dict["page_title"] = 'Schedule folder scan'
        return_dict['tab'] = 'scan_configurations_tab'
        return_dict["error"] = 'Error scheduling Storage Insight folder scan'
        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))
Esempio n. 8
0
def view_scan_configurations(request):
    return_dict = {}
    try:
        if "ack" in request.GET:
            if request.GET["ack"] == "updated_scan_schedule":
                return_dict[
                    'ack_message'] = "Folder scan successfully scheduled"
            elif request.GET["ack"] == "created_scan_configuration":
                return_dict[
                    'ack_message'] = "Folder scan configuration successfully created"
            elif request.GET["ack"] == "deleted_scan_schedule":
                return_dict[
                    'ack_message'] = "Folder scan schedule successfully removed"
            elif request.GET["ack"] == "deleted_scan_configuration":
                return_dict[
                    'ack_message'] = "Folder scan configuration successfully removed"

        configurations, err = scan_utils.get_scan_configurations(
            standalone=False, include_deleted=True)
        if err:
            raise Exception(err)

        if configurations:
            for c in configurations:
                #print c
                if c['cron_task_id']:
                    ct_list, err = scheduler_utils.get_cron_tasks(
                        cron_task_id=c['cron_task_id'])
                    if err:
                        raise Exception(err)
                    if ct_list:
                        c['schedule_description'] = ct_list[0][
                            'schedule_description']
        return_dict['configurations'] = configurations
        return django.shortcuts.render_to_response(
            'view_scan_configurations.html',
            return_dict,
            context_instance=django.template.context.RequestContext(request))
    except Exception, e:
        return_dict['base_template'] = "storage_insights_base.html"
        return_dict["page_title"] = 'View scan configurations'
        return_dict['tab'] = 'scan_configurations_tab'
        return_dict[
            "error"] = 'Error loading Storage Insight scan configurations'
        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 create_event_notification(schedule, event_type_id, event_subtype_id, subsystem_type_id, notification_type_id, severity_type_id, enc_id, reference_table_entries=None):
    """Create an event notification. This involves creating a trigger entry and a cron entry

    """
    audit_str = None
    try:
        psp, err = config.get_python_scripts_path()
        if err:
            raise Exception(err)
        ent_id, err = create_event_notification_trigger(
            event_type_id, event_subtype_id, subsystem_type_id, notification_type_id, severity_type_id, enc_id, -1)
        if err:
            raise Exception(err)
        if event_type_id == 1:
            cmd = 'python %s/process_alert_notifications.py %d' % (
                psp, int(ent_id))
        elif event_type_id == 2:
            cmd = 'python %s/process_audit_notifications.py %d' % (
                psp, int(ent_id))
        elif event_type_id == 3:
            cmd = 'python %s/process_report_notifications.py %d' % (
                psp, int(ent_id))
        description, err = stringify_event_notification(
            event_type_id, notification_type_id, subsystem_type_id, severity_type_id, event_subtype_id, reference_table_entries=reference_table_entries)
        if err:
            delete_event_notification_trigger(ent_id)
            raise Exception(err)
        cron_task_id, err = scheduler_utils.create_cron_task(
            cmd, description, schedule[0], schedule[1], schedule[2], schedule[3], schedule[4], task_type_id=5)
        if err:
            delete_event_notification_trigger(ent_id)
            raise Exception(err)

        ret, err = update_event_notification_trigger_cron_id(
            ent_id, cron_task_id)
        if err:
            delete_event_notification_trigger(ent_id)
            scheduler_utils.delete_cron(cron_task_id)
            raise Exception(err)

        cron_task_list, err = scheduler_utils.get_cron_tasks(cron_task_id)
        if err:
            audit_str = 'Created event notification : %s. Scheduled for <Error while retrieving schedule>' % description
        else:
            audit_str = 'Created event notification : %s. Scheduled for %s' % (
                description, cron_task_list[0]['schedule_description'])
    except Exception, e:
        return None, 'Error creating event notification : %s' % str(e)
def delete_scan_schedule(request):

    return_dict = {}
    try:
        req_ret, err = django_utils.get_request_parameter_values(request, ['scan_configuration_id'])
        if err:
            raise Exception(err)
        if 'scan_configuration_id' not in req_ret:
            raise Exception('Malformed request. Please use the menus.')
        scan_configuration_id = int(req_ret['scan_configuration_id'])
        configurations, err = scan_utils.get_scan_configurations(scan_configuration_id=scan_configuration_id)
        if err:
            raise Exception(err)
        if not configurations:
            raise Exception('Invalid configuration specified. Please us the menus.')
        if not configurations[0]['cron_task_id']:
            raise Exception('The specified configuration is not currently scheduled. Please us the menus.')
        cron_task_id = configurations[0]['cron_task_id']

        cron_task_list, err = scheduler_utils.get_cron_tasks(configurations[0]['cron_task_id'], task_type_id=6)
        if err:
            raise Exception(err)
        return_dict["cron_task"] = cron_task_list[0]
        return_dict["configuration"] = configurations[0]
        return_dict["scan_configuration_id"] = scan_configuration_id

        if request.method == "GET":
            # Return the conf page
            return django.shortcuts.render_to_response("delete_scan_schedule_conf.html", return_dict, context_instance=django.template.context.RequestContext(request))
        else:
            cron_description = cron_task_list[0]['description'].lower()

            ret, err = scheduler_utils.delete_cron(cron_task_id)
            if err:
                raise Exception(err)

            audit_str = "Removed application Storage Insights folder scan scheduled for %s" % (cron_task_list[0]['schedule_description'].lower())
            audit.audit("application_action", audit_str, request)
            return django.http.HttpResponseRedirect('/applications/storage_insights/view_scan_configurations?ack=deleted_scan_schedule')
    except Exception, e:
        return_dict['base_template'] = "storage_insights_base.html"
        return_dict["page_title"] = 'Remove folder scan schedule'
        return_dict['tab'] = 'scan_schedule_tab'
        return_dict["error"] = 'Error removing Storage Insight folder scan 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))
Esempio n. 11
0
def get_event_notification_triggers(event_type_id=None,
                                    event_subtype_id=None,
                                    subsystem_type_id=None,
                                    severity_type_id=None):
    """Get all the trigger entries that match the specified parameters..

    """
    ent_list = None
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        if not event_type_id:
            query = 'select * from event_notification_triggers'
        else:
            # Get all scheduled notifications for this event type and then
            # filter down later..
            query = 'select * from event_notification_triggers where event_type_id=%d' % event_type_id
        ent_list, err = db.get_multiple_rows(db_path, query)
        if err:
            raise Exception(err)
        if ent_list:
            for ent in ent_list:
                # print ent
                if event_subtype_id and ent['event_subtype_id'] != -1:
                    if ent['event_subtype_id'] != event_subtype_id:
                        continue
                if subsystem_type_id and ent['subsystem_type_id'] != -1:
                    if ent['subsystem_type_id'] != subsystem_type_id:
                        continue
                if severity_type_id and ent['severity_type_id'] not in [-1, 0]:
                    if ent['severity_type_id'] != severity_type_id:
                        continue
                # print 'retaining ent - ', ent
                cron_list, err = scheduler_utils.get_cron_tasks(
                    ent['cron_task_id'])
                if err:
                    raise Exception(err)
                if cron_list:
                    ent['schedule_description'] = cron_list[0][
                        'schedule_description']
                    ent['description'] = cron_list[0]['description']
    except Exception, e:
        return None, 'Error retrieving matching event notification configurations : %s' % str(
            e)
def get_event_notification_triggers(event_type_id=None, event_subtype_id=None, subsystem_type_id=None, severity_type_id=None):
    """Get all the trigger entries that match the specified parameters..

    """
    ent_list = None
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        if not event_type_id:
            query = 'select * from event_notification_triggers'
        else:
            # Get all scheduled notifications for this event type and then
            # filter down later..
            query = 'select * from event_notification_triggers where event_type_id=%d' % event_type_id
        ent_list, err = db.get_multiple_rows(db_path, query)
        if err:
            raise Exception(err)
        if ent_list:
            for ent in ent_list:
                # print ent
                if event_subtype_id and ent['event_subtype_id'] != -1:
                    if ent['event_subtype_id'] != event_subtype_id:
                        continue
                if subsystem_type_id and ent['subsystem_type_id'] != -1:
                    if ent['subsystem_type_id'] != subsystem_type_id:
                        continue
                if severity_type_id and ent['severity_type_id'] not in [-1, 0]:
                    if ent['severity_type_id'] != severity_type_id:
                        continue
                # print 'retaining ent - ', ent
                cron_list, err = scheduler_utils.get_cron_tasks(
                    ent['cron_task_id'])
                if err:
                    raise Exception(err)
                if cron_list:
                    ent['schedule_description'] = cron_list[0]['schedule_description']
                    ent['description'] = cron_list[0]['description']
    except Exception, e:
        return None, 'Error retrieving matching event notification configurations : %s' % str(e)
Esempio n. 13
0
def get_task_pgid(task_id):
    """Identify the process group id of this task

    This action is applicable only for remote replication tasks(task_type_id=4)
    """
    pgid = ''
    try:
        pgid_dir_path, err = config.get_tasks_pgid_dir()
        if err:
            raise Exception(err)
        task, err = get_task(task_id)
        if err:
            raise Exception(err)
        cron_task_id = task['cron_task_id']
        task_type_id = task['task_type_id']
        if task_type_id != 4:
            raise Exception("Not a remote replication task")
        cron_entry, err = scheduler_utils.get_cron_tasks(cron_task_id)
        if err:
            raise Exception(err)
        rr_cmd_str = str(cron_entry[0]['command']).strip()

        # extract the remote replication id
        rr_id = rr_cmd_str.split()[1]

        pgid_file_path = '%s/rr.%s.pgid' % (pgid_dir_path, rr_id)
        ret, err = command.get_command_output('cat %s' % pgid_file_path,
                                              shell=True)
        if err:
            raise Exception("Could not identify the process instance")

        if ret and ret[0]:
            pgid = ret[0]
        else:
            raise Exception("Could not identify the process instance")

    except Exception, e:
        return False, 'Error fetching pgid: %s' % e
def get_task_pgid(task_id):
    """Identify the process group id of this task

    This action is applicable only for remote replication tasks(task_type_id=4)
    """
    pgid = ''
    try:
        pgid_dir_path, err = config.get_tasks_pgid_dir()
        if err:
            raise Exception(err)
        task, err = get_task(task_id)
        if err:
            raise Exception(err)
        cron_task_id = task['cron_task_id']
        task_type_id = task['task_type_id']
        if task_type_id != 4:
            raise Exception("Not a remote replication task")
        cron_entry, err = scheduler_utils.get_cron_tasks(cron_task_id)
        if err:
            raise Exception(err)
        rr_cmd_str = str(cron_entry[0]['command']).strip()

        # extract the remote replication id
        rr_id = rr_cmd_str.split()[1]

        pgid_file_path = '%s/rr.%s.pgid' % (pgid_dir_path, rr_id)
        ret, err = command.get_command_output(
            'cat %s' % pgid_file_path, shell=True)
        if err:
            raise Exception("Could not identify the process instance")

        if ret and ret[0]:
            pgid = ret[0]
        else:
            raise Exception("Could not identify the process instance")

    except Exception, e:
        return False, 'Error fetching pgid: %s' % e
def get_event_notification_trigger(ent_id):
    """Get the trigger entry corresponding to the passed trigger id

    """
    return_dict = None
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        query = 'select * from event_notification_triggers where ent_id=%d' % int(
            ent_id)
        return_dict, err = db.get_single_row(db_path, query)
        if err:
            raise Exception(err)
        if return_dict:
            cron_list, err = scheduler_utils.get_cron_tasks(
                return_dict['cron_task_id'])
            if err:
                raise Exception(err)
            if cron_list:
                return_dict['schedule_description'] = cron_list[0]['schedule_description']
                return_dict['description'] = cron_list[0]['description']
    except Exception, e:
        return None, 'Error retrieving event notification trigger : %s' % str(e)
Esempio n. 16
0
def delete_scan_schedule(request):

    return_dict = {}
    try:
        req_ret, err = django_utils.get_request_parameter_values(
            request, ['scan_configuration_id'])
        if err:
            raise Exception(err)
        if 'scan_configuration_id' not in req_ret:
            raise Exception('Malformed request. Please use the menus.')
        scan_configuration_id = int(req_ret['scan_configuration_id'])
        configurations, err = scan_utils.get_scan_configurations(
            scan_configuration_id=scan_configuration_id)
        if err:
            raise Exception(err)
        if not configurations:
            raise Exception(
                'Invalid configuration specified. Please us the menus.')
        if not configurations[0]['cron_task_id']:
            raise Exception(
                'The specified configuration is not currently scheduled. Please us the menus.'
            )
        cron_task_id = configurations[0]['cron_task_id']

        cron_task_list, err = scheduler_utils.get_cron_tasks(
            configurations[0]['cron_task_id'], task_type_id=6)
        if err:
            raise Exception(err)
        return_dict["cron_task"] = cron_task_list[0]
        return_dict["configuration"] = configurations[0]
        return_dict["scan_configuration_id"] = scan_configuration_id

        if request.method == "GET":
            # Return the conf page
            return django.shortcuts.render_to_response(
                "delete_scan_schedule_conf.html",
                return_dict,
                context_instance=django.template.context.RequestContext(
                    request))
        else:
            cron_description = cron_task_list[0]['description'].lower()

            ret, err = scheduler_utils.delete_cron(cron_task_id)
            if err:
                raise Exception(err)

            audit_str = "Removed application Storage Insights folder scan scheduled for %s" % (
                cron_task_list[0]['schedule_description'].lower())
            audit.audit("application_action", audit_str, request)
            return django.http.HttpResponseRedirect(
                '/applications/storage_insights/view_scan_configurations?ack=deleted_scan_schedule'
            )
    except Exception, e:
        return_dict['base_template'] = "storage_insights_base.html"
        return_dict["page_title"] = 'Remove folder scan schedule'
        return_dict['tab'] = 'scan_schedule_tab'
        return_dict[
            "error"] = 'Error removing Storage Insight folder scan 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 _create_rsync_remote_replication(request, cleaned_data):
    """Schedule rsync remote replication

    - call add_remote_replication() which adds the remote replication
      entry to the remote_replications table, the appropriate rsync 
      mode specific replication table:rsync_replications and adds the
      python script as a crontab entry that runs rsync replication.
    """
    try:
        if (not request) or (not cleaned_data):
            raise Exception('Insufficient parameters')

        cd = cleaned_data
        source_path = None
        target_path = None
        target_ip = cd['target_ip']
        target_user_name = "replicator"
        switches_formed = {}
        switches_formed['short'] = ''
        switches_formed['long'] = ''
        switches = {}
        description = ''
        is_between_integralstor = False
        is_one_shot = False

        if 'is_between_integralstor' in cd and cd['is_between_integralstor'] == True:
            is_between_integralstor = True
        if 'is_one_shot' in cd and cd['is_one_shot'] == True:
            is_one_shot = True
            description = 'one time '


        rsync_type = cd['rsync_type']
        if rsync_type == 'push':
            source_path = cd['local_path']
            target_path = cd['remote_path']
        elif rsync_type == 'pull':
            source_path = cd['remote_path']
            target_path = cd['local_path']
        elif rsync_type == 'local':
            source_path = cd['local_path']
            target_path = cd['remote_path']
            #target_user_name = None
            # since this replication is local to the box, go in as root
            # instead of going in as 'replicator'. This variable
            # becomes a dummy later anyway for 'local' related checks,
            # so, does not matter.
            target_user_name = "root"

        scheduler = request.POST.get('scheduler')
        schedule = scheduler.split()

        # argument value of switches that can take an argument is a
        # separate input element; not part of switches. So, update
        # switches dictionary to contain the argument value as well.
        if 'switches' in cd and cd['switches']:
            for switch in cd['switches']:
                s = ast.literal_eval(switch)
                for k, v in s.items():
                    if v['is_arg']:
                        v['arg_value'] = cd['%s_arg' % v['id']]
                switches.update(s)
        if switches:
            # pass the switches dictionary to form the switch part of
            # the rsync command as a string. Two strings will be
            # returned as a dictionary: long,short
            switches_formed, err = rsync.form_switches_command(
                switches)
            if err:
                raise Exception(
                    'Could not form rsync switch: %s' % err)

        existing_repl, err = remote_replication.get_remote_replications_with(
            'rsync', {'source_path': source_path, 'target_ip': target_ip, 'target_path': target_path})
        if err:
            raise Exception(err)
        if existing_repl:
            raise Exception(
                "A replication schedule already exists with matching entries/options.")

        if rsync_type == 'pull':
            description = '%srsync replication of %s from %s to %s on local host' % (
                description, source_path, target_ip, target_path)
        elif rsync_type == 'push':
            description = '%srsync replication of %s from local host to %s on %s' % (
                description, source_path, target_path, target_ip)
        elif rsync_type == 'local':
            description = '%srsync replication of %s from local host to %s on local host' % (
                description, source_path, target_path)

        # add_remote_replication() will add the remote replication
        # entry to the remote_replications table, the appropriate rsync
        # mode specific replication table:rsync_replications and add the
        # python script as a crontab entry that runs rsync replication.

        ids, err = remote_replication.add_remote_replication('rsync', {'rsync_type': rsync_type, 'short_switches': switches_formed['short'], 'long_switches': switches_formed[
                                                             'long'], 'source_path': source_path, 'target_path': target_path, 'target_ip': target_ip, 'is_one_shot': is_one_shot, 'is_between_integralstor': is_between_integralstor, 'target_user_name': target_user_name, 'description': description, 'schedule': schedule})
        if err:
            raise Exception(err)

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

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

    except Exception as e:
        return False, 'Failed creating/scheduling rsync replication: %s' % e
    else:
        return True, None
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_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_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 _create_rsync_remote_replication(request, cleaned_data):
    """Schedule rsync remote replication

    - call add_remote_replication() which adds the remote replication
      entry to the remote_replications table, the appropriate rsync 
      mode specific replication table:rsync_replications and adds the
      python script as a crontab entry that runs rsync replication.
    """
    try:
        if (not request) or (not cleaned_data):
            raise Exception('Insufficient parameters')

        cd = cleaned_data
        source_path = None
        target_path = None
        target_ip = cd['target_ip']
        target_user_name = "replicator"
        switches_formed = {}
        switches_formed['short'] = ''
        switches_formed['long'] = ''
        switches = {}
        description = ''
        is_between_integralstor = False
        is_one_shot = False

        if 'is_between_integralstor' in cd and cd[
                'is_between_integralstor'] == True:
            is_between_integralstor = True
        if 'is_one_shot' in cd and cd['is_one_shot'] == True:
            is_one_shot = True
            description = 'one time '

        rsync_type = cd['rsync_type']
        if rsync_type == 'push':
            source_path = cd['local_path']
            target_path = cd['remote_path']
        elif rsync_type == 'pull':
            source_path = cd['remote_path']
            target_path = cd['local_path']
        elif rsync_type == 'local':
            source_path = cd['local_path']
            target_path = cd['remote_path']
            #target_user_name = None
            # since this replication is local to the box, go in as root
            # instead of going in as 'replicator'. This variable
            # becomes a dummy later anyway for 'local' related checks,
            # so, does not matter.
            target_user_name = "root"

        scheduler = request.POST.get('scheduler')
        schedule = scheduler.split()

        # argument value of switches that can take an argument is a
        # separate input element; not part of switches. So, update
        # switches dictionary to contain the argument value as well.
        if 'switches' in cd and cd['switches']:
            for switch in cd['switches']:
                s = ast.literal_eval(switch)
                for k, v in s.items():
                    if v['is_arg']:
                        v['arg_value'] = cd['%s_arg' % v['id']]
                switches.update(s)
        if switches:
            # pass the switches dictionary to form the switch part of
            # the rsync command as a string. Two strings will be
            # returned as a dictionary: long,short
            switches_formed, err = rsync.form_switches_command(switches)
            if err:
                raise Exception('Could not form rsync switch: %s' % err)

        existing_repl, err = remote_replication.get_remote_replications_with(
            'rsync', {
                'source_path': source_path,
                'target_ip': target_ip,
                'target_path': target_path
            })
        if err:
            raise Exception(err)
        if existing_repl:
            raise Exception(
                "A replication schedule already exists with matching entries/options."
            )

        if rsync_type == 'pull':
            description = '%srsync replication of %s from %s to %s on local host' % (
                description, source_path, target_ip, target_path)
        elif rsync_type == 'push':
            description = '%srsync replication of %s from local host to %s on %s' % (
                description, source_path, target_path, target_ip)
        elif rsync_type == 'local':
            description = '%srsync replication of %s from local host to %s on local host' % (
                description, source_path, target_path)

        # add_remote_replication() will add the remote replication
        # entry to the remote_replications table, the appropriate rsync
        # mode specific replication table:rsync_replications and add the
        # python script as a crontab entry that runs rsync replication.

        ids, err = remote_replication.add_remote_replication(
            'rsync', {
                'rsync_type': rsync_type,
                'short_switches': switches_formed['short'],
                'long_switches': switches_formed['long'],
                'source_path': source_path,
                'target_path': target_path,
                'target_ip': target_ip,
                'is_one_shot': is_one_shot,
                'is_between_integralstor': is_between_integralstor,
                'target_user_name': target_user_name,
                'description': description,
                'schedule': schedule
            })
        if err:
            raise Exception(err)

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

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

    except Exception as e:
        return False, 'Failed creating/scheduling rsync replication: %s' % e
    else:
        return True, None
def _create_zfs_remote_replication(request, cleaned_data):
    """Schedule ZFS remote replication

    - call add_remote_replication() which adds the remote replication
      entry to the remote_replications table, the appropriate zfs 
      mode specific replication table:zfs_replications and adds the
      python script as a crontab entry that runs ZFS replication.
    """
    try:
        if (not request) or (not cleaned_data):
            raise Exception('Insufficient parameters')

        cd = cleaned_data
        source_dataset = cd['source_dataset']
        scheduler = request.POST.get('scheduler')
        schedule = scheduler.split()
        target_ip = cd['target_ip']
        target_pool = cd['target_pool']
        target_user_name = "replicator"
        is_one_shot = False
        description = ''

        if (not target_ip) or (not target_pool) or (not source_dataset):
            raise Exception("Incomplete request.")
        if 'is_one_shot' in cd and cd['is_one_shot'] == True:
            is_one_shot = True
            description = 'one time '

        existing_repl, err = remote_replication.get_remote_replications_with(
            'zfs', {
                'source_dataset': source_dataset,
                'target_ip': target_ip,
                'target_pool': target_pool
            })
        if err:
            raise Exception(err)
        if existing_repl:
            raise Exception(
                "A replication schedule already exists with matching entries/options."
            )

        description = '%sZFS replication of %s to pool %s on machine %s' % (
            description, source_dataset, target_pool, target_ip)

        # add_remote_replication() will add the remote replication
        # entry to the remote_replications table, the appropriate ZFS
        # mode specific replication table:zfs_replications and add the
        # python script as a crontab entry that runs ZFS replication.
        ids, err = remote_replication.add_remote_replication(
            'zfs', {
                'source_dataset': source_dataset,
                'target_ip': target_ip,
                'target_user_name': target_user_name,
                'target_pool': target_pool,
                'schedule': schedule,
                'description': description,
                'is_one_shot': is_one_shot
            })
        if err:
            raise Exception(err)

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

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

    except Exception as e:
        return False, 'Failed creating/scheduling ZFS replication: %s' % e
    else:
        return True, None
Esempio n. 24
0
def update_scan_schedule(request):
    return_dict = {}
    try:
        req_ret, err = django_utils.get_request_parameter_values(
            request, ['scan_configuration_id', 'scheduler'])
        if err:
            raise Exception(err)
        if 'scan_configuration_id' not in req_ret:
            raise Exception('Malformed request. Please use the menus.')
        scan_configuration_id = int(req_ret['scan_configuration_id'])
        if request.method == "GET":
            # Return the conf page
            configurations, err = scan_utils.get_scan_configurations(
                scan_configuration_id=scan_configuration_id)
            if err:
                raise Exception(err)
            if not configurations:
                raise Exception(
                    'Invalid configuration specified. Please us the menus.')

            return_dict['configuration'] = configurations[0]
            return_dict['scan_configuration_id'] = req_ret[
                'scan_configuration_id']
            return django.shortcuts.render_to_response(
                "schedule_scan.html",
                return_dict,
                context_instance=django.template.context.RequestContext(
                    request))
        else:
            if 'scheduler' not in req_ret:
                raise Exception("Invalid request, please use the menus.")
            scheduler = req_ret['scheduler']
            schedule = scheduler.split()
            app_root, err = config.get_application_root(
                app_tag='storage_insights')
            if err:
                raise Exception(err)
            cmd = 'python %s/scripts/python/storage_insights_scanner.py -d -s %d' % (
                app_root, scan_configuration_id)

            cron_description = 'Storage Insights scanner'

            cron_task_id, err = scheduler_utils.create_cron_task(
                cmd,
                cron_description,
                schedule[0],
                schedule[1],
                schedule[2],
                schedule[3],
                schedule[4],
                task_type_id=6)
            if err:
                raise Exception(err)
            ret, err = scan_utils.update_cron_schedule(scan_configuration_id,
                                                       cron_task_id)
            if err:
                raise Exception(err)

            cron_task_list, err = scheduler_utils.get_cron_tasks(
                cron_task_id, task_type_id=6)
            if err:
                raise Exception(err)

            audit_str = "Application Storage Insights scan process scheduled for %s." % cron_task_list[
                0]['schedule_description'].lower()
            audit.audit("application_action", audit_str, request)
            return django.http.HttpResponseRedirect(
                '/applications/storage_insights/view_scan_configurations?ack=updated_scan_schedule'
            )
    except Exception, e:
        return_dict['base_template'] = "storage_insights_base.html"
        return_dict["page_title"] = 'Schedule folder scan'
        return_dict['tab'] = 'scan_configurations_tab'
        return_dict["error"] = 'Error scheduling Storage Insight folder scan'
        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 _create_zfs_remote_replication(request, cleaned_data):
    """Schedule ZFS remote replication

    - call add_remote_replication() which adds the remote replication
      entry to the remote_replications table, the appropriate zfs 
      mode specific replication table:zfs_replications and adds the
      python script as a crontab entry that runs ZFS replication.
    """
    try:
        if (not request) or (not cleaned_data):
            raise Exception('Insufficient parameters')

        cd = cleaned_data
        source_dataset = cd['source_dataset']
        scheduler = request.POST.get('scheduler')
        schedule = scheduler.split()
        target_ip = cd['target_ip']
        target_pool = cd['target_pool']
        target_user_name = "replicator"
        is_one_shot = False
        description = ''

        if (not target_ip) or (not target_pool) or (not source_dataset):
            raise Exception("Incomplete request.")
        if 'is_one_shot' in cd and cd['is_one_shot'] == True:
            is_one_shot = True
            description = 'one time '

        existing_repl, err = remote_replication.get_remote_replications_with(
            'zfs', {'source_dataset': source_dataset, 'target_ip': target_ip, 'target_pool': target_pool})
        if err:
            raise Exception(err)
        if existing_repl:
            raise Exception(
                "A replication schedule already exists with matching entries/options.")

        description = '%sZFS replication of %s to pool %s on machine %s' % (
            description, source_dataset, target_pool, target_ip)

        # add_remote_replication() will add the remote replication
        # entry to the remote_replications table, the appropriate ZFS
        # mode specific replication table:zfs_replications and add the
        # python script as a crontab entry that runs ZFS replication.
        ids, err = remote_replication.add_remote_replication(
            'zfs', {'source_dataset': source_dataset, 'target_ip': target_ip, 'target_user_name': target_user_name, 'target_pool': target_pool, 'schedule': schedule, 'description': description, 'is_one_shot':is_one_shot})
        if err:
            raise Exception(err)

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

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

    except Exception as e:
        return False, 'Failed creating/scheduling ZFS replication: %s' % e
    else:
        return True, None