Example #1
0
def delete_background_task(request):
    return_dict = {}
    try:
        req_ret, err = django_utils.get_request_parameter_values(
            request, ['task_id'])
        if err:
            raise Exception(err)
        if 'task_id' not in req_ret:
            raise Exception('Invalid request. Please use the menus.')

        task, err = scheduler_utils.get_task(req_ret['task_id'])
        if err:
            raise Exception(err)

        ret, err = scheduler_utils.delete_task(req_ret['task_id'])
        if err:
            raise Exception(err)

        audit.audit("remove_background_task", task['description'], request)
        return django.http.HttpResponseRedirect(
            '/view_background_tasks?ack=deleted')
    except Exception, e:
        return_dict['base_template'] = "scheduler_base.html"
        return_dict["page_title"] = 'Background tasks'
        return_dict['tab'] = 'view_background_tasks_tab'
        return_dict["error"] = 'Error removing background task'
        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))
Example #2
0
def create_ftp_user_dirs(request):
    return_dict = {}
    try:
        config, err = vsftp.get_ftp_config()
        if err:
            raise Exception(err)
        if 'dataset' not in config:
            raise Exception(
                'No home dataset has been configured for the FTP service. Please do that before creating FTP home directories'
            )
        users, err = local_users.get_local_users()
        if err:
            raise Exception(err)
        res, err = vsftp.create_ftp_user_dirs(config['dataset'], users)
        if err:
            raise Exception(err)

        audit.audit("create_ftp_dir", 'Created FTP user directories', request)
        return django.http.HttpResponseRedirect(
            '/view_ftp_configuration?ack=dirs_created')

    except Exception, e:
        return_dict['base_template'] = "services_base.html"
        return_dict["page_title"] = 'Create FTP user directories'
        return_dict['tab'] = 'ftp_service_settings'
        return_dict["error"] = 'Error creating FTP user directories '
        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 add_iscsi_acl(request):
    return_dict = {}
    try:
        if 'target_name' not in request.REQUEST:
            raise Exception(
                "Malformed request. No target specified. Please use the menus."
            )

        target_name = request.REQUEST['target_name']
        target, err = iscsi_stgt.get_target(target_name)
        if err:
            raise Exception(err)
        if not target:
            raise Exception('Specified target not found')

        if request.method == "GET":
            # Return the form
            initial = {}
            initial['target_name'] = target_name
            form = iscsi_stgt_forms.IscsiAclForm(initial=initial)
            return_dict["form"] = form
            return django.shortcuts.render_to_response(
                "add_iscsi_acl.html",
                return_dict,
                context_instance=django.template.context.RequestContext(
                    request))
        else:
            # Form submission so create
            return_dict = {}
            form = iscsi_stgt_forms.IscsiAclForm(request.POST)
            if form.is_valid():
                cd = form.cleaned_data
                ret, err = iscsi_stgt.add_acl(cd['target_name'], cd['acl'])
                if not ret:
                    if err:
                        raise Exception(err)
                    else:
                        raise Exception("Unknown error.")
                audit_str = "Added ISCSI ACL %s for target %s" % (
                    cd["acl"], cd['target_name'])
                url = '/view_iscsi_target?name=%s&ack=added_acl' % target_name
                audit.audit("add_iscsi_acl", audit_str, request)
                return django.http.HttpResponseRedirect(url)
            else:
                return_dict["form"] = form
                return django.shortcuts.render_to_response(
                    "add_iscsi_acl.html",
                    return_dict,
                    context_instance=django.template.context.RequestContext(
                        request))
    except Exception, e:
        return_dict['base_template'] = "shares_and_targets_base.html"
        return_dict["page_title"] = 'Add ISCSI ACL'
        return_dict['tab'] = 'view_iscsi_targets_tab'
        return_dict["error"] = 'Error adding ISCSI ACL'
        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))
Example #4
0
def delete_remote_monitoring_server(request):
    return_dict = {}
    try:
        req_ret, err = django_utils.get_request_parameter_values(request, [
            'view', 'ip'])
        if err:
            raise Exception(err)
        if 'ip' not in req_ret:
            raise Exception('Invalid request, please use the menus.')
        ip = req_ret['ip']
        servers, err = remote_monitoring.get_servers()
        if err:
            raise Exception(err)
        if ip not in servers.keys():
            raise Exception(
                'Specified server is currently not being remote monitored.')
        name = servers[ip]['name']
        ret, err = remote_monitoring.delete_server(ip)
        if err:
            raise Exception(err)
        audit_str = 'Removed the remote monitoring server with IP : %s name : %s' % (
            ip, name)
        audit.audit("delete_remote_monitoring_server", audit_str, request)
        return django.http.HttpResponseRedirect('/view_remote_monitoring_servers?ack=deleted')

    except Exception, e:
        return_dict["page_title"] = 'Remove remote server monitoring server'
        return_dict['tab'] = 'remote_monitoring_tab'
        return_dict["error"] = 'Error removing remote monitoring server'
        return_dict['base_template'] = "dashboard_base.html"
        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))
Example #5
0
def delete_nfs_share(request):

    return_dict = {}
    try:
        if request.method == "GET":
            # Return the conf page
            path = request.GET["path"]
            return_dict["path"] = path
            return django.shortcuts.render_to_response("delete_nfs_share_conf.html", return_dict, context_instance=django.template.context.RequestContext(request))
        else:
            path = request.POST["path"]
            #logger.debug("Delete share request for name %s"%name)
            result, err = nfs.delete_share(path)
            if err:
                raise Exception(err)

            audit_str = "Deleted NFS share %s" % path
            audit.audit("delete_nfs_share", audit_str, request)
            return django.http.HttpResponseRedirect('/view_nfs_shares?ack=deleted')
    except Exception, e:
        return_dict['base_template'] = "shares_base.html"
        return_dict["page_title"] = 'Remove NFS share '
        return_dict['tab'] = 'view_nfs_shares_tab'
        return_dict["error"] = 'Error removing NFS share'
        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))
Example #6
0
def delete_ssl_certificate(request):

    return_dict = {}
    try:
        ret, err = django_utils.get_request_parameter_values(request, ['name'])
        if err:
            raise Exception(err)
        if 'name' not in ret:
            raise Exception("Invalid request, please use the menus.")
        name = ret['name']
        return_dict["name"] = name

        if request.method == "GET":
            # Return the conf page
            return django.shortcuts.render_to_response("delete_ssl_certificate_conf.html", return_dict, context_instance=django.template.context.RequestContext(request))
        else:

            ret, err = pki.delete_ssl_certificate(name)
            if err:
                raise Exception(err)

            audit_str = "Deleted SSL certificate name '%s'" % name
            audit.audit("delete_certificate", audit_str,
                        request)
            return django.http.HttpResponseRedirect('/view_ssl_certificates?ack=deleted')
    except Exception, e:
        return_dict['base_template'] = "key_management_base.html"
        return_dict["page_title"] = 'Delete a SSL certificate'
        return_dict['tab'] = 'certificates_tab'
        return_dict["error"] = 'Error deleting SSL certificate'
        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_rsync_share(request):
    return_dict = {}
    try:
        if request.method == "GET":
            name = request.GET.get("name")
            return_dict["name"] = name
            return django.shortcuts.render_to_response(
                "delete_rsync_share.html",
                return_dict,
                context_instance=django.template.context.RequestContext(
                    request))
        else:
            name = request.POST.get("name")
            delshare, err = rsync.delete_rsync_share(name)
            if err:
                raise Exception(err)
            audit_str = "Deleted RSYNC share %s" % name
            audit.audit("delete_rsync_share", audit_str, request)
            return django.http.HttpResponseRedirect(
                "/view_rsync_shares/?ack=deleted")
    except Exception, e:
        return_dict['base_template'] = "shares_base.html"
        return_dict["page_title"] = 'RSync shares'
        return_dict['tab'] = 'view_rsync_shares_tab'
        return_dict["error"] = 'Error deleting RSync share'
        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))
Example #8
0
def upload_ssl_certificate(request):
    return_dict = {}
    try:
        if request.method == "GET":
            # Return the conf page
            form = pki_forms.UploadCertForm()
            return_dict['form'] = form
            return django.shortcuts.render_to_response("upload_ssl_certificate.html", return_dict, context_instance=django.template.context.RequestContext(request))
        else:
            form = pki_forms.UploadCertForm(request.POST)
            return_dict['form'] = form
            if not form.is_valid():
                return django.shortcuts.render_to_response("upload_ssl_certificate.html", return_dict, context_instance=django.template.context.RequestContext(request))
            cd = form.cleaned_data
            ret, err = pki.upload_ssl_certificate(cd)
            if err:
                raise Exception(err)

            audit_str = "Uploaded a SSL certificate named %s" % cd['name']
            audit.audit("upload_certificate", audit_str,
                        request.META)
            return django.http.HttpResponseRedirect('/view_ssl_certificates?ack=uploaded_cert')
    except Exception, e:
        return_dict['base_template'] = "key_management_base.html"
        return_dict["page_title"] = 'Upload a SSL certificate'
        return_dict['tab'] = 'certificates_tab'
        return_dict["error"] = 'Error uploading a SSL certificate'
        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_zfs_replication_conf.html",
                return_dict,
                context_instance=django.template.context.RequestContext(
                    request))
        else:
            ret, err = django_utils.get_request_parameter_values(
                request, ['cron_task_id'])
            if err:
                raise Exception(err)
            if 'cron_task_id' not in ret:
                raise Exception("Request not found, please use the menus.")
            cron_task_id = ret['cron_task_id']

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

            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(
                '/view_remote_replications?ack=cancelled')
    except Exception as e:
        return_dict['base_template'] = "snapshot_replication_base.html"
        return_dict["page_title"] = 'Cancel ZFS replication'
        return_dict['tab'] = 'view_remote_replications_tab'
        return_dict["error"] = 'Error cancelling ZFS 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))
Example #10
0
def update_admin_password(request):
    """ Used to change a user's password for the management utility"""

    try:
        return_dict = {}

        if request.user and request.user.is_authenticated():
            if request.method == 'POST':
                iv_logging.debug("Admin password change posted")
                # user has submitted the password info
                form = admin_forms.ChangeAdminPasswordForm(request.POST)
                if form.is_valid():
                    cd = form.cleaned_data
                    oldPasswd = cd['oldPasswd']
                    newPasswd1 = cd['newPasswd1']
                    newPasswd2 = cd['newPasswd2']
                    # Checking for old password is done in the form itself
                    if request.user.check_password(oldPasswd):
                        if newPasswd1 == newPasswd2:
                            # all systems go so now change password
                            request.user.set_password(newPasswd1)
                            request.user.save()
                            return_dict[
                                'ack_message'] = 'Password changed sucessful.'
                            iv_logging.info(
                                "Admin password change request successful.")
                            audit_str = "Changed admin password"
                            audit.audit("modify_admin_password", audit_str,
                                        request)
                        else:
                            return_dict['error'] = 'New passwords do not match'
                # else invalid form or error so existing form data to return_dict and
                # fall through to redisplay the form
                if 'success' not in return_dict:
                    return_dict['form'] = form
                    iv_logging.info("Admin password change request failed.")
            else:
                form = admin_forms.ChangeAdminPasswordForm()
                return_dict['form'] = form

            return django.shortcuts.render_to_response(
                'update_admin_password_form.html',
                return_dict,
                context_instance=django.template.context.RequestContext(
                    request))
        else:
            # User not authenticated so return a login screen
            return django.http.HttpResponseRedirect('/login/')
    except Exception, e:
        return_dict['base_template'] = "admin_base.html"
        return_dict["page_title"] = 'Change admininistrator password'
        return_dict['tab'] = 'change_admin_pswd_tab'
        return_dict["error"] = 'Error changing administrator password'
        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 change_admin_password(request):
    """ Used to change a user's password for the management utility"""

    try:
        return_dict = {}

        if request.user and request.user.is_authenticated():
            if "ack" in request.GET:
                if request.GET["ack"] == "modified":
                    return_dict['ack_message'] = "Password successfully modified."
                elif request.GET["ack"] == "bad_password":
                    return_dict['ack_message'] = "Invalid current password. Please try again."
                elif request.GET["ack"] == "passwd_mismatch":
                    return_dict['ack_message'] = "The new passwords do not match. Please try again."
            if request.method == 'GET':
                form = admin_forms.ChangeAdminPasswordForm()
                return_dict['form'] = form
                return django.shortcuts.render_to_response('change_admin_password_form.html', return_dict, context_instance=django.template.context.RequestContext(request))
            else:
                #iv_logging.debug("Admin password change posted")
                # user has submitted the password info
                form = admin_forms.ChangeAdminPasswordForm(request.POST)
                if form.is_valid():
                    print 'valid'
                    cd = form.cleaned_data
                    oldPasswd = cd['oldPasswd']
                    newPasswd1 = cd['newPasswd1']
                    # Checking for old password is done in the form itself
                    if request.user.check_password(oldPasswd):
                        if cd['newPasswd1'] != cd['newPasswd2']:
                            return django.http.HttpResponseRedirect('/change_admin_password?ack=passwd_mismatch')
                        # all systems go so now change password
                        request.user.set_password(newPasswd1)
                        request.user.save()
                        #iv_logging.info("Admin password change request successful.")
                        audit_str = "Changed admin password"
                        audit.audit("modify_admin_password",
                                    audit_str, request)
                        return django.http.HttpResponseRedirect('/change_admin_password?ack=modified')
                    else:
                        # Invalid old password
                        return django.http.HttpResponseRedirect('/change_admin_password?ack=bad_password')
                else:
                    # invalid form
                    return_dict['form'] = form
                    return django.shortcuts.render_to_response('change_admin_password_form.html', return_dict, context_instance=django.template.context.RequestContext(request))
        else:
            # User not authenticated so return a login screen
            return django.http.HttpResponseRedirect('/login/')
    except Exception, e:
        return_dict['base_template'] = "admin_base.html"
        return_dict["page_title"] = 'Change admininistrator password'
        return_dict['tab'] = 'admin_change_pass_tab'
        return_dict["error"] = 'Error changing administrator password'
        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_iscsi_user_authentication(request):
    return_dict = {}
    try:
        req_ret, err = django_utils.get_request_parameter_values(
            request, ['target_name', 'authentication_type', 'username'])
        if err:
            raise Exception(err)
        if ('target_name' and 'authentication_type'
                and 'username') not in req_ret:
            raise Exception("Invalid request, please use the menus.")

        authentication_type = req_ret['authentication_type']
        target_name = req_ret['target_name']
        username = req_ret['username']

        if authentication_type not in ['incoming', 'outgoing']:
            raise Exception("Invalid user type. Please use the menus.")

        if request.method == "GET":
            return_dict["target_name"] = target_name
            return_dict["username"] = username
            return_dict["authentication_type"] = authentication_type
            return django.shortcuts.render_to_response(
                "delete_iscsi_user_auth_conf.html",
                return_dict,
                context_instance=django.template.context.RequestContext(
                    request))
        else:
            ret, err = iscsi_stgt.remove_user_authentication(
                target_name, username, authentication_type)
            if not ret:
                if err:
                    raise Exception(err)
                else:
                    raise Exception("Unknown error.")
            if authentication_type == 'incoming':
                audit_str = "Removed ISCSI initiator authentication user %s for target %s" % (
                    username, target_name)
                url = '/view_iscsi_target?name=%s&ack=removed_initiator_authentication' % target_name
            else:
                audit_str = "Removed ISCSI target authentication user %s for target %s" % (
                    username, target_name)
                url = '/view_iscsi_target?name=%s&ack=removed_target_authentication' % target_name
            audit.audit("remove_iscsi_target_authentication", audit_str,
                        request)
            return django.http.HttpResponseRedirect(url)
    except Exception, e:
        return_dict['base_template'] = "shares_base.html"
        return_dict["page_title"] = 'Remove ISCSI authentication user'
        return_dict['tab'] = 'view_iscsi_targets_tab'
        return_dict["error"] = 'Error removing ISCSI authentication user'
        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))
Example #13
0
def update_nfs_share(request):
    return_dict = {}
    try:
        if request.method == "GET":
            # Return the conf page
            path = request.GET["path"]
            d, err = nfs.get_share(path)
            if err:
                raise Exception(err)
            if not d:
                raise Exception(
                    'Could not find the specified share. Please use the menus.')
            initial = {}
            initial['path'] = d['path']
            if 'clients' in d:
                client_list = []
                for client in d['clients']:
                    client_list.append(client['name'])
                initial['clients'] = ','.join(client_list)
            initial['readonly'] = False
            initial['root_squash'] = False
            initial['all_squash'] = False
            if 'options' in d:
                for option in d['options']:
                    if option == 'ro':
                        initial['readonly'] = True
                    elif option == 'root_squash':
                        initial['root_squash'] = True
                    elif option == 'all_squash':
                        initial['all_squash'] = True
            form = nfs_shares_forms.ShareForm(initial=initial)
            return_dict['form'] = form
            return django.shortcuts.render_to_response("update_nfs_share.html", return_dict, context_instance=django.template.context.RequestContext(request))
        else:
            form = nfs_shares_forms.ShareForm(request.POST)
            path = request.POST["path"]
            return_dict['form'] = form
            if not form.is_valid():
                return django.shortcuts.render_to_response("update_nfs_share.html", return_dict, context_instance=django.template.context.RequestContext(request))
            cd = form.cleaned_data
            result, err = nfs.save_share(cd)
            if err:
                raise Exception(err)

            audit_str = "Edited NFS share %s" % path
            audit.audit("edit_nfs_share", audit_str, request)
            return django.http.HttpResponseRedirect('/view_nfs_shares?ack=saved')
    except Exception, e:
        return_dict['base_template'] = "shares_base.html"
        return_dict["page_title"] = 'Modify a NFS share '
        return_dict['tab'] = 'view_nfs_shares_tab'
        return_dict["error"] = 'Error modifying a NFS share'
        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))
Example #14
0
def upload_ssh_host_key(request):
    return_dict = {}
    try:
        user = request.GET.get('user', 'replicator')
        return_dict["selected_user"] = user

        if request.method == 'POST':
            authorized_key = request.POST.get('authorized_key', None)
            # This is a delete operation. authorized_key in post is delete and
            # as a file is file upload
            if authorized_key:
                user = request.POST.get("selected_user")
                key = request.POST.get("authorized_key")
                description = "%s" % (user)
                audit.audit("remove_ssh_host_key", description, request)

                files = open((pki._get_known_hosts(user)), 'r').readlines()
                authorized_keys = open(pki._get_known_hosts(user), 'w')
                for file in files:
                    if key.strip() != file.strip():
                        authorized_keys.write(file)
                ack_message = "host_deleted"
            else:
                authorized_key = request.FILES.get('pub_key')
                ip = request.POST.get('ip')
                user = request.POST.get('user', 'replicator')
                description = "%s %s  %s" % (user, ip, authorized_key)
                audit.audit("upload_ssh_host_key", description, request)

                hosts_file = pki._get_known_hosts(user)
                # print hosts_file
                with open("/tmp/hosts_file", 'wb+') as destination:
                    for chunk in authorized_key.chunks():
                        destination.write(chunk)
                with open("/tmp/hosts_file", 'r') as key:
                    data = key.read()
                # print data
                with open(hosts_file, 'ab') as key:
                    key.write(ip + " " + data)
                perm, err = pki.update_ssh_dir_permissions(user)
                if err:
                    raise Exception(err)
                ack_message = "host_added"
            return django.http.HttpResponseRedirect("/view_known_hosts_ssh_keys/?ack=%s&user=%s" % (ack_message, user))
        elif request.method == 'GET':
            return django.shortcuts.render_to_response("upload_ssh_host_key.html", return_dict, context_instance=django.template.context.RequestContext(request))
    except Exception, e:
        return_dict['base_template'] = "key_management_base.html"
        return_dict["page_title"] = 'Upload a Host Key'
        return_dict['tab'] = 'host_ssh_keys_tab'
        return_dict["error"] = 'Error adding host key. Please check the value'
        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_service_status(request):
    return_dict = {}
    try:
        if request.method == "GET":
            raise Exception("Invalid request. Please use the menus")
        if 'service' not in request.POST:
            raise Exception("Invalid request. Please use the menus")
        if 'action' not in request.POST or request.POST['action'] not in [
                'start', 'stop', 'restart', 'enable', 'disable'
        ]:
            raise Exception("Invalid request. Please use the menus")

        service = request.POST['service']
        action = request.POST['action']

        if 'action' == 'start' and service == 'vsftpd':
            # Need to make sure that all local users have their directories
            # created so do it..
            config, err = vsftp.get_ftp_config()
            if err:
                raise Exception(err)
            users, err = local_users.get_local_users()
            if err:
                raise Exception(err)
            ret, err = create_ftp_user_dirs(config['dataset'], users)
            if err:
                raise Exception(err)

        audit_str = "Service status change of %s initiated to %s state." % (
            service, action)
        audit.audit("change_service_status", audit_str, request)

        out, err = services_management.update_service_status(service, action)
        if err:
            raise Exception(err)

        if out:
            return django.http.HttpResponseRedirect(
                '/view_services?&service_change_status=%s' % ','.join(out))
        else:
            return django.http.HttpResponseRedirect(
                '/view_services?service_change_status=none')

    except Exception, e:
        return_dict['base_template'] = "services_base.html"
        return_dict["page_title"] = 'Modify system service state'
        return_dict['tab'] = 'view_services_tab'
        return_dict["error"] = 'Error modifying system services state'
        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))
Example #16
0
def delete_local_group(request):
    return_dict = {}
    try:
        req_ret, err = django_utils.get_request_parameter_values(
            request, ['grpname'])
        if err:
            raise Exception(err)
        if 'grpname' not in req_ret:
            raise Exception('Invalid request, please use the menus.')

        gd, err = local_users.get_local_group(req_ret['grpname'])
        if err or (not gd):
            if err:
                raise Exception(err)
            else:
                raise Exception("Could not retrieve group information")

        if gd['members']:
            raise Exception(
                "Cannot delete this group as it has the following members : %s"
                % (','.join(gd['members'])))

        if request.method == "GET":
            # Return the form
            return_dict["grpname"] = request.GET["grpname"]
            return django.shortcuts.render_to_response(
                "delete_local_group_conf.html",
                return_dict,
                context_instance=django.template.context.RequestContext(
                    request))
        else:
            # Form submission so create
            return_dict = {}
            ret, err = local_users.delete_local_group(request.POST["grpname"])
            if not ret:
                if err:
                    raise Exception('Error deleting group : %s' % err)
                else:
                    raise Exception('Error deleting group')
            audit_str = "Deleted a local group %s" % request.POST["grpname"]
            audit.audit("delete_local_group", audit_str, request)
            url = '/view_local_groups?ack=deleted'
            return django.http.HttpResponseRedirect(url)
    except Exception, e:
        return_dict['base_template'] = 'users_groups_base.html'
        return_dict["page_title"] = 'Delete a local user group'
        return_dict['tab'] = 'view_local_groups_tab'
        return_dict["error"] = 'Error deleting a local user group'
        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))
Example #17
0
def delete_local_user(request):

    return_dict = {}
    try:
        if "userid" not in request.REQUEST:
            return_dict["error"] = "Invalid request. No user name specified."
            return django.shortcuts.render_to_response(
                'logged_in_error.html',
                return_dict,
                context_instance=django.template.context.RequestContext(
                    request))

        if request.method == "GET":
            # Return the form
            return_dict["userid"] = request.GET["userid"]
            return django.shortcuts.render_to_response(
                "delete_local_user_conf.html",
                return_dict,
                context_instance=django.template.context.RequestContext(
                    request))
        else:
            # Form submission so create
            return_dict = {}
            try:
                ret = local_users.delete_local_user(request.POST["userid"])
                audit_str = "Deleted a local user %s" % request.POST["userid"]
                audit.audit("delete_local_user", audit_str,
                            request.META["REMOTE_ADDR"])
                url = '/view_local_users?action=deleted'
                if ret:
                    warnings = ','.join(ret)
                    url = "%s&warnings=%s" % (url, warnings)
                return django.http.HttpResponseRedirect(url)
            except Exception, e:
                return_dict["error"] = "Error deleting the local user - %s" % e
                return django.shortcuts.render_to_response(
                    'logged_in_error.html',
                    return_dict,
                    context_instance=django.template.context.RequestContext(
                        request))
    except Exception, e:
        s = str(e)
        if "Another transaction is in progress".lower() in s.lower():
            return_dict[
                "error"] = "An underlying storage operation has locked a volume so we are unable to process this request. Please try after a couple of seconds"
        else:
            return_dict[
                "error"] = "An error occurred when processing your request : %s" % s
        return django.shortcuts.render_to_response(
            "logged_in_error.html",
            return_dict,
            context_instance=django.template.context.RequestContext(request))
Example #18
0
def update_remote_monitoring_server(request):
    return_dict = {}
    try:
        if request.method == "GET":
            servers, err = remote_monitoring.get_servers()
            if err:
                raise Exception(err)
            req_ret, err = django_utils.get_request_parameter_values(request, [
                'view', 'ip'])
            if err:
                raise Exception(err)
            initial = {}
            if 'ip' in req_ret:
                ip = req_ret['ip']
                if ip in servers.keys():
                    initial['ip'] = ip
                    initial['name'] = servers[ip]['name']
                return_dict['action'] = 'update'
            else:
                return_dict['action'] = 'create'
            form = system_forms.RemoteMonitoringServerForm(initial=initial)
            return_dict['form'] = form
            return django.shortcuts.render_to_response("update_remote_monitoring_server.html", return_dict, context_instance=django.template.context.RequestContext(request))
        else:
            form = system_forms.RemoteMonitoringServerForm(request.POST)
            return_dict["form"] = form
            if form.is_valid():
                cd = form.cleaned_data
                res, err = remote_monitoring.update_server(
                    cd['ip'], cd['name'])
                if not res:
                    if err:
                        raise Exception(err)
                    else:
                        raise Exception(
                            'Error updating remote monitoring server list')
                audit_str = 'Updated the remote monitoring server with IP : %s and name : %s' % (
                    cd['ip'], cd['name'])
                audit.audit("update_remote_monitoring_server",
                            audit_str, request)
                return django.http.HttpResponseRedirect('/view_remote_monitoring_servers?ack=updated')
            else:
                # invalid form
                return django.shortcuts.render_to_response("update_remote_monitoring_server.html", return_dict, context_instance=django.template.context.RequestContext(request))
    except Exception, e:
        return_dict["page_title"] = 'Update remote server monitoring server'
        return_dict['tab'] = 'remote_monitoring_tab'
        return_dict["error"] = 'Error updating remote monitoring server'
        return_dict['base_template'] = "dashboard_base.html"
        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_dns_nameservers(request):

    return_dict = {}
    try:
        ns_list, err = networking.get_name_servers()
        if err:
            raise Exception(err)
        if request.method == "GET":
            if not ns_list:
                form = networking_forms.DNSNameServersForm()
            else:
                form = networking_forms.DNSNameServersForm(
                    initial={'nameservers': ','.join(ns_list)})
            url = "update_dns_nameservers.html"
        else:
            form = networking_forms.DNSNameServersForm(request.POST)
            if form.is_valid():
                cd = form.cleaned_data
                nameservers = cd["nameservers"]
                if ',' in nameservers:
                    slist = nameservers.split(',')
                else:
                    slist = nameservers.split(' ')
                res, err = networking.update_name_servers(slist)
                if not res:
                    if err:
                        raise Exception(err)
                    else:
                        raise Exception('Error updating nameservers')
                audit_str = "Updated the DNS nameserver list to %s" % nameservers
                audit.audit("set_dns_nameservers", audit_str, request)
                return django.http.HttpResponseRedirect(
                    '/view_dns_nameservers?ack=saved')
            else:
                # invalid form
                url = "update_dns_nameservers.html"
        return_dict["form"] = form
        return django.shortcuts.render_to_response(
            url,
            return_dict,
            context_instance=django.template.context.RequestContext(request))
    except Exception, e:
        return_dict['base_template'] = "networking_base.html"
        return_dict["page_title"] = 'Modify DNS servers'
        return_dict['tab'] = 'view_dns_nameservers_tab'
        return_dict["error"] = 'Error modifying DNS servers'
        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))
Example #20
0
def create_local_group(request):
    return_dict = {}
    try:
        if request.method == "GET":
            # Return the form
            form = local_user_forms.LocalGroupForm()
            return_dict["form"] = form
            return django.shortcuts.render_to_response(
                "create_local_group.html",
                return_dict,
                context_instance=django.template.context.RequestContext(
                    request))
        else:
            # Form submission so create
            return_dict = {}
            # print '1'
            form = local_user_forms.LocalGroupForm(request.POST)
            if form.is_valid():
                # print '2'
                cd = form.cleaned_data
                ret, err = local_users.create_local_group(cd["grpname"])
                # print '3'
                if not ret:
                    if err:
                        raise Exception(err)
                    else:
                        raise Exception("Error creating the local group.")
                audit_str = "Created a local group %s" % cd["grpname"]
                audit.audit("create_local_group", audit_str, request)
                #url = '/view_local_groups?ack=created'
                url = '/update_group_membership?grpname=%s&ack=created' % cd[
                    'grpname']
                return django.http.HttpResponseRedirect(url)
            else:
                return_dict["form"] = form
                return django.shortcuts.render_to_response(
                    "create_local_group.html",
                    return_dict,
                    context_instance=django.template.context.RequestContext(
                        request))
    except Exception, e:
        return_dict['base_template'] = 'users_groups_base.html'
        return_dict["page_title"] = 'Create a local user group'
        return_dict['tab'] = 'view_local_groups_tab'
        return_dict["error"] = 'Error create a local user group'
        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 internal_audit(request):
    response = django.http.HttpResponse()
    if request.method == "GET":
        response.write("Error!")
    else:
        if not "who" in request.POST or request.POST["who"] != "batch":
            response.write("Unknown requester")
            return response
        if (not "audit_action" in request.POST) or (not "audit_str" in request.POST):
            response.write("Insufficient information!")
        else:
            audit.audit(request.POST["audit_action"],
                        request.POST["audit_str"], request)
        response.write("Success")
    return response
Example #22
0
def iscsi_delete_target(request):

    return_dict = {}
    try:
        if 'id' not in request.REQUEST:
            raise Exception('Target ID not specified. Please use the menus')
        id = request.REQUEST["id"]
        if request.method == "GET":
            # Return the conf page
            return_dict["id"] = id
            return django.shortcuts.render_to_response("delete_iscsi_target_conf.html", return_dict, context_instance=django.template.context.RequestContext(request))
        else:
            ret, err = iscsi.delete_target(int(id))
            if err:
                raise Exception(err)
            if not ret:
                raise Exception("Error deleting ISCSI target")
            audit_str = "Deleted ISCSI target %s" % id
            ret, err = audit.audit("delete_iscsi_target",
                                   audit_str, request)
            if err:
                raise Exception(err)
            return django.http.HttpResponseRedirect('/iscsi_display_targets?action=deleted')
    except Exception, e:
        s = str(e)
        if "Another transaction is in progress".lower() in s.lower():
            return_dict["error"] = "An underlying storage operation has locked a volume so we are unable to process this request. Please try after a couple of seconds"
        else:
            return_dict["error"] = "An error occurred when processing your request : %s" % s
        return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
Example #23
0
def internal_audit(request):
    response = django.http.HttpResponse()
    if request.method == "GET":
        response.write("Error!")
    else:
        if not "who" in request.POST or request.POST["who"] != "batch":
            response.write("Unknown requester")
            return response
        if (not "audit_action" in request.POST) or (not "audit_str"
                                                    in request.POST):
            response.write("Insufficient information!")
        else:
            audit.audit(request.POST["audit_action"],
                        request.POST["audit_str"], request)
        response.write("Success")
    return response
def change_local_user_password(request):

    return_dict = {}
    try:
        return_dict['base_template'] = "users_base.html"
        return_dict["page_title"] = 'Change local user password'
        return_dict['tab'] = 'local_user_tab'
        return_dict["error"] = 'Error changing local user password'
        if request.method == "GET":
            # Return the form
            if "userid" not in request.GET:
                raise Exception("Invalid request. No user name specified.")
            d = {}
            d["userid"] = request.GET["userid"]
            form = local_user_forms.PasswordChangeForm(initial=d)
            return_dict["form"] = form
            return django.shortcuts.render_to_response(
                "change_local_user_password.html",
                return_dict,
                context_instance=django.template.context.RequestContext(
                    request))
        else:
            # Form submission so create
            return_dict = {}
            form = local_user_forms.PasswordChangeForm(request.POST)
            if form.is_valid():
                cd = form.cleaned_data
                ret, err = local_users.change_password(cd["userid"],
                                                       cd["password"])
                if err:
                    raise Exception(err)
                if not ret:
                    raise Exception('Error changing local user password')

                audit_str = "Changed password for local user %s" % cd["userid"]
                ret, err = audit.audit("change_local_user_password", audit_str,
                                       request)
                if err:
                    raise Exception(err)
                return django.http.HttpResponseRedirect(
                    '/view_local_users?ack=changed_password')
            else:
                return_dict["form"] = form
                return django.shortcuts.render_to_response(
                    "change_local_user_password.html",
                    return_dict,
                    context_instance=django.template.context.RequestContext(
                        request))
    except Exception, e:
        s = str(e)
        if "Another transaction is in progress".lower() in s.lower():
            return_dict[
                "error_details"] = "An underlying storage operation has locked a volume so we are unable to process this request. Please try after a couple of seconds"
        else:
            return_dict[
                "error_details"] = "An error occurred when processing your request : %s" % s
        return django.shortcuts.render_to_response(
            "logged_in_error.html",
            return_dict,
            context_instance=django.template.context.RequestContext(request))
def delete_iscsi_lun(request):
    return_dict = {}
    try:
        if 'target_name' not in request.REQUEST:
            raise Exception(
                "Malformed request. No target specified. Please use the menus."
            )
        if 'store' not in request.REQUEST:
            raise Exception(
                "Malformed request. No LUN specified. Please use the menus.")

        store = request.REQUEST['store']
        target_name = request.REQUEST['target_name']
        print store, target_name

        if request.method == "GET":
            return_dict["target_name"] = target_name
            return_dict["store"] = store
            return django.shortcuts.render_to_response(
                "delete_iscsi_lun_conf.html",
                return_dict,
                context_instance=django.template.context.RequestContext(
                    request))
        else:
            ret, err = iscsi_stgt.delete_lun(target_name, store)
            if not ret:
                if err:
                    raise Exception(err)
                else:
                    raise Exception("Unknown error.")
            audit_str = "Deleted ISCSI LUN %s from target %s" % (store,
                                                                 target_name)
            cmd = 'zfs destroy frzpool/%s' % (store.split("/")[-1])
            ret, err = command.execute_with_rc(cmd=cmd, shell=True)
            url = '/view_iscsi_target?name=%s&ack=lun_deleted' % target_name
            audit.audit("delete_iscsi_lun", audit_str, request)
            return django.http.HttpResponseRedirect(url)
    except Exception, e:
        return_dict['base_template'] = "shares_and_targets_base.html"
        return_dict["page_title"] = 'Remove an ISCSI LUN'
        return_dict['tab'] = 'view_iscsi_targets_tab'
        return_dict["error"] = 'Error removing an ISCSI LUN'
        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))
Example #26
0
def iscsi_edit_initiator(request):

    return_dict = {}
    try:
        if "id" not in request.REQUEST:
            raise Exception("Unknown initiator specified")

        id = int(request.REQUEST["id"])

        if request.method == "GET":
            # Shd be an edit request
            initiator, err = iscsi.load_initiator_info(int(id))
            if err:
                raise Exception(err)
            if not initiator:
                raise Exception("Specified initiator not found")

            # Set initial form values
            initial = {}
            initial["id"] = initiator["id"]
            initial["initiators"] = initiator["initiators"]
            initial["auth_network"] = initiator["auth_network"]
            initial["comment"] = initiator["comment"]

            form = iscsi_forms.InitiatorForm(initial=initial)

            return_dict["form"] = form
            return django.shortcuts.render_to_response('edit_iscsi_initiator.html', return_dict, context_instance=django.template.context.RequestContext(request))

        else:

            # Shd be an save request
            form = iscsi_forms.InitiatorForm(request.POST)
            if form.is_valid():
                cd = form.cleaned_data
                ret, err = iscsi.save_initiator(id, cd)
                if err:
                    raise Exception(err)
                if not ret:
                    raise Exception('Could not save initiator information')

                audit_str = "Modified initiator %s" % id
                ret, err = audit.audit(
                    "modify_initiator", audit_str, request)
                if err:
                    raise Exception(err)
                return django.http.HttpResponseRedirect('/iscsi_view_initiator?access_mode=by_id&id=%s&action=saved' % id)
            else:
                # Invalid form
                form.initial = form.data
                return_dict["form"] = form
                return django.shortcuts.render_to_response('edit_iscsi_initiator.html', return_dict, context_instance=django.template.context.RequestContext(request))
    except Exception, e:
        s = str(e)
        if "Another transaction is in progress".lower() in s.lower():
            return_dict["error"] = "An underlying storage operation has locked a volume so we are unable to process this request. Please try after a couple of seconds"
        else:
            return_dict["error"] = "An error occurred when processing your request : %s" % s
        return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def iscsi_create_auth_access_user(request):

    return_dict = {}
    try:
        if request.method == "GET":
            # Return the form
            if 'auth_access_group_id' not in request.GET:
                raise Exception('No group ID provided. Please use the menus')
            auth_access_group_id = int(request.GET["auth_access_group_id"])
            init = {}
            init["auth_access_group_id"] = auth_access_group_id
            form = iscsi_forms.AuthorizedAccessUserForm(initial=init)
            return_dict["form"] = form
            return django.shortcuts.render_to_response(
                "create_iscsi_auth_access_group.html",
                return_dict,
                context_instance=django.template.context.RequestContext(
                    request))
        else:
            # Form submission so create
            return_dict = {}
            form = iscsi_forms.AuthorizedAccessUserForm(request.POST)
            return_dict["form"] = form
            if form.is_valid():
                cd = form.cleaned_data
                ret, err = iscsi.create_auth_access_user(
                    cd["auth_access_group_id"], cd["user"], cd["secret"])
                if err:
                    raise Exception(err)
                if not ret:
                    raise Exception('Error creating authorized access user')

                audit_str = "Created an ISCSI authorized access user in group %s" % cd[
                    "auth_access_group_id"]
                ret, err = audit.audit("create_iscsi_auth_access_group",
                                       audit_str, request)
                if err:
                    raise Exception(err)
                return django.http.HttpResponseRedirect(
                    '/iscsi_display_auth_access_group_list?action=user_created'
                )
            else:
                return django.shortcuts.render_to_response(
                    "create_iscsi_auth_access_user.html",
                    return_dict,
                    context_instance=django.template.context.RequestContext(
                        request))
    except Exception, e:
        s = str(e)
        if "Another transaction is in progress".lower() in s.lower():
            return_dict[
                "error"] = "An underlying storage operation has locked a volume so we are unable to process this request. Please try after a couple of seconds"
        else:
            return_dict[
                "error"] = "An error occurred when processing your request : %s" % s
        return django.shortcuts.render_to_response(
            "logged_in_error.html",
            return_dict,
            context_instance=django.template.context.RequestContext(request))
def update_interface_state(request):

    return_dict = {}
    try:
        req_ret, err = django_utils.get_request_parameter_values(
            request, ['name', 'state'])
        if err:
            raise Exception(err)
        if ('name' and 'state') not in req_ret:
            raise Exception('Invalid request, please use the menus')

        name = req_ret['name']
        return_dict["name"] = name
        state = req_ret['state']
        return_dict["state"] = state

        if request.method == "GET" and state == 'down':
            # Return the conf page
            return django.shortcuts.render_to_response(
                "update_interface_state_conf.html",
                return_dict,
                context_instance=django.template.context.RequestContext(
                    request))
        else:
            result, err = networking.update_interface_state(name, state)
            if not result:
                if err:
                    raise Exception(err)
                else:
                    raise Exception("Error setting interface state")

            audit_str = "Set the state of network interface %s to %s" % (name,
                                                                         state)
            audit.audit("set_interface_state", audit_str, request)
            return django.http.HttpResponseRedirect(
                '/view_interfaces?ack=state_%s' % state)
    except Exception, e:
        return_dict['base_template'] = "networking_base.html"
        return_dict["page_title"] = 'Set interface state'
        return_dict['tab'] = 'view_interfaces_tab'
        return_dict["error"] = 'Error setting interface state'
        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))
Example #29
0
def change_local_user_password(request):

    return_dict = {}
    try:
        if request.method == "GET":
            # Return the form
            if "userid" not in request.GET:
                return_dict[
                    "error"] = "Invalid request. No user name specified."
                return django.shortcuts.render_to_response(
                    'logged_in_error.html',
                    return_dict,
                    context_instance=django.template.context.RequestContext(
                        request))
            d = {}
            d["userid"] = request.GET["userid"]
            form = samba_shares_forms.PasswordChangeForm(initial=d)
            return_dict["form"] = form
            return django.shortcuts.render_to_response(
                "change_local_user_password.html",
                return_dict,
                context_instance=django.template.context.RequestContext(
                    request))
        else:
            # Form submission so create
            return_dict = {}
            form = samba_shares_forms.PasswordChangeForm(request.POST)
            if form.is_valid():
                cd = form.cleaned_data
                try:
                    local_users.change_password(cd["userid"], cd["password"])
                except Exception, e:
                    return_dict[
                        "error"] = "Error creating the local user - %s" % e
                    return django.shortcuts.render_to_response(
                        'logged_in_error.html',
                        return_dict,
                        context_instance=django.template.context.
                        RequestContext(request))

                audit_str = "Changed password for local user %s" % cd["userid"]
                audit.audit("change_local_user_password", audit_str,
                            request.META["REMOTE_ADDR"])
                return django.http.HttpResponseRedirect(
                    '/view_local_users?action=changed_password')
            else:
Example #30
0
def upload_ssh_user_key(request):
    return_dict = {}
    try:
        user = request.GET.get('user', 'replicator')
        return_dict["selected_user"] = user
        if request.method == 'POST':
            # This works for user deleting the key files. This should be moved
            # to a new function in itself
            authorized_key = request.POST.get('authorized_key', None)
            if authorized_key:
                description = ""
                user = request.POST.get("selected_user")
                key = request.POST.get("authorized_key")
                description = "%s" % (user)
                audit.audit("remove_ssh_user_key", description, request)
                files = open((pki._get_authorized_file(user)), 'r').readlines()
                authorized_keys = open(pki._get_authorized_file(user), 'w')
                for file in files:
                    if key.strip() != file.strip():
                        authorized_keys.write(file)
                ack_message = "key_deleted"
            # This works for user uploading new keys
            else:
                desscription = ""
                authorized_key = request.FILES.get('pub_key')
                user = request.POST.get('user')
                description = "%s  %s" % (user, authorized_key)
                audit.audit("upload_ssh_user_key", description, request)

                with open('/%s/authorized_keys' % (pki._get_ssh_dir(user)), 'ab') as destination:
                    for chunk in authorized_key.chunks():
                        destination.write(chunk)
                perm, err = pki.update_ssh_dir_permissions(user)
                if err:
                    raise Exception(err)
                ack_message = "key_added"
            return django.http.HttpResponseRedirect("/view_user_ssh_keys/?ack=%s&user=%s" % (ack_message, user))
        elif request.method == 'GET':
            return django.shortcuts.render_to_response("upload_ssh_user_key.html", return_dict, context_instance=django.template.context.RequestContext(request))
    except Exception, e:
        return_dict['base_template'] = "key_management_base.html"
        return_dict["page_title"] = 'Upload a Public Key'
        return_dict['tab'] = 'upload_public_key_tab'
        return_dict["error"] = 'Error adding Public key. Please check the value'
        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))
Example #31
0
def delete_share(request):

    return_dict = {}
    try:
        if request.method == "GET":
            # Return the conf page
            share_id = request.GET["share_id"]
            name = request.GET["name"]
            return_dict["share_id"] = share_id
            return_dict["name"] = name
            return django.shortcuts.render_to_response(
                "delete_share_conf.html",
                return_dict,
                context_instance=django.template.context.RequestContext(
                    request))
        else:
            share_id = request.POST["share_id"]
            name = request.POST["name"]
            #logger.debug("Delete share request for name %s"%name)
            try:
                samba_settings.delete_share(share_id)
                samba_settings.generate_smb_conf()
            except Exception, e:
                return_dict["error"] = "Error deleting share - %s" % e
                return django.shortcuts.render_to_response(
                    'logged_in_error.html',
                    return_dict,
                    context_instance=django.template.context.RequestContext(
                        request))

            audit_str = "Deleted Samba share %s" % name
            audit.audit("delete_share", audit_str, request.META["REMOTE_ADDR"])
            return django.http.HttpResponseRedirect(
                '/display_shares?action=deleted')
    except Exception, e:
        s = str(e)
        if "Another transaction is in progress".lower() in s.lower():
            return_dict[
                "error"] = "An underlying storage operation has locked a volume so we are unable to process this request. Please try after a couple of seconds"
        else:
            return_dict[
                "error"] = "An error occurred when processing your request : %s" % s
        return django.shortcuts.render_to_response(
            "logged_in_error.html",
            return_dict,
            context_instance=django.template.context.RequestContext(request))
Example #32
0
def update_local_user_password(request):

    return_dict = {}
    try:
        if request.method == "GET":
            # Return the form
            if "username" not in request.GET:
                raise Exception("Invalid request. No user name specified.")
            d = {}
            d["username"] = request.GET["username"]
            form = local_user_forms.PasswordChangeForm(initial=d)
            return_dict["form"] = form
            return django.shortcuts.render_to_response(
                "update_local_user_password.html",
                return_dict,
                context_instance=django.template.context.RequestContext(
                    request))
        else:
            # Form submission so create
            return_dict = {}
            form = local_user_forms.PasswordChangeForm(request.POST)
            if form.is_valid():
                cd = form.cleaned_data
                rc, err = local_users.change_password(cd["username"],
                                                      cd["password"])
                if not rc:
                    if err:
                        raise Exception(err)
                    else:
                        raise Exception(
                            "Error changing the local user password")

                audit_str = "Changed password for local user %s" % cd[
                    "username"]
                ret, err = audit.audit("change_local_user_password", audit_str,
                                       request)
                # print ret, err
                if err:
                    raise Exception(err)
                return django.http.HttpResponseRedirect(
                    '/view_local_users?ack=changed_password')
            else:
                return_dict["form"] = form
                return django.shortcuts.render_to_response(
                    "update_local_user_password.html",
                    return_dict,
                    context_instance=django.template.context.RequestContext(
                        request))
    except Exception, e:
        return_dict['base_template'] = 'users_groups_base.html'
        return_dict["page_title"] = "Modify local user's password"
        return_dict['tab'] = 'view_local_users_tab'
        return_dict["error"] = "Error modifying local user's password"
        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_iscsi_target(request):
    return_dict = {}
    try:
        if request.method == "GET":
            # Return the form
            form = iscsi_stgt_forms.IscsiTargetForm()
            return_dict["form"] = form
            return django.shortcuts.render_to_response(
                "create_iscsi_target.html",
                return_dict,
                context_instance=django.template.context.RequestContext(
                    request))
        else:
            # Form submission so create
            return_dict = {}
            form = iscsi_stgt_forms.IscsiTargetForm(request.POST)
            if form.is_valid():
                cd = form.cleaned_data
                ret, err = iscsi_stgt.create_target(cd["name"])
                if not ret:
                    if err:
                        raise Exception(err)
                    else:
                        raise Exception("Unknown error.")
                audit_str = "Created an ISCSI target %s" % cd["name"]
                audit.audit("create_iscsi_target", audit_str, request)
                url = '/view_iscsi_targets?ack=created'
                return django.http.HttpResponseRedirect(url)
            else:
                return_dict["form"] = form
                return django.shortcuts.render_to_response(
                    "create_iscsi_target.html",
                    return_dict,
                    context_instance=django.template.context.RequestContext(
                        request))
    except Exception, e:
        return_dict['base_template'] = "shares_base.html"
        return_dict["page_title"] = 'Create an ISCSI target'
        return_dict['tab'] = 'view_iscsi_targets_tab'
        return_dict["error"] = 'Error creating an ISCSI target'
        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_vlan(request):
    return_dict = {}
    try:
        req_ret, err = django_utils.get_request_parameter_values(
            request, ['name'])
        if err:
            raise Exception(err)
        if 'name' not in req_ret:
            raise Exception('Invalid request, please use the menus')
        name = req_ret['name']
        return_dict["name"] = name

        if request.method == "GET":
            # Return the conf page
            return django.shortcuts.render_to_response(
                "delete_vlan_conf.html",
                return_dict,
                context_instance=django.template.context.RequestContext(
                    request))
        else:
            result, err = networking.delete_vlan(name)
            if not result:
                if not err:
                    raise Exception("Error removing VLAN")
                else:
                    raise Exception(err)

            result, err = networking.restart_networking()
            if err:
                raise Exception(err)

            audit_str = "Removed VLAN %s" % (name)
            audit.audit("remove_vlan", audit_str, request)
            return django.http.HttpResponseRedirect(
                '/view_interfaces?ack=removed_vlan')
    except Exception, e:
        return_dict['base_template'] = "networking_base.html"
        return_dict["page_title"] = 'Remove a VLAN'
        return_dict['tab'] = 'view_interfaces_tab'
        return_dict["error"] = 'Error removing a VLAN'
        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))
Example #35
0
def iscsi_edit_target_global_config(request):

    return_dict = {}
    try:
        aal, err = iscsi.load_auth_access_group_list()
        if err:
            raise Exception(err)
        if request.method == 'GET':
            # Display the form
            init, err = iscsi.load_global_target_conf()
            if err:
                raise Exception(err)
            if not init:
                init = {}
            if "base_name" not in init or not init["base_name"]:
                init["base_name"] = "iqn.2014-15.com.integralstor.istgt"
            if "discovery_auth_method" not in init or not init["discovery_auth_method"]:
                init["discovery_auth_method"] = "None"
            form = iscsi_forms.TargetGlobalConfigForm(
                initial=init, auth_access_group_list=aal)
            return_dict["form"] = form
            return django.shortcuts.render_to_response('edit_iscsi_target_global_config.html', return_dict, context_instance=django.template.context.RequestContext(request))
        else:
            # Save request
            form = iscsi_forms.TargetGlobalConfigForm(
                request.POST, auth_access_group_list=aal)
            return_dict["form"] = form

            if form.is_valid():
                cd = form.cleaned_data
                ret, err = iscsi.save_global_target_conf(cd)
                if err:
                    raise Exception(err)
                if not ret:
                    raise Exception(
                        "Error saving ISCSI global target configuration")

                audit_str = "Modified ISCSI global targets configuration%s" % id
                ret, err = audit.audit(
                    "modify_iscsi_global_target_conf", audit_str, request)
                if err:
                    raise Exception(err)

                return django.http.HttpResponseRedirect('/iscsi_view_target_global_config?action=saved')

            else:
                # Invalid form
                form.initial = form.data
                return django.shortcuts.render_to_response('edit_iscsi_target_global_config.html', return_dict, context_instance=django.template.context.RequestContext(request))
    except Exception, e:
        s = str(e)
        if "Another transaction is in progress".lower() in s.lower():
            return_dict["error"] = "An underlying storage operation has locked a volume so we are unable to process this request. Please try after a couple of seconds"
        else:
            return_dict["error"] = "An error occurred when processing your request : %s" % s
        return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def change_local_user_password(request):

    return_dict = {}
    try:
        return_dict['base_template'] = "users_base.html"
        return_dict["page_title"] = 'Change local user password'
        return_dict['tab'] = 'local_user_tab'
        return_dict["error"] = 'Error changing local user password'
        if request.method == "GET":
            # Return the form
            if "userid" not in request.GET:
                raise Exception("Invalid request. No user name specified.")
            d = {}
            d["userid"] = request.GET["userid"]
            form = local_user_forms.PasswordChangeForm(initial=d)
            return_dict["form"] = form
            return django.shortcuts.render_to_response("change_local_user_password.html", return_dict, context_instance=django.template.context.RequestContext(request))
        else:
            # Form submission so create
            return_dict = {}
            form = local_user_forms.PasswordChangeForm(request.POST)
            if form.is_valid():
                cd = form.cleaned_data
                ret, err = local_users.change_password(
                    cd["userid"], cd["password"])
                if err:
                    raise Exception(err)
                if not ret:
                    raise Exception('Error changing local user password')

                audit_str = "Changed password for local user %s" % cd["userid"]
                ret, err = audit.audit(
                    "change_local_user_password", audit_str, request)
                if err:
                    raise Exception(err)
                return django.http.HttpResponseRedirect('/view_local_users?ack=changed_password')
            else:
                return_dict["form"] = form
                return django.shortcuts.render_to_response("change_local_user_password.html", return_dict, context_instance=django.template.context.RequestContext(request))
    except Exception, e:
        s = str(e)
        if "Another transaction is in progress".lower() in s.lower():
            return_dict["error_details"] = "An underlying storage operation has locked a volume so we are unable to process this request. Please try after a couple of seconds"
        else:
            return_dict["error_details"] = "An error occurred when processing your request : %s" % s
        return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def delete_cifs_share(request):

    return_dict = {}
    try:
        return_dict['base_template'] = "shares_and_targets_base.html"
        return_dict["page_title"] = 'Delete a CIFS share'
        return_dict['tab'] = 'view_cifs_shares_tab'
        return_dict["error"] = 'Error deleteing a CIFS share'

        print request.REQUEST.keys()
        if 'share_id' not in request.REQUEST or 'name' not in request.REQUEST:
            raise Exception(
                'Invalid request. Required parameters not passed. Please use the menus.')

        share_id = request.REQUEST["share_id"]
        name = request.REQUEST["name"]
        if request.method == "GET":
            # Return the conf page
            return_dict["share_id"] = share_id
            return_dict["name"] = name
            return django.shortcuts.render_to_response("delete_cifs_share_conf.html", return_dict, context_instance=django.template.context.RequestContext(request))
        else:
            ret, err = cifs_utils.delete_share(share_id)
            if err:
                raise Exception(err)
            if not ret:
                raise Exception('Error deleting share')
            ret, err = cifs_gridcell.generate_smb_conf()
            if err:
                raise Exception(err)
            if not ret:
                raise Exception('Error generating CIFS configuration file')

            audit_str = "Deleted Windows share %s" % name
            ret, err = audit.audit("delete_share", audit_str, request)
            if err:
                raise Exception(err)
            return django.http.HttpResponseRedirect('/view_cifs_shares?ack=deleted')
    except Exception, e:
        s = str(e)
        if "Another transaction is in progress".lower() in s.lower():
            return_dict["error_details"] = "An underlying storage operation has locked a volume so we are unable to process this request. Please try after a couple of seconds"
        else:
            return_dict["error_details"] = "An error occurred when processing your request : %s" % s
        return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
Example #38
0
def iscsi_create_auth_access_user(request):

    return_dict = {}
    try:
        if request.method == "GET":
            # Return the form
            if 'auth_access_group_id' not in request.GET:
                raise Exception('No group ID provided. Please use the menus')
            auth_access_group_id = int(request.GET["auth_access_group_id"])
            init = {}
            init["auth_access_group_id"] = auth_access_group_id
            form = iscsi_forms.AuthorizedAccessUserForm(initial=init)
            return_dict["form"] = form
            return django.shortcuts.render_to_response("create_iscsi_auth_access_group.html", return_dict, context_instance=django.template.context.RequestContext(request))
        else:
            # Form submission so create
            return_dict = {}
            form = iscsi_forms.AuthorizedAccessUserForm(request.POST)
            return_dict["form"] = form
            if form.is_valid():
                cd = form.cleaned_data
                ret, err = iscsi.create_auth_access_user(
                    cd["auth_access_group_id"], cd["user"], cd["secret"])
                if err:
                    raise Exception(err)
                if not ret:
                    raise Exception('Error creating authorized access user')

                audit_str = "Created an ISCSI authorized access user in group %s" % cd[
                    "auth_access_group_id"]
                ret, err = audit.audit(
                    "create_iscsi_auth_access_group", audit_str, request)
                if err:
                    raise Exception(err)
                return django.http.HttpResponseRedirect('/iscsi_display_auth_access_group_list?action=user_created')
            else:
                return django.shortcuts.render_to_response("create_iscsi_auth_access_user.html", return_dict, context_instance=django.template.context.RequestContext(request))
    except Exception, e:
        s = str(e)
        if "Another transaction is in progress".lower() in s.lower():
            return_dict["error"] = "An underlying storage operation has locked a volume so we are unable to process this request. Please try after a couple of seconds"
        else:
            return_dict["error"] = "An error occurred when processing your request : %s" % s
        return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def create_local_user(request):
    return_dict = {}
    try:
        return_dict['base_template'] = "users_base.html"
        return_dict["page_title"] = 'Create a local user'
        return_dict['tab'] = 'create_local_user_tab'
        return_dict["error"] = 'Error creating local user'

        if request.method == "GET":
            # Return the form
            form = local_user_forms.LocalUserForm()
            return_dict["form"] = form
            return django.shortcuts.render_to_response("create_local_user.html", return_dict, context_instance=django.template.context.RequestContext(request))
        else:
            # Form submission so create
            form = local_user_forms.LocalUserForm(request.POST)
            if form.is_valid():
                cd = form.cleaned_data
                ret, err = local_users.create_local_user(
                    cd["userid"], cd["name"], cd["password"])
                if err:
                    raise Exception(err)
                if not ret:
                    raise Exception('Error creating local user')
                audit_str = "Created a local user %s" % cd["userid"]
                r, err = audit.audit("create_local_user",
                                     audit_str, request)
                if err:
                    raise Exception(err)
                url = '/view_local_users?ack=created'
                return django.http.HttpResponseRedirect(url)
            else:
                return_dict["form"] = form
                return django.shortcuts.render_to_response("create_local_user.html", return_dict, context_instance=django.template.context.RequestContext(request))
    except Exception, e:
        s = str(e)
        if "Another transaction is in progress".lower() in s.lower():
            return_dict["error_details"] = "An underlying storage operation has locked a volume so we are unable to process this request. Please try after a couple of seconds"
        else:
            return_dict["error_details"] = "An error occurred when processing your request : %s" % s
        return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
Example #40
0
def iscsi_create_initiator(request):

    return_dict = {}
    try:
        if request.method == "GET":
            # Return the form
            form = iscsi_forms.InitiatorForm()
            return_dict["form"] = form
            return django.shortcuts.render_to_response("create_iscsi_initiator.html", return_dict, context_instance=django.template.context.RequestContext(request))
        else:
            # Form submission so create
            return_dict = {}
            form = iscsi_forms.InitiatorForm(request.POST)
            return_dict["form"] = form
            if form.is_valid():
                cd = form.cleaned_data
                ret, err = iscsi.create_iscsi_initiator(
                    cd["initiators"], cd["auth_network"], cd["comment"])
                if err:
                    raise Exception(err)
                if not ret:
                    raise Exception('Error creating initiator')

                audit_str = "Created an ISCSI initiator"
                ret, err = audit.audit(
                    "create_iscsi_initiator", audit_str, request)
                if err:
                    raise Exception(err)
                return django.http.HttpResponseRedirect('/iscsi_display_initiators?action=created')
            else:
                return django.shortcuts.render_to_response("create_iscsi_initiator.html", return_dict, context_instance=django.template.context.RequestContext(request))
    except Exception, e:
        s = str(e)
        if "Another transaction is in progress".lower() in s.lower():
            return_dict["error"] = "An underlying storage operation has locked a volume so we are unable to process this request. Please try after a couple of seconds"
        else:
            return_dict["error"] = "An error occurred when processing your request : %s" % s
        return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
Example #41
0
def iscsi_delete_auth_access_user(request):

    return_dict = {}
    try:
        if 'user_id' not in request.REQUEST:
            raise Exception('User ID not specified. Please use the menus')
        user_id = request.REQUEST["user_id"]
        if request.method == "GET":
            # Return the conf page
            d, err = iscsi.load_auth_access_user_info(int(user_id))
            if err:
                raise Exception(err)
            if not d:
                raise Exception(
                    "Could not find information about ISCSI authorized access user")
            return_dict["user_id"] = user_id
            return_dict["user"] = d["user"]
            return django.shortcuts.render_to_response("delete_iscsi_auth_access_user_conf.html", return_dict, context_instance=django.template.context.RequestContext(request))
        else:
            ret, err = iscsi.delete_auth_access_user(int(user_id))
            if err:
                raise Exception(err)
            if not ret:
                raise Exception('Error deleting user')

            audit_str = "Deleted ISCSI authorized access user %s" % user_id
            ret, err = audit.audit(
                "delete_iscsi_auth_access_user", audit_str, request)
            if err:
                raise Exception(err)
            return django.http.HttpResponseRedirect('/iscsi_display_auth_access_group_list?action=user_deleted')
    except Exception, e:
        s = str(e)
        if "Another transaction is in progress".lower() in s.lower():
            return_dict["error"] = "An underlying storage operation has locked a volume so we are unable to process this request. Please try after a couple of seconds"
        else:
            return_dict["error"] = "An error occurred when processing your request : %s" % s
        return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def delete_local_user(request):

    return_dict = {}
    try:
        return_dict['base_template'] = "users_base.html"
        return_dict["page_title"] = 'Delete a local user'
        return_dict['tab'] = 'local_user_tab'
        return_dict["error"] = 'Error deleteing a local user'
        if "userid" not in request.REQUEST:
            raise Exception("Invalid request. No user name specified.")

        if request.method == "GET":
            # Return the form
            return_dict["userid"] = request.GET["userid"]
            return django.shortcuts.render_to_response("delete_local_user_conf.html", return_dict, context_instance=django.template.context.RequestContext(request))
        else:
            # Form submission so create
            return_dict = {}
            ret, err = local_users.delete_local_user(request.POST["userid"])
            if err:
                raise Exception(err)
            if not ret:
                raise Exception('Error deleting local user')
            audit_str = "Deleted a local user %s" % request.POST["userid"]
            ret, err = audit.audit("delete_local_user",
                                   audit_str, request)
            if err:
                raise Exception(err)
            url = '/view_local_users?ack=deleted'
            return django.http.HttpResponseRedirect(url)
    except Exception, e:
        s = str(e)
        if "Another transaction is in progress".lower() in s.lower():
            return_dict["error_details"] = "An underlying storage operation has locked a volume so we are unable to process this request. Please try after a couple of seconds"
        else:
            return_dict["error_details"] = "An error occurred when processing your request : %s" % s
        return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def process_batch(d, file, logger=None):
    # Process each batch file

    try:
        batch_files_path, err = config.get_batch_files_path()
        if err:
            raise Exception(err)
        if not d:
            raise Exception("Error: No JSON info in %s/%s" %
                            (batch_files_path, file))

        # if not d["process"] in ["replace_sled", "volume_rebalance", "factory_defaults_reset"]:
        #  raise Exception("Error! Unknown process in %s/%s"%(batch_files_path, file))

        if not "start_time" in d:
            # Update when this process was started
            d["start_time"] = time.strftime(
                "%a %b %d %H:%M:%S %Y", time.localtime())

        if d["status"] != "In progress":
            d["status"] = "In progress"

        # ADD CODE HERE TO MOVE IT TO COMPLETED DIR IF STATUS IS COMPLETE

        # Not committed so process the file
        for cd in d["command_list"]:

            # Remove old err_msg because we are reprocessing
            cd.pop("err_msg", None)

            # Status codes explanation -
            # 3 - complete
            # 0 - not yet run
            # 1 - in progress
            # -1 - error executing command

            if cd["status_code"] == 3:
                # Completed so skip to next command
                continue

            # Else failed or not done so do it

            if cd["type"] == "volume_heal_full":
                # No XML output so do some dirty text processing.
                try:
                    r = None
                    r, err = command.execute(cd["command"])
                    if err:
                        raise Exception(err)
                    lines = []
                    if r:
                        lines, err = command.get_output_list(r)
                        if err:
                            raise Exception(err)
                    else:
                        raise Exception('')

                    # Now start processing output of command
                    if lines:
                        for line in lines:
                            # print line
                            m = re.search("has been successful", line)
                            # print m
                            if m:
                                # print 'success'
                                # Successfully executed
                                ret, err = audit.audit(
                                    cd["type"], cd["desc"], 'Batch job')
                                cd["status_code"] = 3
                                break
                        if cd["status_code"] != 3:
                            # Stop executing more commands!
                            raise Exception("Got : %s" % line)
                    else:
                        # No output from command execution so flag error
                        raise Exception(
                            "Volume heal did not seem to kick off properly. Please make sure the volume is started.")
                except Exception, e:
                    cd["status_code"] = -1
                    cd["err_msg"] = "Error executing volume heal command : %s" % str(
                        e)
                    # Stop executing more commands!
                    break

            elif cd["type"] == "brick_delete":
                # Need to execute a shell command to remotely delete a brick.
                try:
                    (ret, rc), err = command.execute_with_rc(cd["command"])
                    if rc == 0:
                        cd["status_code"] = 3
                    else:
                        raise Exception(
                            "Error deleting the volume brick : %s %s" % (ret[0], ret[1]))
                except Exception, e:
                    cd["status_code"] = -1
                    cd["err_msg"] = "Error executing brick delete command : %s" % str(
                        e)
                    # Stop executing more commands!
                    break
Example #44
0
def iscsi_edit_target(request):

    return_dict = {}
    try:
        vil, err = volume_info.get_basic_volume_info_all()
        if err:
            raise Exception(err)
        vl, err = iscsi.load_iscsi_volumes_list(vil)
        if err:
            raise Exception(err)
        aal, err = iscsi.load_auth_access_group_list()
        if err:
            raise Exception(err)
        igl, err = iscsi.load_initiators_list()
        if err:
            raise Exception(err)

        if "id" not in request.REQUEST:
            raise Exception("Unknown target specified")

        id = int(request.REQUEST["id"])

        if request.method == "GET":
            # Shd be an edit request
            target, err = iscsi.load_target_info(int(id))
            if err:
                raise Exception(err)
            if not target:
                raise Exception('Specified target not found')

            # Set initial form values
            initial = {}
            initial["id"] = target["id"]
            initial["vol_name"] = target["vol_name"]
            initial["target_alias"] = target["target_alias"]
            initial["lun_size"] = target["lun_size"]
            initial["auth_method"] = target["auth_method"]
            initial["queue_depth"] = target["queue_depth"]
            initial["auth_group_id"] = int(target["auth_group_id"])
            initial["init_group_id"] = int(target["init_group_id"])

            form = iscsi_forms.TargetForm(
                auth_access_group_list=aal, initiator_group_list=igl, volumes_list=vl, initial=initial)

            return_dict["form"] = form
            return django.shortcuts.render_to_response('edit_iscsi_target.html', return_dict, context_instance=django.template.context.RequestContext(request))

        else:

            # Shd be an save request
            form = iscsi_forms.TargetForm(
                request.POST, auth_access_group_list=aal, initiator_group_list=igl, volumes_list=vl)
            return_dict["form"] = form
            if form.is_valid():
                cd = form.cleaned_data
                ret, err = iscsi.save_target(id, cd)
                if err:
                    raise Exception(err)
                if not ret:
                    raise Exception('Error saving the specified target')
                ret, err = iscsi.generate_istgt_conf()
                if err:
                    raise Exception(err)
                if not ret:
                    raise Exception(
                        'Error generating the ISCSI configuration file')
                audit_str = "Modified target %s" % id
                ret, err = audit.audit(
                    "modify_target", audit_str, request)
                if err:
                    raise Exception(err)

                return django.http.HttpResponseRedirect('/iscsi_view_target?access_mode=by_id&id=%s&action=saved' % id)

            else:
                # Invalid form
                return django.shortcuts.render_to_response('edit_iscsi_target.html', return_dict, context_instance=django.template.context.RequestContext(request))
    except Exception, e:
        s = str(e)
        if "Another transaction is in progress".lower() in s.lower():
            return_dict["error"] = "An underlying storage operation has locked a volume so we are unable to process this request. Please try after a couple of seconds"
        else:
            return_dict["error"] = "An error occurred when processing your request : %s" % s
        return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
Example #45
0
def iscsi_create_target(request):

    return_dict = {}
    try:
        vil, err = volume_info.get_basic_volume_info_all()
        if err:
            raise Exception(err)
        vl, err = iscsi.load_iscsi_volumes_list(vil)
        if err:
            raise Exception(err)
        aal, err = iscsi.load_auth_access_group_list()
        if err:
            raise Exception(err)
        igl, err = iscsi.load_initiators_list()
        if err:
            raise Exception(err)

        if not igl or not aal or not vl:
            if not igl:
                raise Exception(
                    "Please create an initiator before creating a target")
            if not vl:
                raise Exception(
                    "Please create an ISCSI access enabled volume before creating a target")
            if not aal:
                raise Exception(
                    "Please create an authorized access before creating a target")

        if request.method == "GET":
            # Return the form
            return_dict = {}
            form = iscsi_forms.TargetForm(
                auth_access_group_list=aal, initiator_group_list=igl, volumes_list=vl)
            return_dict["form"] = form
            return django.shortcuts.render_to_response("create_iscsi_target.html", return_dict, context_instance=django.template.context.RequestContext(request))
        else:
            # Form submission so create
            return_dict = {}
            form = iscsi_forms.TargetForm(
                request.POST, auth_access_group_list=aal, initiator_group_list=igl, volumes_list=vl)
            return_dict["form"] = form
            if form.is_valid():
                cd = form.cleaned_data
                ret, err = iscsi.create_iscsi_target(
                    cd["vol_name"],  cd["target_alias"], cd["lun_size"], cd["auth_method"], cd["queue_depth"], cd["auth_group_id"], cd["init_group_id"])
                if err:
                    raise Exception(err)
                if not ret:
                    raise Exception('Error creating ISCSI target')

                audit_str = "Created an ISCSI target"
                ret, err = audit.audit(
                    "create_iscsi_target", audit_str, request)
                if err:
                    raise Exception(err)
                return django.http.HttpResponseRedirect('/iscsi_display_targets?action=created')
            else:
                return django.shortcuts.render_to_response("create_iscsi_target.html", return_dict, context_instance=django.template.context.RequestContext(request))
    except Exception, e:
        s = str(e)
        if "Another transaction is in progress".lower() in s.lower():
            return_dict["error"] = "An underlying storage operation has locked a volume so we are unable to process this request. Please try after a couple of seconds"
        else:
            return_dict["error"] = "An error occurred when processing your request : %s" % s
        return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def edit_cifs_share(request):

    return_dict = {}
    try:
        gluster_lck, err = lock.get_lock('gluster_commands')
        if err:
            raise Exception(err)

        if not gluster_lck:
            raise Exception(
                'This action cannot be performed as an underlying storage command is being run. Please retry this operation after a few seconds.')

        return_dict['base_template'] = "shares_and_targets_base.html"
        return_dict["page_title"] = 'Edit CIFS share details'
        return_dict['tab'] = 'view_cifs_shares_tab'
        return_dict["error"] = 'Error editing CIFS share details'

        vil, err = gluster_volumes.get_basic_volume_info_all()
        if err:
            raise Exception(err)
        if not vil:
            raise Exception('Could not load volume information')
        user_list, err = cifs_gridcell.get_user_list()
        if err:
            raise Exception(err)
        group_list, err = cifs_gridcell.get_group_list()
        if err:
            raise Exception(err)

        if request.method == "GET":
            # Shd be an edit request
            if "share_id" not in request.GET:
                raise Exception("Unknown share specified")
            share_id = request.GET["share_id"]
            share_dict, err = cifs_utils.get_share_info("by_id", share_id)
            if err:
                raise Exception(err)
            valid_users_list, err = cifs_gridcell.get_valid_users_list(
                share_dict["share_id"])
            if err:
                raise Exception(err)

            # Set initial form values
            initial = {}
            initial["share_id"] = share_dict["share_id"]
            initial["name"] = share_dict["name"]
            initial["path"] = share_dict["path"]
            initial["display_path"] = share_dict["display_path"]
            initial["vol"] = share_dict["vol"]
            if share_dict["guest_ok"]:
                initial["guest_ok"] = True
            else:
                initial["guest_ok"] = False
            if share_dict["browseable"]:
                initial["browseable"] = True
            else:
                initial["browseable"] = False
            if share_dict["read_only"]:
                initial["read_only"] = True
            else:
                initial["read_only"] = False
            initial["comment"] = share_dict["comment"]

            if valid_users_list:
                vgl = []
                vul = []
                for u in valid_users_list:
                    if u["grp"]:
                        vgl.append(u["name"])
                    else:
                        vul.append(u["name"])
                initial["users"] = vul
                initial["groups"] = vgl

            form = cifs_shares_forms.ShareForm(
                initial=initial, user_list=user_list, group_list=group_list, volume_list=vil)

            return_dict["form"] = form
            return django.shortcuts.render_to_response('edit_cifs_share.html', return_dict, context_instance=django.template.context.RequestContext(request))

        else:

            # Shd be an save request
            form = cifs_shares_forms.ShareForm(
                request.POST, user_list=user_list, group_list=group_list, volume_list=vil)
            return_dict["form"] = form
            if form.is_valid():
                cd = form.cleaned_data
                name = cd["name"]
                share_id = cd["share_id"]
                path = cd["path"]
                if "comment" in cd:
                    comment = cd["comment"]
                else:
                    comment = None
                if "read_only" in cd:
                    read_only = cd["read_only"]
                else:
                    read_only = False
                if "browseable" in cd:
                    browseable = cd["browseable"]
                else:
                    browseable = False
                if "guest_ok" in cd:
                    guest_ok = cd["guest_ok"]
                else:
                    guest_ok = False
                if "users" in cd:
                    users = cd["users"]
                else:
                    users = None
                if "groups" in cd:
                    groups = cd["groups"]
                else:
                    groups = None
                vol = cd["vol"]
                ret, err = cifs_utils.update_share(
                    share_id, name, comment, guest_ok, read_only, path, browseable, users, groups)
                if err:
                    raise Exception(err)
                if not ret:
                    raise Exception('Error saving share')
                ret, err = cifs_gridcell.generate_smb_conf()
                if err:
                    raise Exception(err)
                if not ret:
                    raise Exception('Error generating CIFS configuration file')

                audit_str = "Modified share %s" % cd["name"]
                ret, err = audit.audit("modify_share", audit_str, request)
                if err:
                    raise Exception(err)

                return django.http.HttpResponseRedirect('/view_cifs_share?access_mode=by_id&index=%s&ack=saved' % cd["share_id"])

            else:
                # Invalid form
                return django.shortcuts.render_to_response('edit_cifs_share.html', return_dict, context_instance=django.template.context.RequestContext(request))
    except Exception, e:
        s = str(e)
        if "Another transaction is in progress".lower() in s.lower():
            return_dict["error_details"] = "An underlying storage operation has locked a volume so we are unable to process this request. Please try after a couple of seconds"
        else:
            return_dict["error_details"] = "An error occurred when processing your request : %s" % s
        return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def edit_cifs_authentication_settings(request):

    return_dict = {}
    try:
        return_dict['base_template'] = "services_base.html"
        return_dict["page_title"] = 'Configure CIFS access'
        return_dict['tab'] = 'service_cifs_access_tab'
        return_dict["error"] = 'Error configuring CIFS access'

        if request.method == 'GET':
            d, err = cifs_utils.get_auth_settings()
            if err:
                raise Exception(err)

            ini = {}
            if d:
                for k in d.keys():
                    ini[k] = d[k]
            if d and d["security"] == "ads":
                form = cifs_shares_forms.ADAuthenticationSettingsForm(
                    initial=ini)
            else:
                form = cifs_shares_forms.LocalUsersAuthenticationSettingsForm(
                    initial=ini)
            return_dict["form"] = form
            return django.shortcuts.render_to_response('edit_cifs_authentication_settings.html', return_dict, context_instance=django.template.context.RequestContext(request))
        else:
            # Save request
            if "security" not in request.POST:
                raise Exception(
                    "Invalid security specification. Please try again using the menus")

            if request.POST["security"] == "ads":
                form = cifs_shares_forms.ADAuthenticationSettingsForm(
                    request.POST)
            elif request.POST["security"] == "users":
                form = cifs_shares_forms.LocalUsersAuthenticationSettingsForm(
                    request.POST)
            else:
                raise Exception(
                    "Invalid security specification. Please try again using the menus")

            return_dict["form"] = form
            return_dict["action"] = "edit"

            if form.is_valid():
                # print 'valid form!'
                cd = form.cleaned_data

                ret, err = cifs_utils.update_auth_settings(cd)
                if err:
                    raise Exception(err)
                # print '1'

                if cd["security"] == "ads":
                    client = salt.client.LocalClient()
                    results = client.cmd(
                        '*', 'integralstor.configure_name_servers', [cd['password_server_ip']])
                    if results:
                        for node, ret in results.items():
                            if not ret[0]:
                                raise Exception(
                                    "Error updating the DNS configuration on GRIDCell %s" % node)
                '''
        # We now need to add the AD server as the forwarder in our DNS config on the primary...
        nsl, err = networking.get_name_servers()
        if err:
          raise Exception(err)
        if not nsl:
          raise Exception("Could not detect the IP addresses of the primary and secondary GRIDCells")
        if len(nsl) < 2:
          raise Exception("Could not detect the IP addresses of the primary and secondary GRIDCells")
        ipinfo, err = networking.get_ip_info('bond0')
        if err:
          raise Exception(err)
        if cd["security"] == "ads":
          rc, err = networking.generate_default_primary_named_conf(nsl[0], ipinfo['netmask'], nsl[1], True, cd['password_server_ip'], False)
          if err:
            raise Exception(err)
          if not rc:
            raise Exception("Error updating the DNS configuration on the primary GRIDCell")

          # ... and on the secondary
          client = salt.client.LocalClient()
          python_scripts_path, err = config.get_python_scripts_path()
          if err:
            raise Exception(err)
          r2 = client.cmd('roles:secondary', 'cmd.run_all', ['python %s/create_secondary_named_config.py %s %s %s %s'%(python_scripts_path, nsl[0], nsl[1], ipinfo['netmask'], cd['password_server_ip'])], expr_form='grain')
          if r2:
            for node, ret in r2.items():
              if ret["retcode"] != 0:
                raise Exception("Error updating the DNS configuration on the primary GRIDCell")
        '''

                # print '2'
                if cd["security"] == "ads":
                    ret, err = cifs_utils.generate_krb5_conf()
                    if err:
                        raise Exception(err)
                    if not ret:
                        raise Exception(
                            'Error generating the kerberos config file')
                ret, err = cifs_gridcell.generate_smb_conf()
                if err:
                    raise Exception(err)
                if not ret:
                    raise Exception('Error generating CIFS configuration file')
                if cd["security"] == "ads":
                    rc, err = cifs_gridcell.kinit(
                        "administrator", cd["password"], cd["realm"])
                    if err:
                        raise Exception(err)
                    if not rc:
                        raise Exception("Kerberos init failure")
                print cd
                if cd["security"] == "ads":
                    rc, err = cifs_gridcell.net_ads_join(
                        "administrator", cd["password"], cd["password_server"])
                    if err:
                        raise Exception(err)
                    if not rc:
                        raise Exception("AD join failure")
                ret, err = cifs_gridcell.restart_samba_services()
                if err:
                    raise Exception(err)
                if not ret:
                    raise Exception('Error restarting the CIFS service')
            else:
                return django.shortcuts.render_to_response('edit_cifs_authentication_settings.html', return_dict, context_instance=django.template.context.RequestContext(request))

            # print '7'
            audit_str = "Modified share authentication settings"
            ret, err = audit.audit(
                "modify_samba_settings", audit_str, request)
            if err:
                raise Exception(err)
            #return_dict["conf_message"] = "Information successfully updated"
            # print '8'
            return django.http.HttpResponseRedirect('/view_cifs_authentication_settings?ack=saved')

    except Exception, e:
        s = str(e)
        if "Another transaction is in progress".lower() in s.lower():
            return_dict["error_details"] = "An underlying storage operation has locked a volume so we are unable to process this request. Please try after a couple of seconds"
        else:
            return_dict["error_details"] = "An error occurred when processing your request : %s" % s
        return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def create_cifs_share(request):

    return_dict = {}
    try:
        return_dict['base_template'] = "shares_and_targets_base.html"
        return_dict["page_title"] = 'Create a Windows share'
        return_dict['tab'] = 'view_cifs_shares_tab'
        return_dict["error"] = 'Error creating a Windows share'

        gluster_lck, err = lock.get_lock('gluster_commands')
        if err:
            raise Exception(err)

        if not gluster_lck:
            raise Exception(
                'This action cannot be performed as an underlying storage command is being run. Please retry this operation after a few seconds.')

        user_list, err = cifs_gridcell.get_user_list()
        if err:
            raise Exception(err)
        group_list, err = cifs_gridcell.get_group_list()
        if err:
            raise Exception(err)

        if 'vol_name' in request.REQUEST:
            return_dict['vol_name'] = request.REQUEST['vol_name']

        vil, err = gluster_volumes.get_basic_volume_info_all()
        if err:
            raise Exception(err)
        if not vil:
            raise Exception(
                'No volumes have been created. Please create a volume before creating shares.')

        il, err = iscsi.load_iscsi_volumes_list(vil)
        if err:
            raise Exception(err)
        vl = []
        for v in vil:
            # Get only file based volumes that have been started
            if il and v["name"] in il:
                continue
            if v['status'] != 1:
                continue
            vl.append(v)
        if not vl:
            raise Exception(
                'Shares can only be created on volumes that are file based and that are started. No volumes seem to match these criteria.')

        if request.method == "GET":
            # Return the form
            form = cifs_shares_forms.CreateShareForm(
                user_list=user_list, group_list=group_list, volume_list=vl)
            return_dict["form"] = form
            return django.shortcuts.render_to_response("create_cifs_share.html", return_dict, context_instance=django.template.context.RequestContext(request))
        else:
            # Form submission so create
            form = cifs_shares_forms.CreateShareForm(
                request.POST, user_list=user_list, group_list=group_list, volume_list=vl)
            return_dict["form"] = form
            # print request.POST
            if form.is_valid():
                # print return_dict
                cd = form.cleaned_data
                # print cd
                name = cd["name"]
                path = "%s" % cd["path"]

                if "comment" in cd:
                    comment = cd["comment"]
                else:
                    comment = None
                if "read_only" in cd:
                    read_only = cd["read_only"]
                else:
                    read_only = None
                if "browseable" in cd:
                    browseable = cd["browseable"]
                else:
                    browseable = None
                if "guest_ok" in cd:
                    guest_ok = cd["guest_ok"]
                else:
                    guest_ok = None
                if "users" in cd:
                    users = cd["users"]
                else:
                    users = None
                if "groups" in cd:
                    groups = cd["groups"]
                else:
                    groups = None
                vol = cd["vol"]
                if 'new_dir_name' in cd and cd['new_dir_name'].strip():
                    path = os.path.join(path, cd['new_dir_name'])
                    # print path
                    ret, err = gluster_gfapi.create_gluster_dir(vol, path)
                    if err:
                        raise Exception(err)
                # print users, groups
                ret, err = cifs_utils.create_share(
                    name, comment, guest_ok, read_only, path, "", browseable, users, groups, vol)
                if err:
                    raise Exception(err)
                if not ret:
                    raise Exception('Error creating share')
                ret, err = cifs_gridcell.generate_smb_conf()
                if err:
                    raise Exception(err)
                if not ret:
                    raise Exception('Error generating CIFS configuration file')

                audit_str = "Created Windows share %s" % name
                ret, err = audit.audit("create_share", audit_str, request)
                if err:
                    raise Exception(err)
                return django.http.HttpResponseRedirect('/view_cifs_shares?ack=created')
            else:
                return django.shortcuts.render_to_response("create_cifs_share.html", return_dict, context_instance=django.template.context.RequestContext(request))
    except Exception, e:
        s = str(e)
        if "Another transaction is in progress".lower() in s.lower():
            return_dict["error_details"] = "An underlying storage operation has locked a volume so we are unable to process this request. Please try after a couple of seconds"
        else:
            return_dict["error_details"] = "An error occurred when processing your request : %s" % s
        return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
                        raise Exception(
                            "Could not get status of command %s" % cd["command"])
                    if (not "op_ret" in op_status) or (not "op_errno" in op_status):
                        raise Exception(
                            "Could not get opStatus or opErrno of command %s" % cd["command"])
                    if op_status["op_ret"] != 0:
                        raise Exception("Error executing %s. Returned op_ret %d. op_errno %d. op_errstr %s" % (
                            cd["command"], op_status["op_ret"], op_status["op_errno"], op_status["op_errstr"]))

                    # Come here only if successful

                    if cd["type"] in ["add_brick", "remove_brick_start", "rebalance_start", "volume_heal_full"]:
                        # One off command so
                        # All ok so mark status as successful so it is not
                        # rerun
                        ret, err = audit.audit(
                            cd["type"], cd["desc"], 'Batch job')
                        cd["status_code"] = 3
                        continue

                    # Continue only for commands that need to be polled for
                    # status

                    done = True
                    if cd["type"] in ["remove_brick_status", "rebalance_status"]:

                        if cd["type"] == "remove_brick_status":
                            rootStr = "volRemoveBrick"
                        else:
                            rootStr = "volRebalance"

                        nodes = tree.findall(".//%s/node" % rootStr)
def create_volume(request):
    """ Used to actually create the volume"""

    return_dict = {}
    try:
        gluster_lck, err = lock.get_lock('gluster_commands')
        if err:
            raise Exception(err)

        if not gluster_lck:
            raise Exception(
                'This action cannot be performed as an underlying storage command is being run. Please retry this operation after a few seconds.')

        return_dict['base_template'] = "volume_base.html"
        return_dict["page_title"] = 'Create a volume'
        return_dict['tab'] = 'view_volumes_tab'
        return_dict["error"] = 'Error creating a volume'

        if request.method != "POST":
            raise Exception("Invalid access method. Please use the menus.")

        if 'cmd' not in request.POST or 'dataset_list' not in request.POST:
            raise Exception('Required parameters not passed.')

        # cmd represents the actual gluster volume creation command built using
        # the wizard choices.
        cmd = request.POST['cmd']
        # print cmd

        # dataset_list is a list of hostname:dataset components of the datasets
        # that need to br created on various gridcells.
        dsl = request.POST.getlist('dataset_list')
        dataset_dict = {}
        for ds in dsl:
            tl = ds.split(':')
            dataset_dict[tl[0]] = tl[1]

        iv_logging.info("create volume command %s" % cmd)

        # First create the datasets on which the bricks will reside.
        # revert_list will consist of the set of node:command components to
        # perform to undo dataset creation in case of some failures.
        client = salt.client.LocalClient()
        revert_list = []
        errors = ""
        for node, dataset in dataset_dict.items():
            dataset_cmd = 'zfs create %s' % dataset
            dataset_revert_cmd = 'zfs destroy %s' % dataset
            r1 = client.cmd(node, 'cmd.run_all', [dataset_cmd])
            if r1:
                for node, ret in r1.items():
                    # print ret
                    if ret["retcode"] != 0:
                        errors += ", Error creating the underlying storage brick on %s" % node
                        # print errors
                    else:
                        revert_list.append({node: dataset_revert_cmd})

        if errors != "":
            # print errors
            if revert_list:
                # Undo the creation of the datasets
                for revert in revert_list:
                    for node, dsr_cmd in revert.items():
                        r1 = client.cmd(node, 'cmd.run_all', [dsr_cmd])
                        if r1:
                            for node, ret in r1.items():
                                # print ret
                                if ret["retcode"] != 0:
                                    errors += ", Error undoing the creating the underlying storage brick on %s" % node
            raise Exception(errors)

        # Underlying storage created so now create the volume

        d, errors = xml_parse.run_gluster_command("%s force" % cmd)
        # print d, errors
        if not errors:
            # All ok so mount and change the owner and group of the volume to
            # integralstor
            (ret, rc), err = command.execute_with_rc("gluster volume set " +
                                                     request.POST['vol_name'] + " storage.owner-gid 1000")
            if err:
                raise Exception('Error setting volume owner : %s' % err)

            # Now start the volume
            (ret, rc), err = command.execute_with_rc(
                "gluster volume start " + request.POST['vol_name'])
            if err:
                raise Exception('Error starting volume : %s' % err)

            '''
      #Set the client side quorum count
      cmd = "gluster volume set %s quorum-count 2 --xml"%request.POST['vol_name']
      d, err = xml_parse.run_gluster_command(cmd)
      if err:
        raise Exception('Error setting volume client side quorum count : %s'%err)

      #Set the client side quorum type
      cmd = "gluster volume set %s quorum-type fixed --xml"%request.POST['vol_name']
      d, err = xml_parse.run_gluster_command(cmd)
      if err:
        raise Exception('Errot setting volume client side quorum type : %s'%err)
      '''

            # Temporarily mount the volume
            (ret, rc), err = command.execute_with_rc(
                "mount -t glusterfs localhost:/" + request.POST['vol_name'] + " /mnt")
            if err:
                raise Exception(err)

            # Set the volume permissions
            (ret, rc), err = command.execute_with_rc("chmod 770 /mnt")
            if err:
                raise Exception(err)

            #..and unmount the volume
            (ret, rc), err = command.execute_with_rc("umount /mnt")
            if err:
                raise Exception(err)

            # If it is an ISCSI volume, then add it to the iscsi volume list..
            # print request.POST['vol_access']
            if request.POST["vol_access"] == "iscsi":
                ret, err = iscsi.add_iscsi_volume(request.POST["vol_name"])
                if err:
                    raise Exception(err)

            # Success so audit the change
            audit_str = "Create "
            if request.POST["vol_type"] in ["replicated"]:
                audit_str = audit_str + \
                    "replicated (count %d) " % int(request.POST["repl_count"])
            else:
                audit_str = audit_str + "distributed  "
            audit_str = audit_str + \
                " volume named %s" % request.POST["vol_name"]
            ret, err = audit.audit("create_volume", audit_str, request)
            if err:
                raise Exception(err)
        else:
            # Volume creation itself failed so try and delete the underlying
            # datasets if they were created..
            if not errors:
                errors = ""
            if revert_list:
                # Undo the creation of the datasets
                for revert in revert_list:
                    for node, dsr_cmd in revert.items():
                        r1 = client.cmd(node, 'cmd.run_all', [dsr_cmd])
                        if r1:
                            for node, ret in r1.items():
                                print ret
                                if ret["retcode"] != 0:
                                    errors += ", Error undoing the creating the underlying storage brick on %s" % node
        if errors:
            raise Exception(errors)

        if request.POST['vol_type'] == 'replicated':
            return_dict['repl_count'] = request.POST['repl_count']
        return_dict['vol_type'] = request.POST['vol_type']
        return_dict['vol_name'] = request.POST['vol_name']
        return_dict['node_list_str'] = request.POST['node_list_str']
        return_dict['cmd'] = cmd
        return_dict['result_dict'] = d

        return django.shortcuts.render_to_response('vol_create_wiz_result.html', return_dict, context_instance=django.template.context.RequestContext(request))
    except Exception, e:
        s = str(e)
        if "Another transaction is in progress".lower() in s.lower():
            return_dict["error_details"] = "An underlying storage operation has locked a volume so we are unable to process this request. Please try after a couple of seconds"
        else:
            return_dict["error_details"] = "An error occurred when processing your request : %s" % s
        return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
Example #51
0
def iscsi_edit_auth_access_user(request):

    return_dict = {}
    try:
        if "user_id" not in request.REQUEST:
            raise Exception("Unknown authorized access user specified")
            return django.shortcuts.render_to_response('logged_in_error.html', return_dict, context_instance=django.template.context.RequestContext(request))

        user_id = int(request.REQUEST["user_id"])
        return_dict["user_id"] = user_id

        auth_access = iscsi.load_auth_access_user_info(int(user_id))
        if err:
            raise Exception(err)
        if not auth_access:
            raise Exception("authorized access user information not found")

        if request.method == "GET":
            # Shd be an edit request

            # Set initial form values
            initial = {}
            initial["auth_access_group_id"] = auth_access["auth_access_group_id"]
            initial["user_id"] = auth_access["id"]
            initial["user"] = auth_access["user"]

            form = iscsi_forms.AuthorizedAccessUserForm(initial=initial)

            return_dict["form"] = form
            return django.shortcuts.render_to_response('edit_iscsi_auth_access_user.html', return_dict, context_instance=django.template.context.RequestContext(request))

        else:

            # Shd be an save request
            form = iscsi_forms.AuthorizedAccessUserForm(request.POST)
            return_dict["form"] = form

            if form.is_valid():
                cd = form.cleaned_data
                user = cd["user"]
                auth_access_group_id = cd["auth_access_group_id"]
                user_id = cd["user_id"]
                secret = cd["secret"]
                ret, err = iscsi.save_auth_access_user(
                    auth_access_group_id, user_id, user, secret)
                if err:
                    raise Exception(err)
                if not ret:
                    raise Exception(
                        "Error saving authorized access user information")

                audit_str = "Modified authorized access user in auth group %s" % auth_access_group_id
                ret, err = audit.audit(
                    "modify_iscsi_auth_access_user", audit_str, request)
                if err:
                    raise Exception(err)

                return django.http.HttpResponseRedirect('/iscsi_display_auth_access_group_list?action=user_saved')

            else:
                # Invalid form
                form.initial = form.data
                return django.shortcuts.render_to_response('edit_iscsi_auth_access_user.html', return_dict, context_instance=django.template.context.RequestContext(request))
    except Exception, e:
        s = str(e)
        if "Another transaction is in progress".lower() in s.lower():
            return_dict["error"] = "An underlying storage operation has locked a volume so we are unable to process this request. Please try after a couple of seconds"
        else:
            return_dict["error"] = "An error occurred when processing your request : %s" % s
        return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))